diff options
author | Ben Sima <ben@bsima.me> | 2021-04-19 09:11:29 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2021-11-26 13:47:33 -0500 |
commit | 304ab785d07bbdb808d6c824c5457a06628274c1 (patch) | |
tree | 7d9c3f1917286e21528f17bdd3ed5a4c0e5be444 | |
parent | 600d1715e8ed2f7000118d3395248b28dd0a9420 (diff) |
Copy gmnisrv into tree
The correct way to do this would be to use my own nixpkgs fork published
at git.simatime.com, but to do that I need to setup a public git repo,
so until then I have to do it this way, which is fine.
-rw-r--r-- | Biz/Cloud.nix | 1 | ||||
-rw-r--r-- | Biz/Cloud/gmnisrv.nix | 70 |
2 files changed, 71 insertions, 0 deletions
diff --git a/Biz/Cloud.nix b/Biz/Cloud.nix index 5bcb0a1..44fb5a8 100644 --- a/Biz/Cloud.nix +++ b/Biz/Cloud.nix @@ -20,6 +20,7 @@ bild.os { ./Cloud/Networking.nix ./Cloud/Web.nix ./Cloud/Znc.nix + ./Cloud/gmnisrv.nix nixos-mailserver ]; networking.hostName = "simatime"; diff --git a/Biz/Cloud/gmnisrv.nix b/Biz/Cloud/gmnisrv.nix new file mode 100644 index 0000000..2dbe872 --- /dev/null +++ b/Biz/Cloud/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}"; + }; + }; +} |