Fediversity/infra/common/procolixResource.nix

68 lines
1.6 KiB
Nix
Raw Normal View History

{
self,
inputs,
providers,
lib,
config,
...
}:
let
2025-01-31 16:28:52 +01:00
inherit (lib) attrValues elem mkOption;
inherit (lib.attrsets) concatMapAttrs optionalAttrs;
inherit (lib.strings) removeSuffix;
in
{
options = {
2025-01-31 15:11:56 +01:00
procolixVm = {
name = mkOption { };
host = mkOption { };
2025-01-31 16:28:52 +01:00
hostPublicKey = mkOption {
description = ''
The host public key of the machine. It is used in particular
to filter Age secrets and only keep the relevant ones.
'';
};
2025-01-31 15:11:56 +01:00
};
};
2025-01-31 16:28:52 +01:00
config =
let
2025-01-31 15:11:56 +01:00
hostPublicKey = self.keys.systems.${config.procolixVm.name};
2025-01-31 16:28:52 +01:00
in
{
type = providers.local.exec;
2025-01-31 16:28:52 +01:00
ssh = {
host = config.procolixVm.host;
hostPublicKey = hostPublicKey;
};
2025-01-31 16:28:52 +01:00
nixpkgs = inputs.nixpkgs;
2025-01-31 16:28:52 +01:00
nixos.module = {
imports = [
inputs.agenix.nixosModules.default
./nixosConfiguration
];
2025-01-31 16:28:52 +01:00
## Read all the secrets, filter the ones that are supposed to be
## readable with this host's public key, and add them correctly to the
## configuration as `age.secrets.<name>.file`.
age.secrets = concatMapAttrs (
name: secret:
optionalAttrs (elem hostPublicKey secret.publicKeys) ({
${removeSuffix ".age" name}.file = ../../secrets + "/${name}";
})
) (import ../../secrets/secrets.nix);
## FIXME: Remove direct root authentication once the NixOps4 NixOS
## provider supports users with password-less sudo.
users.users.root.openssh.authorizedKeys.keys = attrValues self.keys.contributors;
};
};
}