112 lines
4.2 KiB
Nix
112 lines
4.2 KiB
Nix
|
{
|
||
|
inputs = {
|
||
|
nixpkgs.url = "nixpkgs/nixos-24.05";
|
||
|
unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||
|
numbers.url = "git+https://git.strudelline.net/cascade/numbers";
|
||
|
interlude.url = "git+https://git.strudelline.net/nix/interlude";
|
||
|
nixos-generators = { url = "github:nix-community/nixos-generators"; inputs.nixpkgs.follows = "nixpkgs"; };
|
||
|
deploy-rs.url = "github:serokell/deploy-rs";
|
||
|
};
|
||
|
outputs = { self, nixpkgs, unstable, numbers, interlude, nixos-generators, deploy-rs }@inputs:
|
||
|
with builtins;
|
||
|
with nixpkgs.lib;
|
||
|
with interlude.lib;
|
||
|
let
|
||
|
includableModules =
|
||
|
let localModules = "${./.}" + "/modules";
|
||
|
dirContents = readDir (traceVal localModules);
|
||
|
filenames = attrNames (trace "dirContents: ${toJSON dirContents}" dirContents);
|
||
|
dirs = (filter (n: dirContents."${n}" == "directory" &&
|
||
|
readFileType "${localModules}/${n}/default.nix" == "regular" ) filenames);
|
||
|
files = concatMap (filterAndStripSuffix ".nix") (filter (n: dirContents."${n}" == "regular") filenames);
|
||
|
in
|
||
|
foldl recursiveUpdate {} (
|
||
|
(map (x: { nixosModules."${x}" = import (trace "importing ${localModules}/${x}" "${localModules}/${x}"); }) (trace "dirs: ${toJSON dirs}" dirs))
|
||
|
++ (map (x: { nixosModules."${x}" = import (trace "importing ${localModules}/${x}.nix" "${localModules}/${x}.nix"); }) (trace "files: ${toJSON files}" files))
|
||
|
);
|
||
|
buildMachine' = name: mods: cfg: {
|
||
|
# the evaluated machine
|
||
|
nixosConfigurations."${name}" =
|
||
|
let
|
||
|
pkgs = import nixpkgs { config = { allowUnfree = true; };};
|
||
|
specialArgs = { basePath = "${toString ./.}"; inherit inputs numbers; };
|
||
|
in nixosSystem (cfg // {
|
||
|
inherit pkgs specialArgs;
|
||
|
modules = [
|
||
|
self.nixosModules.vmFormats
|
||
|
numbers.nixosModules.users
|
||
|
self.nixosModules.session
|
||
|
({...}: {
|
||
|
# fixed values.
|
||
|
networking.hostName = traceVal name;
|
||
|
system.stateVersion = "24.05";
|
||
|
nix.settings.require-sigs = false;
|
||
|
})
|
||
|
] ++ mods;
|
||
|
});
|
||
|
};
|
||
|
buildMachine = name:
|
||
|
# the evaluated machine
|
||
|
with numbers.api;
|
||
|
let
|
||
|
modules = [
|
||
|
self.nixosModules.fixFlakeRegistry
|
||
|
numbers.nixosModules.networking
|
||
|
self.nixosModules.packages
|
||
|
self.nixosModules.luks
|
||
|
self.nixosModules.systemd-efi
|
||
|
numbers.nixosModules.users
|
||
|
] ++ (map (x: self.nixosModules."${x}") (hostModules name));
|
||
|
arch = hostSystem name;
|
||
|
in
|
||
|
(buildMachine' name modules { system = arch; })
|
||
|
//
|
||
|
{
|
||
|
deploy.nodes."${name}" = {
|
||
|
hostname = "172.16.19.1";
|
||
|
profiles.system = {
|
||
|
user = "root";
|
||
|
path = deploy-rs.lib."${arch}".activate.nixos self.nixosConfigurations."${name}";
|
||
|
};
|
||
|
};
|
||
|
|
||
|
# This is highly advised, and will prevent many possible mistakes
|
||
|
checks = deploy-rs.lib."${arch}".deployChecks self.deploy;
|
||
|
};
|
||
|
in
|
||
|
foldl recursiveUpdate {
|
||
|
nixosModules = {
|
||
|
vmFormats = { config, ... }: {
|
||
|
imports = [
|
||
|
nixos-generators.nixosModules.all-formats
|
||
|
];
|
||
|
|
||
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||
|
|
||
|
formatConfigs.iso = { ... }: {
|
||
|
isoImage.squashfsCompression = "zstd";
|
||
|
};
|
||
|
|
||
|
# the sample format from nixos-generators
|
||
|
# formatConfigs.my-custom-format = { config, modulesPath, ... }: {
|
||
|
# imports = [ "${toString modulesPath}/installer/cd-dvd/installation-cd-base.nix" ];
|
||
|
# formatAttr = "isoImage";
|
||
|
# fileExtension = ".iso";
|
||
|
# networking.wireless.networks = {
|
||
|
# # ...
|
||
|
# };
|
||
|
# };
|
||
|
};
|
||
|
fixFlakeRegistry = { ... }: { nix.registry = {
|
||
|
nixpkgs.flake = inputs.nixpkgs;
|
||
|
unstable.flake = inputs.unstable;
|
||
|
};};
|
||
|
};
|
||
|
} ( # lists to recursively merge into the config.
|
||
|
[ includableModules ]
|
||
|
++ (with numbers.api; map (h: buildMachine h) deployableHosts)
|
||
|
++ [(buildMachine' "cascade-installer" [self.nixosModules.installer] {} )]
|
||
|
#++ [(buildMachine' "cascade-installer" [] {} )]
|
||
|
);
|
||
|
}
|