forked from Fediversity/Fediversity
Inject sources, secrets and keys via module system - avoid import ../
(#421)
Co-authored-by: Nicolas “Niols” Jeannerod <nicolas.jeannerod@moduscreate.com> Reviewed-on: Fediversity/Fediversity#421 Reviewed-by: Nicolas Jeannerod <nicolas.jeannerod@moduscreate.com> Reviewed-by: Valentin Gagarin <valentin.gagarin@tweag.io> Co-authored-by: Kiara Grouwstra <kiara@procolix.eu> Co-committed-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
parent
c1dc0fef01
commit
a791ad41ec
12 changed files with 49 additions and 28 deletions
|
@ -2,6 +2,7 @@
|
||||||
self,
|
self,
|
||||||
inputs,
|
inputs,
|
||||||
lib,
|
lib,
|
||||||
|
sources,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ in
|
||||||
../common/nixosTest.nix
|
../common/nixosTest.nix
|
||||||
./nixosTest.nix
|
./nixosTest.nix
|
||||||
];
|
];
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
inherit targetMachines pathToRoot pathFromRoot;
|
inherit targetMachines pathToRoot pathFromRoot;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -44,7 +45,7 @@ in
|
||||||
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
||||||
../common/targetResource.nix
|
../common/targetResource.nix
|
||||||
];
|
];
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
inherit nodeName pathToRoot pathFromRoot;
|
inherit nodeName pathToRoot pathFromRoot;
|
||||||
nixos.module =
|
nixos.module =
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
self,
|
self,
|
||||||
inputs,
|
inputs,
|
||||||
lib,
|
lib,
|
||||||
|
sources,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ in
|
||||||
../common/nixosTest.nix
|
../common/nixosTest.nix
|
||||||
./nixosTest.nix
|
./nixosTest.nix
|
||||||
];
|
];
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
inherit
|
inherit
|
||||||
targetMachines
|
targetMachines
|
||||||
pathToRoot
|
pathToRoot
|
||||||
|
@ -44,7 +45,7 @@ in
|
||||||
let
|
let
|
||||||
makeTargetResource = nodeName: {
|
makeTargetResource = nodeName: {
|
||||||
imports = [ ../common/targetResource.nix ];
|
imports = [ ../common/targetResource.nix ];
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
inherit
|
inherit
|
||||||
nodeName
|
nodeName
|
||||||
pathToRoot
|
pathToRoot
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
config,
|
config,
|
||||||
|
sources,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
@ -14,8 +15,6 @@ let
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
|
|
||||||
sources = import ../../../npins;
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
_class = "nixos";
|
_class = "nixos";
|
||||||
|
@ -78,7 +77,7 @@ in
|
||||||
config.system.extraDependenciesFromModule
|
config.system.extraDependenciesFromModule
|
||||||
{
|
{
|
||||||
nixpkgs.hostPlatform = "x86_64-linux";
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
enableAcme = config.enableAcme;
|
enableAcme = config.enableAcme;
|
||||||
acmeNodeIP = config.acmeNodeIP;
|
acmeNodeIP = config.acmeNodeIP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
hostPkgs,
|
hostPkgs,
|
||||||
|
sources,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ in
|
||||||
{
|
{
|
||||||
deployer = {
|
deployer = {
|
||||||
imports = [ ./deployerNode.nix ];
|
imports = [ ./deployerNode.nix ];
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
enableAcme = config.enableAcme;
|
enableAcme = config.enableAcme;
|
||||||
acmeNodeIP = config.nodes.acme.networking.primaryIPAddress;
|
acmeNodeIP = config.nodes.acme.networking.primaryIPAddress;
|
||||||
};
|
};
|
||||||
|
@ -88,7 +89,7 @@ in
|
||||||
|
|
||||||
genAttrs config.targetMachines (_: {
|
genAttrs config.targetMachines (_: {
|
||||||
imports = [ ./targetNode.nix ];
|
imports = [ ./targetNode.nix ];
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
enableAcme = config.enableAcme;
|
enableAcme = config.enableAcme;
|
||||||
acmeNodeIP = if config.enableAcme then config.nodes.acme.networking.primaryIPAddress else null;
|
acmeNodeIP = if config.enableAcme then config.nodes.acme.networking.primaryIPAddress else null;
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
inputs,
|
inputs,
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
|
sources,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ in
|
||||||
(lib.modules.importJSON (config.pathToCwd + "/${config.nodeName}-network.json"))
|
(lib.modules.importJSON (config.pathToCwd + "/${config.nodeName}-network.json"))
|
||||||
];
|
];
|
||||||
|
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
enableAcme = config.enableAcme;
|
enableAcme = config.enableAcme;
|
||||||
acmeNodeIP = trim (readFile (config.pathToCwd + "/acme_server_ip"));
|
acmeNodeIP = trim (readFile (config.pathToCwd + "/acme_server_ip"));
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
self,
|
self,
|
||||||
inputs,
|
inputs,
|
||||||
lib,
|
lib,
|
||||||
|
sources,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ in
|
||||||
../common/nixosTest.nix
|
../common/nixosTest.nix
|
||||||
./nixosTest.nix
|
./nixosTest.nix
|
||||||
];
|
];
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
inherit
|
inherit
|
||||||
targetMachines
|
targetMachines
|
||||||
pathToRoot
|
pathToRoot
|
||||||
|
@ -47,7 +48,7 @@ in
|
||||||
let
|
let
|
||||||
makeTargetResource = nodeName: {
|
makeTargetResource = nodeName: {
|
||||||
imports = [ ../common/targetResource.nix ];
|
imports = [ ../common/targetResource.nix ];
|
||||||
_module.args.inputs = inputs;
|
_module.args = { inherit inputs sources; };
|
||||||
inherit
|
inherit
|
||||||
nodeName
|
nodeName
|
||||||
pathToRoot
|
pathToRoot
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
inherit nixpkgs;
|
inherit nixpkgs;
|
||||||
};
|
};
|
||||||
self = self';
|
self = self';
|
||||||
|
specialArgs = {
|
||||||
|
inherit sources;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
{ inputs, ... }:
|
{ inputs, ... }:
|
||||||
|
@ -48,6 +51,8 @@
|
||||||
|
|
||||||
./deployment/flake-part.nix
|
./deployment/flake-part.nix
|
||||||
./infra/flake-part.nix
|
./infra/flake-part.nix
|
||||||
|
./keys/flake-part.nix
|
||||||
|
./secrets/flake-part.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
perSystem =
|
perSystem =
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
inputs,
|
inputs,
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
|
sources,
|
||||||
|
keys,
|
||||||
|
secrets,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
@ -9,12 +12,6 @@ let
|
||||||
inherit (lib) attrValues elem mkDefault;
|
inherit (lib) attrValues elem mkDefault;
|
||||||
inherit (lib.attrsets) concatMapAttrs optionalAttrs;
|
inherit (lib.attrsets) concatMapAttrs optionalAttrs;
|
||||||
inherit (lib.strings) removeSuffix;
|
inherit (lib.strings) removeSuffix;
|
||||||
sources = import ../../npins;
|
|
||||||
inherit (sources) agenix disko;
|
|
||||||
|
|
||||||
secretsPrefix = ../../secrets;
|
|
||||||
secrets = import (secretsPrefix + "/secrets.nix");
|
|
||||||
keys = import ../../keys;
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -36,8 +33,8 @@ in
|
||||||
## should go into the `./nixos` subdirectory.
|
## should go into the `./nixos` subdirectory.
|
||||||
nixos.module = {
|
nixos.module = {
|
||||||
imports = [
|
imports = [
|
||||||
"${agenix}/modules/age.nix"
|
"${sources.agenix}/modules/age.nix"
|
||||||
"${disko}/module.nix"
|
"${sources.disko}/module.nix"
|
||||||
./options.nix
|
./options.nix
|
||||||
./nixos
|
./nixos
|
||||||
];
|
];
|
||||||
|
@ -46,15 +43,15 @@ in
|
||||||
## configuration.
|
## configuration.
|
||||||
fediversityVm = config.fediversityVm;
|
fediversityVm = config.fediversityVm;
|
||||||
|
|
||||||
## Read all the secrets, filter the ones that are supposed to be readable
|
## Read all the secrets, filter the ones that are supposed to be readable with
|
||||||
## with this host's public key, and add them correctly to the configuration
|
## public key, and create a mapping from `<name>.file` to the absolute path of
|
||||||
## as `age.secrets.<name>.file`.
|
## the secret's file.
|
||||||
age.secrets = concatMapAttrs (
|
age.secrets = concatMapAttrs (
|
||||||
name: secret:
|
name: secret:
|
||||||
optionalAttrs (elem config.fediversityVm.hostPublicKey secret.publicKeys) ({
|
optionalAttrs (elem config.fediversityVm.hostPublicKey secret.publicKeys) ({
|
||||||
${removeSuffix ".age" name}.file = secretsPrefix + "/${name}";
|
${removeSuffix ".age" name}.file = secrets.rootPath + "/${name}";
|
||||||
})
|
})
|
||||||
) secrets;
|
) secrets.mapping;
|
||||||
|
|
||||||
## FIXME: Remove direct root authentication once the NixOps4 NixOS provider
|
## FIXME: Remove direct root authentication once the NixOps4 NixOS provider
|
||||||
## supports users with password-less sudo.
|
## supports users with password-less sudo.
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
{
|
{
|
||||||
inputs,
|
inputs,
|
||||||
lib,
|
lib,
|
||||||
|
sources,
|
||||||
|
keys,
|
||||||
|
secrets,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
@ -13,7 +16,6 @@ let
|
||||||
filterAttrs
|
filterAttrs
|
||||||
;
|
;
|
||||||
inherit (lib.attrsets) genAttrs;
|
inherit (lib.attrsets) genAttrs;
|
||||||
sources = import ../../npins;
|
|
||||||
|
|
||||||
## Given a machine's name and whether it is a test VM, make a resource module,
|
## Given a machine's name and whether it is a test VM, make a resource module,
|
||||||
## except for its missing provider. (Depending on the use of that resource, we
|
## except for its missing provider. (Depending on the use of that resource, we
|
||||||
|
@ -22,7 +24,14 @@ let
|
||||||
{ vmName, isTestVm }:
|
{ vmName, isTestVm }:
|
||||||
{
|
{
|
||||||
# TODO(@fricklerhandwerk): this is terrible but IMO we should just ditch flake-parts and have our own data model for how the project is organised internally
|
# TODO(@fricklerhandwerk): this is terrible but IMO we should just ditch flake-parts and have our own data model for how the project is organised internally
|
||||||
_module.args = { inherit inputs; };
|
_module.args = {
|
||||||
|
inherit
|
||||||
|
inputs
|
||||||
|
sources
|
||||||
|
keys
|
||||||
|
secrets
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
imports =
|
imports =
|
||||||
[
|
[
|
||||||
|
@ -35,7 +44,7 @@ let
|
||||||
{
|
{
|
||||||
nixos.module.users.users.root.openssh.authorizedKeys.keys = [
|
nixos.module.users.users.root.openssh.authorizedKeys.keys = [
|
||||||
# allow our panel vm access to the test machines
|
# allow our panel vm access to the test machines
|
||||||
(import ../keys).panel
|
keys.panel
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
1
keys/flake-part.nix
Normal file
1
keys/flake-part.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{ _module.args.keys = import ./.; }
|
4
secrets/default.nix
Normal file
4
secrets/default.nix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
mapping = import ./secrets.nix;
|
||||||
|
rootPath = ./.;
|
||||||
|
}
|
1
secrets/flake-part.nix
Normal file
1
secrets/flake-part.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{ _module.args.secrets = import ./.; }
|
Loading…
Add table
Reference in a new issue