Skip to content

Commit

Permalink
fix: reprovision secrets via activation script
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Aug 15, 2024
1 parent ec2f625 commit 43a9582
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions modules/op-secrets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@ in {
serviceConfig = {
Type = "oneshot";
EnvironmentFile = cfg.environmentFile;
RemainAfterExit = true;
ExecReload = opnixScript;
};

script = opnixScript;
};
# if no generation already exists, rely on the systemd startup job;
# otherwise, if there already is an existing generation, reprovision
# secrets because we did a nixos-rebuild
system.activationScripts.opnix-on-rebuild.text = ''
${scripts.setOpnixGeneration}
if (( _opnix_generation > 1 )) && {
${opnixScript}
}
'';
}
{
systemd.services = builtins.listToAttrs (builtins.map (systemdName: {
Expand Down
6 changes: 5 additions & 1 deletion modules/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ let
grep -q "${cfg.secretsMountPoint} ramfs" /proc/mounts ||
mount -t ramfs none "${cfg.secretsMountPoint}" -o nodev,nosuid,mode=0751
'';
newGeneration = ''
setOpnixGeneration = ''
_opnix_generation="$(basename "$(readlink ${cfg.secretsDir})" || echo 0)"
(( ++_opnix_generation ))
'';
newGeneration = ''
${setOpnixGeneration}
echo "[opnix] creating new generation in ${cfg.secretsMountPoint}/$_opnix_generation"
mkdir -p "${cfg.secretsMountPoint}"
chmod 0751 "${cfg.secretsMountPoint}"
Expand Down Expand Up @@ -115,6 +118,7 @@ let
] ++ (map installSecret (builtins.attrValues cfg.secrets))
++ [ cleanupAndLink ]);
in {
inherit setOpnixGeneration;
inherit createOpConfigDir;
inherit installSecrets;
inherit chownSecrets;
Expand Down

0 comments on commit 43a9582

Please sign in to comment.