~andir/nixpkgs-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH v3] nixos/gmnisrv: init

Details
Message ID
<20210417001707.17601-1-ben@bsima.me>
DKIM signature
missing
Download raw message
Patch: +71 -0
---
I think I addressed all comments in previous threads. This does not include the
change to lib.formats, but works around the limitation with a private cfgFormat
function. Given that the lib.formats patch is changing a somewhat corelib in
nixpkgs, I figure it will take a while to review and merge, so this patch is
available as an alternative in the meantime.

 nixos/modules/module-list.nix                 |  1 +
 .../modules/services/web-servers/gmnisrv.nix  | 70 +++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 nixos/modules/services/web-servers/gmnisrv.nix

diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 41cbb501323..54cda99c85f 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -883,6 +883,7 @@
  ./services/web-servers/caddy.nix
  ./services/web-servers/darkhttpd.nix
  ./services/web-servers/fcgiwrap.nix
  ./services/web-servers/gmnisrv.nix
  ./services/web-servers/hitch/default.nix
  ./services/web-servers/hydron.nix
  ./services/web-servers/jboss/default.nix
diff --git a/nixos/modules/services/web-servers/gmnisrv.nix b/nixos/modules/services/web-servers/gmnisrv.nix
new file mode 100644
index 00000000000..2dbe872329b
--- /dev/null
+++ b/nixos/modules/services/web-servers/gmnisrv.nix
@@ -0,0 +1,70 @@
{ lib
, options
, config
, pkgs
, ...
}:

let
  cfg = config.services.gmnisrv;

  # from https://github.com/openlab-aux/vuizvui/blob/1576e1025d570851449f6668e0bda2b1b9b21e06/modules/programs/foot/default.nix#L15-L48
  # this can be replaced with lib.formats.ini when
  # https://github.com/NixOS/nixpkgs/pull/118925 is merged
  cfgFormat = {
    type = with lib.types;
      let
        iniAtom = nullOr (oneOf [ bool int float str ]) // {
          description = "INI atom (null, bool, int, float, or string)";
        };
      in (attrsOf (either iniAtom (attrsOf iniAtom))) // {
        description = ''
          attribute set of either top-level INI atoms (bool, int, float or string)
          or attribute sets (sections) of INI atoms
        '';
      };
    generate = name: value:
      let
        isSection = builtins.isAttrs;
        topLevel = lib.filterAttrs (_: v: !(isSection v)) value;
        sections = lib.filterAttrs (_: v: isSection v) value;
      in  pkgs.writeText name ''
        ${lib.generators.toKeyValue {} topLevel}
        ${lib.generators.toINI {} sections}
      '';
  };
in {
  options.services.gmnisrv = {
    enable = lib.mkEnableOption "Enable the gmnisrv service";
    settings = lib.mkOption {
      type = cfgFormat.type;
      description = ''
        Configuration for gmnisrv. See gmnisrv.ini(5) for supported settings.
      '';
      default = {
        "listen" = lib.mkDefault "0.0.0.0:1965 [::]:1965";
        ":tls" = {
          "store" = lib.mkDefault "${cfg.dataDir}/certs";
        };
      };
    };
    package = lib.mkOption {
      type = lib.types.package;
      default = pkgs.gmnisrv;
      description = "gmnisrv package to use";
    };
    dataDir = lib.mkOption {
      type = lib.types.str;
      default = "/var/lib/gemini";
      description = "Where gmnisrv should store certs and other data.";
    };
  };
  config = lib.mkIf cfg.enable {
    systemd.services.gmnisrv = {
      description = "gmnisrv service";
      wantedBy = [ "multi-user.target" ];
      after = [ "network-online.target" ];
      script = "${cfg.package}/bin/gmnisrv -C ${cfgFormat.generate "gmnisrv.ini" cfg.settings}";
    };
  };
}
-- 
2.31.1
William Casarin <jb55@jb55.com>
Details
Message ID
<20210419140126.3ii3vraheuhielj2@quiver>
In-Reply-To
<20210417001707.17601-1-ben@bsima.me> (view parent)
DKIM signature
missing
Download raw message
Reviewed-by: William Casarin <jb55@jb55.com>
Reply to thread Export thread (mbox)