Fediversity/infra/common/resource.nix

61 lines
1.5 KiB
Nix
Raw Normal View History

{
inputs,
lib,
config,
...
}:
let
inherit (lib) attrValues elem;
2025-01-31 16:28:52 +01:00
inherit (lib.attrsets) concatMapAttrs optionalAttrs;
inherit (lib.strings) removeSuffix;
secretsPrefix = ../../secrets;
secrets = import (secretsPrefix + "/secrets.nix");
keys = import ../../keys;
in
{
imports = [ ./options.nix ];
2025-01-31 16:28:52 +01:00
config =
let
hostPublicKey = keys.systems.${config.procolixVm.name};
2025-01-31 16:28:52 +01:00
in
{
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
./options.nix
2025-01-31 16:28:52 +01:00
./nixosConfiguration
];
## Inject the shared options from the resource's `config` into the NixOS
## configuration.
procolixVm = config.procolixVm;
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 = secretsPrefix + "/${name}";
2025-01-31 16:28:52 +01:00
})
) secrets;
2025-01-31 16:28:52 +01:00
## FIXME: Remove direct root authentication once the NixOps4 NixOS
## provider supports users with password-less sudo.
users.users.root.openssh.authorizedKeys.keys = attrValues keys.contributors;
2025-01-31 16:28:52 +01:00
};
};
}