-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
277 lines (241 loc) · 8.85 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
{
description = "Peter's NixOS and Home Manager Configuration";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
nur.url = "github:nix-community/NUR"; # https://nur.nix-community.org/
home-manager.url = "github:nix-community/home-manager/release-24.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
bashrc.url = "github:pjones/bashrc";
bashrc.inputs.nixpkgs.follows = "nixpkgs";
desktop-scripts.url = "github:pjones/desktop-scripts";
desktop-scripts.inputs.nixpkgs.follows = "nixpkgs";
emacsrc.url = "github:pjones/emacsrc/nixos-24.05";
emacsrc.inputs.nixpkgs.follows = "nixpkgs";
emacsrc.inputs.home-manager.follows = "home-manager";
emacsrc.inputs.desktop-scripts.follows = "desktop-scripts";
superkey.url = "github:pjones/superkey";
superkey.inputs.nixpkgs.follows = "nixpkgs";
superkey.inputs.home-manager.follows = "home-manager";
superkey.inputs.emacsrc.follows = "emacsrc";
superkey.inputs.desktop-scripts.follows = "desktop-scripts";
encryption-utils.url = "github:pjones/encryption-utils";
encryption-utils.inputs.nixpkgs.follows = "nixpkgs";
haskellrc.url = "github:pjones/haskellrc";
haskellrc.inputs.nixpkgs.follows = "nixpkgs";
image-scripts.url = "github:pjones/image-scripts";
image-scripts.inputs.nixpkgs.follows = "nixpkgs";
kmonad.url = "github:kmonad/kmonad?dir=nix";
maintenance-scripts.url = "github:pjones/maintenance-scripts";
maintenance-scripts.inputs.nixpkgs.follows = "nixpkgs";
mediarc.url = "github:pjones/mediarc";
mediarc.inputs.nixpkgs.follows = "nixpkgs";
network-scripts.url = "github:pjones/network-scripts";
network-scripts.inputs.nixpkgs.follows = "nixpkgs";
tmuxrc.url = "github:pjones/tmuxrc";
tmuxrc.inputs.nixpkgs.follows = "nixpkgs";
zshrc.url = "github:pjones/zshrc";
zshrc.inputs.nixpkgs.follows = "nixpkgs";
# For packages I'm building directly:
firefox-csshacks = {
url = "github:MrOtherGuy/firefox-csshacks";
flake = false;
};
tridactyl_emacs_config = {
url = "github:jumper047/tridactyl_emacs_config/5674d6bb38abbe639dd8caaf3d81f33fc06f59fd";
flake = false;
};
};
outputs = inputs@{ self, nixpkgs, home-manager, ... }:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
# OpenJDK prevents this from working:
# "armv7l-linux"
];
hosts = [
"kilgrave"
"sid"
"ursula"
];
# Function to generate a set based on supported systems:
forAllSystems = f:
nixpkgs.lib.genAttrs supportedSystems (system: f system);
# Like `forAllSystems` except just those that are Linux:
forLinuxSystems = f: builtins.listToAttrs
(builtins.filter (set: set ? name)
(builtins.map
(system:
let pkgs = nixpkgsFor.${system}; in
nixpkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
name = system;
value = f system;
})
supportedSystems));
# Package overlay:
overlays = {
bashrc = inputs.bashrc.overlay;
desktop-scripts = self.inputs.desktop-scripts.overlays.desktop-scripts;
encryption-utils = inputs.encryption-utils.overlay;
image-scripts = inputs.image-scripts.overlays.default;
maintenance-scripts = inputs.maintenance-scripts.overlay;
mediarc = inputs.mediarc.overlays.mediarc;
network-scripts = inputs.network-scripts.overlay;
nur = inputs.nur.overlay;
superkey = self.inputs.superkey.overlays.superkey;
tilde = import pkgs/overlay.nix { inherit inputs; };
tmuxrc = inputs.tmuxrc.overlay;
zshrc = inputs.zshrc.overlay;
};
# Attribute set of nixpkgs for each system:
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = builtins.attrValues overlays;
});
# A NixOS module that bootstraps the tilde home manager modules:
nixosBootstrapHomeManager = { config, pkgs, ... }: {
home-manager = {
backupFileExtension = "backup";
useGlobalPkgs = true;
useUserPackages = true;
users.${config.tilde.username} = { ... }: {
imports = [
./home
inputs.emacsrc.homeManagerModules.default
inputs.haskellrc.homeManagerModules.default
inputs.superkey.homeManagerModules.default
];
};
};
};
in
{
inherit overlays;
##########################################################################
# NixOS module for importing into your system flake:
nixosModules =
let
hostFrom = path: { ... }: {
imports = [
self.nixosModules.tilde
(import path { inherit self; })
];
};
hostModules = builtins.listToAttrs (map
(host: {
name = host;
value = hostFrom ./devices/${host}.nix;
})
hosts);
in
{
# Base module:
tilde = { pkgs, ... }: {
imports = [
./nixos
home-manager.nixosModules.home-manager
nixosBootstrapHomeManager
inputs.kmonad.nixosModules.default
inputs.superkey.nixosModules.default
];
};
} // hostModules;
##########################################################################
# A generic NixOS configuration that can be used as a demo:
nixosConfigurations = {
demo = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
{ nixpkgs.pkgs = nixpkgsFor.x86_64-linux; }
self.nixosModules.tilde
self.inputs.superkey.nixosModules.autologin
self.inputs.superkey.nixosModules.qemu-sway
./test/demo.nix
];
};
};
##########################################################################
packages = forLinuxSystems (system:
let pkgs = nixpkgsFor.${system};
in {
default = self.nixosConfigurations.demo.config.system.build.vm;
screenshot = import test/screenshot.nix {
inherit self pkgs;
module = self.nixosModules.tilde;
};
} // self.overlays.tilde pkgs pkgs);
##########################################################################
apps = forLinuxSystems (system:
let pkgs = nixpkgsFor.${system};
in {
# Launch a VM running Peter's configuration:
default = {
type = "app";
program = "${self.packages.${system}.default}/bin/run-tilde-demo-vm";
};
# Run a VM then take a screenshot and store it locally:
screenshot =
let
script = pkgs.writeShellScript "screenshot" ''
cp --force \
${self.packages.${system}.screenshot}/screen.png \
support/screenshot.png
'';
in
{
type = "app";
program = "${script}";
};
});
##########################################################################
checks = forLinuxSystems (system:
let
pkgs = nixpkgsFor.${system};
module = self.nixosModules.tilde;
test = path: import path { inherit pkgs module; };
machine = module:
let
machine = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
{ nixpkgs.pkgs = nixpkgsFor.${system}; }
test/vm.nix
module
];
};
in
machine.config.system.build.vm;
hostChecks = builtins.listToAttrs (map
(host: {
name = host;
value = machine self.nixosModules.${host};
})
hosts);
in
{
# Tests:
config = test test/config.nix;
cron = test test/cron.nix;
emacs = inputs.emacsrc.checks.${system}.default;
superkey-sway = inputs.superkey.checks.${system}.sway;
superkey-greetd = inputs.superkey.checks.${system}.greetd;
} // hostChecks);
##########################################################################
devShells = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; in
{
default = pkgs.mkShell {
NIX_PATH = "nixpkgs=${pkgs.path}";
buildInputs = [
inputs.home-manager.outputs.defaultPackage.${system}
pkgs.neofetch
pkgs.nixpkgs-fmt
];
};
});
};
}