From dfac70cb1d3ae6d19d2dce79ec4710ad01ac3972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 10 Aug 2024 18:04:35 +0200 Subject: [PATCH 1/3] nixos/opendkim: modernize --- nixos/modules/services/mail/opendkim.nix | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/nixos/modules/services/mail/opendkim.nix b/nixos/modules/services/mail/opendkim.nix index dd29e5035089..c4ca4fa94aca 100644 --- a/nixos/modules/services/mail/opendkim.nix +++ b/nixos/modules/services/mail/opendkim.nix @@ -1,16 +1,14 @@ { config, lib, pkgs, ... }: -let +let cfg = config.services.opendkim; defaultSock = "local:/run/opendkim/opendkim.sock"; - keyFile = "${cfg.keyPath}/${cfg.selector}.private"; - args = [ "-f" "-l" "-p" cfg.socket "-d" cfg.domains - "-k" keyFile + "-k" "${cfg.keyPath}/${cfg.selector}.private" "-s" cfg.selector ] ++ lib.optionals (cfg.configFile != null) [ "-x" cfg.configFile ]; @@ -19,17 +17,9 @@ in { (lib.mkRenamedOptionModule [ "services" "opendkim" "keyFile" ] [ "services" "opendkim" "keyPath" ]) ]; - ###### interface - options = { - services.opendkim = { - - enable = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Whether to enable the OpenDKIM sender authentication system."; - }; + enable = lib.mkEnableOption "OpenDKIM sender authentication system"; socket = lib.mkOption { type = lib.types.str; @@ -79,16 +69,10 @@ in { default = null; description = "Additional opendkim configuration."; }; - }; - }; - - ###### implementation - config = lib.mkIf cfg.enable { - users.users = lib.optionalAttrs (cfg.user == "opendkim") { opendkim = { group = cfg.group; @@ -159,6 +143,5 @@ in { UMask = "0077"; }; }; - }; } From 1414b222f52ba757b6af721b9fba0d23c957dab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 10 Aug 2024 18:17:32 +0200 Subject: [PATCH 2/3] nixos/opendkim: add expandable settings option --- nixos/modules/services/mail/opendkim.nix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/mail/opendkim.nix b/nixos/modules/services/mail/opendkim.nix index c4ca4fa94aca..0784c7547ba1 100644 --- a/nixos/modules/services/mail/opendkim.nix +++ b/nixos/modules/services/mail/opendkim.nix @@ -64,10 +64,19 @@ in { description = "Selector to use when signing."; }; + # TODO: deprecate this? configFile = lib.mkOption { type = lib.types.nullOr lib.types.path; default = null; - description = "Additional opendkim configuration."; + description = "Additional opendkim configuration as a file."; + }; + + settings = lib.mkOption { + type = with lib.types; submodule { + freeformType = attrsOf str; + }; + default = { }; + description = "Additional opendkim configuration"; }; }; }; @@ -86,6 +95,9 @@ in { environment.systemPackages = [ pkgs.opendkim ]; + services.opendkim.configFile = lib.mkIf (cfg.settings != { }) (pkgs.writeText "opendkim.conf" + (lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: "${name} ${value}") cfg.settings))); + systemd.tmpfiles.rules = [ "d '${cfg.keyPath}' - ${cfg.user} ${cfg.group} - -" ]; From f497159195ef8c30849a8cd1df0719350ce8c5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 10 Aug 2024 20:21:57 +0200 Subject: [PATCH 3/3] nixos/opendkim: put config file under standard location --- nixos/modules/services/mail/opendkim.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/mail/opendkim.nix b/nixos/modules/services/mail/opendkim.nix index 0784c7547ba1..0aed4d9bee01 100644 --- a/nixos/modules/services/mail/opendkim.nix +++ b/nixos/modules/services/mail/opendkim.nix @@ -12,6 +12,8 @@ let "-s" cfg.selector ] ++ lib.optionals (cfg.configFile != null) [ "-x" cfg.configFile ]; + configFile = pkgs.writeText "opendkim.conf" + (lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: "${name} ${value}") cfg.settings)); in { imports = [ (lib.mkRenamedOptionModule [ "services" "opendkim" "keyFile" ] [ "services" "opendkim" "keyPath" ]) @@ -93,10 +95,14 @@ in { opendkim.gid = config.ids.gids.opendkim; }; - environment.systemPackages = [ pkgs.opendkim ]; + environment = { + etc = lib.mkIf (cfg.settings != { }) { + "opendkim/opendkim.conf".source = configFile; + }; + systemPackages = [ pkgs.opendkim ]; + }; - services.opendkim.configFile = lib.mkIf (cfg.settings != { }) (pkgs.writeText "opendkim.conf" - (lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: "${name} ${value}") cfg.settings))); + services.opendkim.configFile = lib.mkIf (cfg.settings != { }) configFile; systemd.tmpfiles.rules = [ "d '${cfg.keyPath}' - ${cfg.user} ${cfg.group} - -"