nix-config/nix/hosts.nix

94 lines
3.3 KiB
Nix
Raw Normal View History

2024-11-03 21:34:38 +01:00
{ inputs, self, ... }:
2024-08-08 21:38:44 +02:00
{
flake =
{ config, lib, ... }:
2024-07-26 22:12:48 +02:00
let
2024-08-08 21:38:44 +02:00
inherit (lib)
concatMapAttrs
filterAttrs
flip
genAttrs
mapAttrs'
nameValuePair
;
2023-09-20 14:37:21 +02:00
2024-08-08 21:38:44 +02:00
# Creates a new nixosSystem with the correct specialArgs, pkgs and name definition
mkHost =
{ minimal }:
name:
let
pkgs = config.pkgs.x86_64-linux;
2024-08-23 00:30:11 +02:00
stateVersion = "24.05";
2024-08-08 21:38:44 +02:00
in
2024-11-03 21:34:38 +01:00
(import "${self.nixpkgs-patched}/nixos/lib/eval-config.nix") {
system = null;
2024-08-08 21:38:44 +02:00
specialArgs = {
# Use the correct instance lib that has our overlays
inherit (pkgs) lib;
inherit (config) nodes;
2024-11-03 21:34:38 +01:00
inherit minimal stateVersion;
inputs = inputs // {
nixpkgs = self.nixpkgs-patched;
};
2024-08-08 21:38:44 +02:00
};
modules = [
{
# We cannot force the package set via nixpkgs.pkgs and
# inputs.nixpkgs.nixosModules.readOnlyPkgs, since some nixosModules
# like nixseparatedebuginfod depend on adding packages via nixpkgs.overlays.
# So we just mimic the options and overlays defined by the passed pkgs set.
node.name = name;
node.secretsDir = ../. + "/hosts/${name}/secrets";
2024-08-19 16:13:36 +02:00
nixpkgs.overlays = (import ../pkgs inputs) ++ [
2024-08-08 21:38:44 +02:00
# nixpkgs-wayland.overlay
inputs.nixos-extra-modules.overlays.default
inputs.nix-topology.overlays.default
inputs.devshell.overlays.default
inputs.agenix-rekey.overlays.default
inputs.nixvim.overlays.default
];
nixpkgs.config.allowUnfree = true;
}
../hosts/${name}
];
};
2023-09-20 14:37:21 +02:00
2024-08-08 21:38:44 +02:00
# Load the list of hosts that this flake defines, which
# associates the minimum amount of metadata that is necessary
# to instanciate hosts correctly.
hosts = builtins.attrNames (filterAttrs (_: type: type == "directory") (builtins.readDir ../hosts));
in
# Process each nixosHosts declaration and generatea nixosSystem definitions
{
nixosConfigurations = genAttrs hosts (mkHost {
minimal = false;
});
minimalConfigurations = genAttrs hosts (mkHost {
minimal = true;
});
# True NixOS nodes can define additional guest nodes that are built
# together with it. We collect all defined guests from each node here
# to allow accessing any node via the unified attribute `nodes`.
guestConfigurations = flip concatMapAttrs config.nixosConfigurations (
_: node:
flip mapAttrs' (node.config.guests or { }) (
guestName: guestDef:
nameValuePair guestDef.nodeName (
if guestDef.backend == "microvm" then
node.config.microvm.vms.${guestName}.config
else
node.config.containers.${guestName}.nixosConfiguration
)
)
);
# All nixosSystem instanciations are collected here, so that we can refer
# to any system via nodes.<name>
nodes = config.nixosConfigurations // config.guestConfigurations;
2024-11-21 20:37:07 +01:00
wireguardEvalCache = config.pkgs.x86_64-linux.lib.wireguard.createEvalCache inputs [
"scrtiny-patrick"
"elisabeth"
];
2024-08-08 21:38:44 +02:00
};
2023-09-20 14:37:21 +02:00
}