migrate constructSystem to lib/

migrates the bulk of constructSystem to lib/ and splits out the largest
chunks into individual functions (namely SOPS, home-manager, and user creation);

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
2024-05-19 12:29:29 -04:00
committed by Alice Huston
parent 20abca4a8b
commit 0ddf01baef
4 changed files with 184 additions and 142 deletions

View File

@ -2,6 +2,8 @@
{
# create rad-dev namespace for lib
rad-dev = rec {
systems = import ./systems.nix { inherit lib; };
# any(), but checks if any value in the list is true
#
# args:

88
lib/systems.nix Normal file
View File

@ -0,0 +1,88 @@
{ lib, ... }:
rec {
genHostName = hostname: { config.networking.hostName = hostname; };
genHome =
{
inputs,
users,
src,
...
}:
[ inputs.home-manager.nixosModules.home-manager ]
++ (map (user: { home-manager.users.${user} = import (src + "/users/${user}/home.nix"); }) users);
genSops =
{
inputs,
users,
src,
...
}:
[ inputs.sops-nix.nixosModules.sops ]
++ (map (user: {
sops.secrets."${user}/user-password" = {
sopsFile = src + "/users/${user}/secrets.yaml";
neededForUsers = true;
};
}) users);
genUsers =
{ users, src, ... }:
(map (
user:
{
config,
lib,
pkgs,
...
}@args:
{
users.users.${user} = import (src + "/users/${user}") (args // { name = user; });
}
) users);
genWrapper =
var: func: args:
lib.optionals var (func args);
nonX86 = {
config.nixpkgs = {
config.allowUnsupportedSystem = true;
buildPlatform = "x86_64-linux";
};
};
constructSystem =
{
hostname,
users,
inputs,
src,
home ? true,
iso ? [ ],
modules ? [ ],
server ? true,
sops ? true,
system ? "x86_64-linux",
}@args:
lib.nixosSystem {
inherit system;
specialArgs = inputs;
modules =
[
inputs.nixos-modules.nixosModule
(genHostName hostname)
(src + "/systems/${hostname}/hardware.nix")
(src + "/systems/${hostname}/configuration.nix")
]
++ modules
++ (lib.rad-dev.fileList src "modules")
++ genWrapper sops genSops args
++ genWrapper home genHome args
++ genWrapper true genUsers args;
};
}