nixos: Fix secrets in containers
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
server.enable = true;
|
||||
|
||||
secrets = {
|
||||
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMHoWhafCkLVggsO24fFWm3nmkY5t23GHbBafBVGijbQ";
|
||||
files."${vwSecrets}" = {};
|
||||
};
|
||||
|
||||
|
@@ -245,6 +245,12 @@ in
|
||||
(u: ''install -d -o ${u.name} -g ${u.group} /nix/var/nix/{profiles,gcroots}/per-user/"${u.name}"'') users;
|
||||
deps = [ "users" "groups" ];
|
||||
};
|
||||
|
||||
# age requires all keys to at least exist, even if they're not going to be used
|
||||
ensureDevKey.text =
|
||||
''
|
||||
[ ! -e "${devVMKeyPath}" ] && touch "${devVMKeyPath}"
|
||||
'';
|
||||
};
|
||||
|
||||
networking = {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{ lib, config, secretsPath, ... }:
|
||||
{ lib, pkgs, config, secretsPath, ... }:
|
||||
let
|
||||
inherit (builtins) mapAttrs;
|
||||
inherit (lib) mkMerge mkIf;
|
||||
@@ -15,10 +15,22 @@ in
|
||||
|
||||
config = mkMerge [
|
||||
{
|
||||
age.secrets = mapAttrs (f: opts: {
|
||||
file = "${secretsPath}/${f}.age";
|
||||
} // opts) cfg.files;
|
||||
age = {
|
||||
secrets = mapAttrs (f: opts: {
|
||||
file = "${secretsPath}/${f}.age";
|
||||
} // opts) cfg.files;
|
||||
# agenix sets this as a default but adding any custom extras will _replace_ the list (different priority)
|
||||
identityPaths =
|
||||
mkIf config.services.openssh.enable
|
||||
(map (e: e.path) (lib.filter (e: e.type == "rsa" || e.type == "ed25519") config.services.openssh.hostKeys));
|
||||
};
|
||||
}
|
||||
(mkIf (config.age.secrets != { }) {
|
||||
system.activationScripts.agenixMountSecrets.deps = mkIf (config.my.tmproot.persistence.dir != null) [
|
||||
# The key used to decrypt is not going to exist!
|
||||
"persist-files"
|
||||
];
|
||||
})
|
||||
(mkIf config.my.build.isDevVM {
|
||||
age.identityPaths = [ cfg.vmKeyPath ];
|
||||
})
|
||||
|
Reference in New Issue
Block a user