-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
191 lines (168 loc) · 6.26 KB
/
Copy pathflake.nix
File metadata and controls
191 lines (168 loc) · 6.26 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
{
# see the following sources
# https://github.com/malob/nixpkgs
# https://github.com/kclejeune/system/blob/master/flake.nix
description = "jak system configs";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs-stable.url = "github:nixos/nixpkgs/nixpkgs-26.05-darwin";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixpkgs-master.url = "github:nixos/nixpkgs/master";
nixos-stable.url = "github:nixos/nixpkgs/nixos-26.05";
nixos-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
darwin = {
url = "github:LnL7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
home-manager = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
nix-homebrew.url = "github:zhaofengli/nix-homebrew";
zi = {
url = "github:z-shell/zi/main";
flake = false;
};
cookbook.url = "github:jkeifer/homebrew-cookbook";
};
outputs = inputs@{ self, darwin, home-manager, flake-utils, nix-homebrew, ... }:
let
inherit (darwin.lib) darwinSystem;
inherit (home-manager.lib) homeManagerConfiguration;
inherit (inputs.nixpkgs-unstable.lib) mkDefault;
inherit (inputs.nixos-unstable.lib) nixosSystem;
nixpkgsConfig = rec {
config = {
allowUnsupportedSystem = true;
allowUnfree = true;
allowBroken = false;
};
overlays = [ self.overlays.default ];
};
supportedSystems = [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" "aarch64-linux" ];
# Shared module configuration for all Darwin systems
darwinModules = [
home-manager.darwinModules.home-manager
nix-homebrew.darwinModules.nix-homebrew
./modules/users.nix
./modules/common
./modules/darwin
./modules/home-manager.nix
];
# Shared module configuration for all NixOS systems
nixosModules = [
home-manager.nixosModules.home-manager
./modules/users.nix
./modules/common
./modules/nixos
./modules/home-manager.nix
];
# Common configuration injected into all systems
commonConfig = {
nixpkgs = nixpkgsConfig;
nix.registry.my.flake = self;
};
# Helper to build Darwin systems with consistent configuration
# The host directory name doubles as the default hostname
mkDarwin = name: hostModule:
darwinSystem {
modules = darwinModules ++ [
hostModule
commonConfig
{
networking.hostName = mkDefault name;
networking.computerName = mkDefault name;
}
];
specialArgs = { inherit self inputs; };
};
# Helper to build NixOS systems with consistent configuration
# The host directory name doubles as the default hostname
mkNixos = name: hostModule:
nixosSystem {
modules = nixosModules ++ [
hostModule
commonConfig
{ networking.hostName = mkDefault name; }
];
specialArgs = { inherit self inputs; };
};
# Helper to build home-manager configurations with consistent configuration
# Uses builtins.currentSystem so configs work on whatever machine evaluates them.
mkHome = _name: hostDir:
let
pkgs = import inputs.nixpkgs-unstable {
system = builtins.currentSystem;
inherit (nixpkgsConfig) config overlays;
};
in homeManagerConfiguration {
inherit pkgs;
modules = [ hostDir ];
extraSpecialArgs = { inherit self inputs; };
};
# Automatically discover host configurations from directories
mkHostConfigs = dir: constructor:
let
entries = builtins.readDir dir;
hosts = builtins.filter (name: entries.${name} == "directory" && name != "_common") (builtins.attrNames entries);
in
builtins.listToAttrs (map (host: {
name = host;
value = constructor host (dir + "/${host}");
}) hosts);
in {
darwinConfigurations = mkHostConfigs ./hosts/darwin mkDarwin;
nixosConfigurations = mkHostConfigs ./hosts/nixos mkNixos;
homeConfigurations = mkHostConfigs ./hosts/home-manager mkHome;
overlays.default = import ./overlays inputs;
# Validation checks -- run `nix flake check --no-build` to evaluate all configs
# homeConfigurations use builtins.currentSystem so they can't be checked
# in pure evaluation mode; validate them with `nix build .#homeConfigurations.<name>.activationPackage`
checks = let
# Map each darwin config's toplevel derivation into checks for its system
darwinChecks = builtins.mapAttrs
(name: cfg: cfg.config.system.build.toplevel)
self.darwinConfigurations;
# Map each nixos config's toplevel derivation
nixosChecks = builtins.mapAttrs
(name: cfg: cfg.config.system.build.toplevel)
self.nixosConfigurations;
# Group all checks by their target system
groupBySystem = configs: getSystem:
builtins.foldl' (acc: name:
let
sys = getSystem configs.${name};
in acc // { ${sys} = (acc.${sys} or {}) // { ${name} = configs.${name}; }; }
) {} (builtins.attrNames configs);
in
groupBySystem darwinChecks (drv: drv.system)
// groupBySystem nixosChecks (drv: drv.system);
} // flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = import inputs.nixpkgs-unstable { inherit system; inherit (nixpkgsConfig) config overlays; };
in {
legacyPackages = pkgs;
formatter = pkgs.nixfmt;
devShells.default = pkgs.mkShell {
name = "nixpkgs-dev";
packages = with pkgs; [
nixfmt
statix
deadnix
];
};
packages = {
nixlify = pkgs.writeShellScriptBin "nixlify" ''
exec ${self.outPath}/bin/nixlify "$@"
'';
nixdiff = pkgs.writeShellScriptBin "nixdiff" ''
exec ${self.outPath}/bin/lib/nixdiff "$@"
'';
};
}
);
}