Share options between resource and config

This commit is contained in:
Nicolas Jeannerod 2025-01-31 16:47:33 +01:00
parent 8cfc943297
commit 54194cd494
Signed by untrusted user: Niols
GPG key ID: 35DB9EC8886E1CB8
3 changed files with 29 additions and 15 deletions

21
infra/common/options.nix Normal file
View file

@ -0,0 +1,21 @@
{ lib, ... }:
let
inherit (lib) mkOption;
in
{
options = {
procolixVm = {
name = mkOption { };
host = mkOption { };
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.
'';
};
};
};
}

View file

@ -6,7 +6,7 @@
}:
let
inherit (lib) attrValues elem mkOption;
inherit (lib) attrValues elem;
inherit (lib.attrsets) concatMapAttrs optionalAttrs;
inherit (lib.strings) removeSuffix;
@ -16,19 +16,7 @@ let
in
{
options = {
procolixVm = {
name = mkOption { };
host = mkOption { };
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.
'';
};
};
};
imports = [ ./options.nix ];
config =
let
@ -46,9 +34,14 @@ in
nixos.module = {
imports = [
inputs.agenix.nixosModules.default
./options.nix
./nixosConfiguration
];
## Inject the shared options from the resource's `config` into the NixOS
## configuration.
procolixVm = config.procolixVm;
## 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`.

View file

@ -21,7 +21,7 @@ let
type = providers.local.exec;
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
./common/procolixResource.nix
./common/resource.nix
(./. + "/${vmName}")
];
procolixVm.name = vmName;