mirror of
https://github.com/nickolaj-jepsen/nixos.git
synced 2026-01-22 16:16:50 +01:00
complete rework v2
This commit is contained in:
parent
16813aeef9
commit
7409e9ca10
106 changed files with 1522 additions and 403 deletions
53
lib/builder.nix
Normal file
53
lib/builder.nix
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
args @ {
|
||||
lib,
|
||||
withSystem,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
inherit (import ./. args) recursiveMerge;
|
||||
mkBase = {system ? "x86_64-linux", ...}:
|
||||
withSystem system (
|
||||
{
|
||||
pkgs,
|
||||
system,
|
||||
...
|
||||
}: {
|
||||
inherit system;
|
||||
specialArgs = {inherit inputs pkgs;};
|
||||
modules = [
|
||||
inputs.disko.nixosModules.disko
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
];
|
||||
}
|
||||
);
|
||||
mkNixos = args:
|
||||
inputs.nixpkgs.lib.nixosSystem (recursiveMerge [
|
||||
(mkBase args)
|
||||
args
|
||||
]);
|
||||
in {
|
||||
mkHosts = root: let
|
||||
hosts = attrNames (filterAttrs (_: type: type == "directory") (builtins.readDir root));
|
||||
|
||||
hostDirs = builtins.listToAttrs (
|
||||
lib.map (hostName: lib.nameValuePair hostName (lib.path.append root hostName)) hosts
|
||||
);
|
||||
|
||||
hostResolved =
|
||||
lib.mapAttrs (
|
||||
_: hostDir: (lib.map (fileName: lib.path.append hostDir fileName) (attrNames (builtins.readDir hostDir)))
|
||||
)
|
||||
hostDirs;
|
||||
|
||||
hostsConfig = mapAttrs (_: configs: mkNixos {modules = configs;}) hostResolved;
|
||||
in
|
||||
hostsConfig;
|
||||
|
||||
mkVm = configs:
|
||||
inputs.nixos-generators.nixosGenerate {
|
||||
modules = configs;
|
||||
format = "qcow";
|
||||
system = "x86_64-linux";
|
||||
};
|
||||
}
|
||||
4
lib/default.nix
Normal file
4
lib/default.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
args: {
|
||||
inherit (import ./util.nix args) recursiveMerge;
|
||||
inherit (import ./builder.nix args) mkNixos mkHosts mkVm;
|
||||
}
|
||||
17
lib/util.nix
Normal file
17
lib/util.nix
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{lib, ...}:
|
||||
with lib; {
|
||||
recursiveMerge = attrList: let
|
||||
f = attrPath:
|
||||
zipAttrsWith (
|
||||
n: values:
|
||||
if tail values == []
|
||||
then head values
|
||||
else if all isList values
|
||||
then unique (concatLists values)
|
||||
else if all isAttrs values
|
||||
then f (attrPath ++ [n]) values
|
||||
else last values
|
||||
);
|
||||
in
|
||||
f [] attrList;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue