Skip to content

Commit

Permalink
opendkim: automated key generation (no manual changes for service ini…
Browse files Browse the repository at this point in the history
…tialization required anymore)
  • Loading branch information
qknight authored and fpletz committed Oct 23, 2017
1 parent 681c800 commit 61089dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions nixos/modules/rename.nix
Expand Up @@ -112,6 +112,9 @@ with lib;

(mkAliasOptionModule [ "environment" "checkConfigurationOptions" ] [ "_module" "check" ])

# opendkim
(mkRenamedOptionModule [ "services" "opendkim" "keyFile" ] [ "services" "opendkim" "keyPath" ])

# XBMC
(mkRenamedOptionModule [ "services" "xserver" "windowManager" "xbmc" ] [ "services" "xserver" "desktopManager" "kodi" ])
(mkRenamedOptionModule [ "services" "xserver" "desktopManager" "xbmc" ] [ "services" "xserver" "desktopManager" "kodi" ])
Expand Down
26 changes: 23 additions & 3 deletions nixos/modules/services/mail/opendkim.nix
Expand Up @@ -8,10 +8,12 @@ let

defaultSock = "local:/run/opendkim/opendkim.sock";

keyFile = "${cfg.keyPath}/${cfg.selector}.private";

args = [ "-f" "-l"
"-p" cfg.socket
"-d" cfg.domains
"-k" cfg.keyFile
"-k" keyFile
"-s" cfg.selector
] ++ optionals (cfg.configFile != null) [ "-x" cfg.configFile ];

Expand Down Expand Up @@ -57,9 +59,13 @@ in {
'';
};

keyFile = mkOption {
keyPath = mkOption {
type = types.path;
description = "Secret key file used for signing messages.";
description = ''
The path that opendkim should put its generated private keys into.
The DNS settings will be found in this directory with the name selector.txt.
'';
default = "/var/lib/opendkim/keys";
};

selector = mkOption {
Expand Down Expand Up @@ -100,11 +106,25 @@ in {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];

preStart = ''
mkdir -p "${cfg.keyPath}"
cd "${cfg.keyPath}"
if ! test -f ${cfg.selector}.private; then
${pkgs.opendkim}/bin/opendkim-genkey -s ${cfg.selector} -d all-domains-generic-key
echo "Generated OpenDKIM key! Please update your DNS settings:\n"
echo "-------------------------------------------------------------"
cat ${cfg.selector}.txt
echo "-------------------------------------------------------------"
fi
chown ${cfg.user}:${cfg.group} ${cfg.selector}.private
'';

serviceConfig = {
ExecStart = "${pkgs.opendkim}/bin/opendkim ${escapeShellArgs args}";
User = cfg.user;
Group = cfg.group;
RuntimeDirectory = optional (cfg.socket == defaultSock) "opendkim";
PermissionsStartOnly = true;
};
};

Expand Down

0 comments on commit 61089dd

Please sign in to comment.