forked from MonochromeBird/system-constitution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
77 lines (64 loc) · 2 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
nixpkgs-stable.url = "nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nur.url = "github:nix-community/NUR";
};
outputs = inputArgs@{ nixpkgs, nixpkgs-stable, nixpkgs-unstable, home-manager, nur, ... }:
let
args = inputArgs // {
system = "x86_64-linux";
systemPath = ./system;
userPath = ./user;
lawConfig = import ./config.nix;
nur-modules = import nur {
nurpkgs = nixpkgs.legacyPackages.x86_64-linux;
};
};
nixosCustomSystem = { modules }: nixpkgs.lib.nixosSystem {
system = args.system;
specialArgs = args;
modules = [
./system/global.nix
nur.nixosModules.nur
home-manager.nixosModules.home-manager
({ config, lib, pkgs, ... }: {imports = [
((import ./system/law.nix (args // {
inherit config lib pkgs;
pkgs-stable = config.pkgs-stable;
pkgs-unstable = config.pkgs-unstable;
})).makeSystemModulesByPath modules)
];})
];
};
lib = nixpkgs.lib;
utils = import ./system/utils.nix { inherit lib; };
extractConfigurationsFromUserDirectory = user:
let
dir = ./. + "/user/${user}";
hwdir = ./. + "/user/${user}/hardware";
in lib.attrsets.mergeAttrsList (if (utils.hasDirectory dir "hardware") then
(lib.lists.forEach (utils.getDirectories hwdir)
(hw: { "${user}.${hw}" = lib.concatLists [
[ (./. + "/user/${user}/hardware/${hw}/system.nix") ]
(if (utils.hasFile dir "system.nix")
then [ (./. + "/user/${user}/system.nix") ]
else [])
]; })
)
else []);
lawMachines = (lib.attrsets.mergeAttrsList
(lib.lists.forEach (utils.getDirectories ./user)
(user: extractConfigurationsFromUserDirectory user)));
in {
nixosConfigurations = lib.attrsets.mapAttrs
(name: moduleList: nixosCustomSystem {
modules = moduleList;
}) lawMachines;
};
}