-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
250 lines (221 loc) · 6.8 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
{
description = "Copper's NixOS and Home Manager configurations";
inputs = {
# Common Inputs
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-search-cli = {
url = "github:peterldowns/nix-search-cli";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-compat.follows = "flake-compat";
inputs.flake-utils.follows = "flake-utils";
};
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.home-manager.follows = "home-manager";
};
# NixOS inputs
# Secure Boot
lanzaboote = {
url = "github:nix-community/lanzaboote";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
inputs.flake-compat.follows = "flake-compat";
inputs.flake-utils.follows = "flake-utils";
};
# The Window Manager I use
hyprland = {
url = "github:hyprwm/Hyprland";
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
};
# Support for erasing / on every boot
impermanence.url = "github:nix-community/impermanence";
# Declerative disk formatting
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
# NixOS installation on running servers
nixos-anywhere = {
url = "github:numtide/nixos-anywhere";
inputs.nixpkgs.follows = "nixpkgs";
inputs.disko.follows = "disko";
inputs.flake-parts.follows = "flake-parts";
};
# Provides a pre-built index database describing which binaries are
# available in which packages
nix-index-database = {
url = "github:Mic92/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs";
};
# Darwin Inputs
nix-darwin = {
url = "github:LnL7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs";
};
# Install Homebrew via Nix
nix-homebrew = {
url = "github:zhaofengli/nix-homebrew";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.nix-darwin.follows = "nix-darwin";
};
# Only for deduplication of other transitive dependencies
flake-parts = {
url = "github:hercules-ci/flake-parts";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
systems = {
url = "github:nix-systems/default";
};
};
outputs = {
self,
nixpkgs,
home-manager,
nix-darwin,
...
} @ inputs: let
lib = import ./lib inputs;
inherit (lib) loadDir loadDirRec mkFeatureModule injectArgs;
forAllSystems = f:
nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"] (s:
f (import nixpkgs {
system = s;
config.allowUnfree = true;
}));
specialArgs_ = {
inherit inputs;
inherit (self) outputs;
};
loadModules = base: name:
nixpkgs.lib.mapAttrs (_: injectArgs specialArgs_) (
loadDirRec (base + "/modules/common") ({path, ...}: import path)
// loadDirRec (base + "/modules/${name}") ({path, ...}: import path)
# TODO: consider moving this to modules/feature subdirectory;
// nixpkgs.lib.mapAttrs' (name: value: {
name = "feature/${name}";
inherit value;
}) (loadDirRec (base + "/features/${name}") (
{
name,
path,
...
}:
mkFeatureModule {
name = builtins.replaceStrings ["/"] ["."] name;
cfg = import path;
}
))
);
loadSystems = {
constructor,
copperModules,
}: {
dir,
extraModules ? [],
withCopperModules ? true,
specialArgs ? specialArgs_,
}:
loadDir dir ({
path,
name,
...
}: let
modules =
[
(import path)
({lib, ...}: {
networking.hostName = lib.mkOverride 999 (lib.removeSuffix ".nix" name);
})
]
++ nixpkgs.lib.optionals withCopperModules (copperModules
++ [
({lib, ...}: {
copper.feature.base.enable = lib.mkDefault true;
})
])
++ extraModules;
in
constructor {
inherit modules specialArgs;
});
loadNixos = loadSystems {
constructor = nixpkgs.lib.nixosSystem;
copperModules = nixpkgs.lib.attrValues self.outputs.nixosModules;
};
loadDarwin = loadSystems {
constructor = nix-darwin.lib.darwinSystem;
copperModules = nixpkgs.lib.attrValues self.outputs.darwinModules;
};
loadHome = {
dir,
extraModules ? [],
withCopperModules ? true,
specialArgs ? specialArgs_,
}:
loadDir dir ({
path,
name,
...
}: let
user = import path;
username = builtins.elemAt (nixpkgs.lib.splitString "@" name) 0;
modules =
(nixpkgs.lib.optionals withCopperModules (nixpkgs.lib.attrValues self.outputs.homeModules
++ [
({lib, ...}: {
copper.feature.standaloneBase.enable = lib.mkDefault true;
})
]))
++ extraModules
++ [
({lib, ...}: {
home.username = lib.mkDefault username;
})
]
++ user.modules or [];
in
home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.${user.system};
inherit modules;
extraSpecialArgs = specialArgs;
});
in {
lib =
lib
// {
# TODO: move these defintions from flake.nix into a lib file
inherit loadNixos loadHome loadDarwin loadModules;
};
# Shell for bootstrapping either a NixOS or Home-Manager config
devShells = forAllSystems (pkgs: import ./shell.nix {inherit pkgs;});
# Required to make nix fmt work
formatter = forAllSystems (pkgs: pkgs.alejandra);
apps = forAllSystems (pkgs: import ./apps (inputs // {inherit pkgs;}));
packages = forAllSystems (pkgs: pkgs.lib.filterAttrs (n: v: v != null) (import ./packages (inputs // {inherit pkgs;})));
overlays = import ./overlays {
inherit inputs;
inherit (self) outputs;
};
templates = import ./templates;
nixosModules = loadModules ./. "nixos";
homeModules = loadModules ./. "home-manager";
darwinModules = loadModules ./. "darwin";
nixosConfigurations = loadNixos {dir = ./hosts/nixos;};
homeConfigurations = loadHome {dir = ./users;};
darwinConfigurations = loadDarwin {dir = ./hosts/darwin;};
};
}