mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-11 07:10:39 +02:00
refactor: centralize definition of MicroVM node names
This commit is contained in:
parent
d7f69c5baa
commit
cbcd3c943b
3 changed files with 34 additions and 15 deletions
16
flake.nix
16
flake.nix
|
@ -106,15 +106,13 @@
|
||||||
|
|
||||||
colmena = import ./nix/colmena.nix inputs;
|
colmena = import ./nix/colmena.nix inputs;
|
||||||
colmenaNodes = ((colmena.lib.makeHive self.colmena).introspect (x: x)).nodes;
|
colmenaNodes = ((colmena.lib.makeHive self.colmena).introspect (x: x)).nodes;
|
||||||
microvmNodes =
|
# Collect all defined microvm nodes from each colmena node
|
||||||
nixpkgs.lib.concatMapAttrs
|
microvmNodes = nixpkgs.lib.concatMapAttrs (_: node:
|
||||||
(nodeName: nodeAttrs:
|
nixpkgs.lib.mapAttrs'
|
||||||
nixpkgs.lib.mapAttrs'
|
(vm: def: nixpkgs.lib.nameValuePair def.nodeName node.config.microvm.vms.${vm})
|
||||||
# TODO This is duplicated three times. This is microvm naming #3
|
(node.config.extra.microvms.vms or {}))
|
||||||
# TODO maybe use microvm.vms.<name>.compoundName
|
self.colmenaNodes;
|
||||||
(n: nixpkgs.lib.nameValuePair "${nodeName}-${n}")
|
# Expose all nodes in a single attribute
|
||||||
(self.colmenaNodes.${nodeName}.config.microvm.vms or {}))
|
|
||||||
self.colmenaNodes;
|
|
||||||
nodes = self.colmenaNodes // self.microvmNodes;
|
nodes = self.colmenaNodes // self.microvmNodes;
|
||||||
|
|
||||||
# Collect installer packages
|
# Collect installer packages
|
||||||
|
|
|
@ -59,14 +59,24 @@
|
||||||
'';
|
'';
|
||||||
|
|
||||||
microvm.vms.${vmName} = let
|
microvm.vms.${vmName} = let
|
||||||
|
# Loads configuration from a subfolder of this nodes configuration, if it exists.
|
||||||
|
configPath =
|
||||||
|
if nodePath == null
|
||||||
|
then null
|
||||||
|
else nodePath + "/microvms/${vmName}";
|
||||||
|
|
||||||
node =
|
node =
|
||||||
(import ../nix/generate-node.nix inputs)
|
(import ../nix/generate-node.nix inputs)
|
||||||
# TODO This is duplicated three times. This is microvm naming #1
|
vmCfg.nodeName
|
||||||
"${nodeName}-${vmName}"
|
|
||||||
{
|
{
|
||||||
inherit (vmCfg) system;
|
inherit (vmCfg) system;
|
||||||
# TODO make this configurable (or even disableable)
|
# Load configPath, if it exists.
|
||||||
config = nodePath + "/microvms/${vmName}";
|
${
|
||||||
|
if configPath != null && builtins.pathExists configPath
|
||||||
|
then "config"
|
||||||
|
else null
|
||||||
|
} =
|
||||||
|
configPath;
|
||||||
};
|
};
|
||||||
mac = net.mac.addPrivate vmCfg.id cfg.networking.baseMac;
|
mac = net.mac.addPrivate vmCfg.id cfg.networking.baseMac;
|
||||||
in {
|
in {
|
||||||
|
@ -292,6 +302,16 @@ in {
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
options = {
|
options = {
|
||||||
|
nodeName = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "${nodeName}-${name}";
|
||||||
|
description = mdDoc ''
|
||||||
|
The name of the resulting node. By default this will be a compound name
|
||||||
|
of the host's name and the vm's name to avoid name clashes. Can be
|
||||||
|
overwritten to designate special names to specific vms.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
id = mkOption {
|
id = mkOption {
|
||||||
type =
|
type =
|
||||||
types.addCheck types.int (x: x > 1)
|
types.addCheck types.int (x: x > 1)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
attrNames
|
attrNames
|
||||||
literalExpression
|
literalExpression
|
||||||
mapAttrs
|
mapAttrs
|
||||||
|
mdDoc
|
||||||
mkIf
|
mkIf
|
||||||
mkOption
|
mkOption
|
||||||
types
|
types
|
||||||
|
@ -43,7 +44,7 @@ in {
|
||||||
defineNixExtraBuiltins = mkOption {
|
defineNixExtraBuiltins = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
description = ''
|
description = mdDoc ''
|
||||||
Add nix-plugins and the correct extra-builtin-files definition to this host's
|
Add nix-plugins and the correct extra-builtin-files definition to this host's
|
||||||
nix configuration, so that it can be used to decrypt the secrets in this repository.
|
nix configuration, so that it can be used to decrypt the secrets in this repository.
|
||||||
'';
|
'';
|
||||||
|
@ -53,7 +54,7 @@ in {
|
||||||
default = {};
|
default = {};
|
||||||
type = types.attrsOf types.path;
|
type = types.attrsOf types.path;
|
||||||
example = literalExpression "{ local = ./secrets.nix.age; }";
|
example = literalExpression "{ local = ./secrets.nix.age; }";
|
||||||
description = ''
|
description = mdDoc ''
|
||||||
This file manages the origin for this machine's repository-secrets. Anything that is
|
This file manages the origin for this machine's repository-secrets. Anything that is
|
||||||
technically not a secret in the classical sense (i.e. that it has to be protected
|
technically not a secret in the classical sense (i.e. that it has to be protected
|
||||||
after it has been deployed), but something you want to keep secret from the public;
|
after it has been deployed), but something you want to keep secret from the public;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue