diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/default.nix | 3 | ||||
| -rw-r--r-- | modules/mjmap.nix | 51 |
2 files changed, 53 insertions, 1 deletions
diff --git a/modules/default.nix b/modules/default.nix index 180e31b..5c93f8e 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -15,7 +15,8 @@ ./motd.nix ./locale.nix ./test_endpoint.nix - ./prometheus.nix + ./prometheus.nix + ./mjmap.nix ]; nixpkgs.overlays = [ diff --git a/modules/mjmap.nix b/modules/mjmap.nix new file mode 100644 index 0000000..b826469 --- /dev/null +++ b/modules/mjmap.nix @@ -0,0 +1,51 @@ +{pkgs, config, lib, ...}: let + cfg = config.wilkuu.mjmap; + inherit (lib) mkEnableOption mkOption types mkIf; + # TODO: Once the mjmap patch is upstreamed, use this. + #mjmap_wrap = (pkgs.writeScriptBin "mjmap" '' + # #! ${pkgs.bash}/bin/bash + # export MJMAP_CONFIG=${config.sops.secrets."mjmap-creds".path}; + # exec ${pkgs.mjmap} "$@" + # ''); + + # Workaround since the current version does not support setting config path; + mjmap_wrap = (pkgs.writeScriptBin "mjmap-send" '' + #! ${pkgs.bash}/bin/bash + export XDG_CONFIG_DIR=/etc/; + exec ${pkgs.mjmap}/bin/mjmap "$@" + ''); + + sendmail_wrap = pkgs.symlinkJoin { + name = "sendmail-wrapper"; + paths = [ mjmap_wrap ]; + postBuild = '' + ln -s $out/bin/mjmap-send $out/bin/sendmail + ''; + }; + +in { + options.wilkuu.mjmap = { + enable = mkEnableOption "mjmap jmap email"; + users = mkOption { + type = types.listOf types.str; + description = "users that are allowed to view the credentials file and thus use mjmail"; + }; + }; + + config = mkIf cfg.enable{ + users.groups.mjmap = mkIf (cfg.users != []) {}; + users.users = lib.genAttrs cfg.users (_: { + extraGroups = ["mjmap"]; + packages = [mjmap_wrap sendmail_wrap]; + }); + sops.secrets."mjmap-creds" = mkIf (cfg.users != []) { + sopsFile = ../secrets/${config.networking.hostName}/mjmap.scfg.bin; + key = ""; + format = "binary"; + group = "mjmap"; + mode = "440"; + }; + environment.etc."mjmap/config.scfg" = mkIf (cfg.users != []) { source = config.sops.secrets."mjmap-creds".path; }; + environment.systemPackages = [ pkgs.mjmap ]; + }; +} |
