~andir/nixpkgs-dev

nixos/gmnisrv: init v1 PROPOSED

Ben Sima: 1
 nixos/gmnisrv: init

 2 files changed, 57 insertions(+), 0 deletions(-)
sternenseemann <sternenseemann@systemli.org> writes:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~andir/nixpkgs-dev/patches/21881/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] nixos/gmnisrv: init Export this patch

This is currently powering gemini://bsima.me, and renders with amfora and gmni.
The workaround to support anonymous key-vals in the ini file are a bit weird,
but I don't think it's too cryptic. Let me know if there is a better solution.

---
 nixos/modules/module-list.nix                 |  1 +
 .../modules/services/web-servers/gmnisrv.nix  | 56 +++++++++++++++++++
 2 files changed, 57 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 6f172720558..61df95a2d6f 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -942,6 +942,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..e89be8d7a6e
--- /dev/null
+++ b/nixos/modules/services/web-servers/gmnisrv.nix
@@ -0,0 +1,56 @@
{ lib
, options
, config
, pkgs
, modulesPath
}:

let
  cfg = config.services.gmnisrv;
  cfgFormat = pkgs.formats.ini { };
  # this 'writeText' is necessary because lib.generate.toINI does not support
  # top-level, anonymous key-value pairs, but gmnisrv needs the anonymous
  # "listen" key to know where to bind
  cfgFile = pkgs.writeText "gmnisrv.ini" (''
    listen = ${cfg.listen}
  '' + builtins.readFile (cfgFormat.generate "gmnisrv.ini.partial" cfg.config));
in {
  options.services.gmnisrv = {
    enable = lib.mkEnableOption "Enable the gmnisrv service";
    config = lib.mkOption {
      type = cfgFormat.type;
      description = ''
        Configuration for gmnisrv. See gmnisrv.ini(5) for supported settings.
      '';
    };
    package = lib.mkOption {
      type = lib.types.package;
      default = pkgs.gmnisrv;
      description = "gmnisrv package to use";
    };
    listen = lib.mkOption {
      type = lib.types.str;
      default = "0.0.0.0:1965 [::]:1965";
      description = ''
        Host address and port to listen on. See gmnisrv.ini(5) for syntax
        details.
      '';
    };
  };
  config = lib.mkIf cfg.enable {
    services.gmnisrv.config = {
      ":tls" = {
        "store" = "/var/lib/gemini/certs";
      };
    };
    systemd.services.gmnisrv = {
      path = [ cfg.package ];
      description = "gmnisrv service";
      wantedBy = [ "multi-user.target" ];
      after = [ "network-online.target" ];
      script = ''
        ${cfg.package}/bin/gmnisrv -C ${cfgFile}
      '';
    };
  };
}
-- 
2.31.0