1
0
Fork 0
mirror of https://github.com/Mic92/sops-nix.git synced 2025-03-16 13:38:20 +00:00
sops-nix/modules/nix-darwin/secrets-for-users/default.nix

54 lines
1.4 KiB
Nix
Raw Normal View History

2024-11-17 12:17:45 +01:00
{
lib,
config,
pkgs,
...
}:
2024-11-03 19:51:58 +00:00
let
cfg = config.sops;
secretsForUsers = lib.filterAttrs (_: v: v.neededForUsers) cfg.secrets;
2024-11-17 12:17:45 +01:00
templatesForUsers = { }; # We do not currently support `neededForUsers` for templates.
2024-11-03 19:51:58 +00:00
manifestFor = pkgs.callPackage ../manifest-for.nix {
inherit cfg;
inherit (pkgs) writeTextFile;
};
withEnvironment = import ../with-environment.nix {
inherit cfg lib;
};
manifestForUsers = manifestFor "-for-users" secretsForUsers templatesForUsers {
2024-11-03 19:51:58 +00:00
secretsMountPoint = "/run/secrets-for-users.d";
symlinkPath = "/run/secrets-for-users";
};
installScript = ''
echo "Setting up secrets for users"
${withEnvironment "${cfg.package}/bin/sops-install-secrets -ignore-passwd ${manifestForUsers}"}
'';
in
{
2024-11-17 12:17:45 +01:00
assertions = [
{
assertion =
(lib.filterAttrs (
_: v: (v.uid != 0 && v.owner != "root") || (v.gid != 0 && v.group != "root")
) secretsForUsers) == { };
message = "neededForUsers cannot be used for secrets that are not root-owned";
}
];
2024-11-03 19:51:58 +00:00
2024-11-17 12:17:45 +01:00
system.activationScripts = lib.mkIf (secretsForUsers != [ ]) {
2024-11-03 19:51:58 +00:00
postActivation.text = lib.mkAfter installScript;
};
2024-11-17 12:17:45 +01:00
launchd.daemons.sops-install-secrets-for-users = lib.mkIf (secretsForUsers != [ ]) {
2024-11-03 19:51:58 +00:00
command = installScript;
serviceConfig = {
RunAtLoad = true;
KeepAlive = false;
};
};
system.build.sops-nix-users-manifest = manifestForUsers;
}