-
Notifications
You must be signed in to change notification settings - Fork 34
/
flake.nix
324 lines (297 loc) · 10.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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
{
description = "Malo’s Nix system configs, and some other useful stuff.";
inputs = {
# Package sets
nixpkgs-master.url = "github:NixOS/nixpkgs/master";
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixpkgs-23.11-darwin";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# Environment/system management
darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
_1password-shell-plugins = {
url = "github:1Password/shell-plugins";
inputs.nixpkgs.follows = "nixpkgs-unstable";
inputs.flake-utils.follows = "flake-utils";
};
# Flake utilities
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
flake-utils.url = "github:numtide/flake-utils";
# Utility for watching macOS `defaults`.
prefmanager = {
url = "github:malob/prefmanager";
inputs.nixpkgs.follows = "nixpkgs-unstable";
inputs.flake-compat.follows = "flake-compat";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs =
{
self,
darwin,
home-manager,
flake-utils,
...
}@inputs:
let
inherit (self.lib)
attrValues
makeOverridable
mkForce
optionalAttrs
singleton
;
homeStateVersion = "24.11";
nixpkgsDefaults = {
config = {
allowUnfree = true;
};
overlays =
attrValues self.overlays
++ [ inputs.prefmanager.overlays.prefmanager ]
++ singleton (
final: prev:
(optionalAttrs (prev.stdenv.system == "aarch64-darwin") {
# Sub in x86 version of packages that don't build on Apple Silicon.
inherit (final.pkgs-x86) agda idris2;
})
// {
# Add other overlays here if needed.
}
);
};
primaryUserDefaults = {
username = "malo";
fullName = "Malo Bourgon";
email = "[email protected]";
nixConfigDirectory = "/Users/malo/.config/nixpkgs";
};
in
{
# Add some additional functions to `lib`.
lib = inputs.nixpkgs-unstable.lib.extend (
_: _: {
mkDarwinSystem = import ./lib/mkDarwinSystem.nix inputs;
lsnix = import ./lib/lsnix.nix;
}
);
# Overlays --------------------------------------------------------------------------------{{{
overlays = {
# Overlays to add different versions `nixpkgs` into package set
pkgs-master = _: prev: {
pkgs-master = import inputs.nixpkgs-master {
inherit (prev.stdenv) system;
inherit (nixpkgsDefaults) config;
};
};
pkgs-stable = _: prev: {
pkgs-stable = import inputs.nixpkgs-stable {
inherit (prev.stdenv) system;
inherit (nixpkgsDefaults) config;
};
};
pkgs-unstable = _: prev: {
pkgs-unstable = import inputs.nixpkgs-unstable {
inherit (prev.stdenv) system;
inherit (nixpkgsDefaults) config;
};
};
apple-silicon =
_: prev:
optionalAttrs (prev.stdenv.system == "aarch64-darwin") {
# Add access to x86 packages system is running Apple Silicon
pkgs-x86 = import inputs.nixpkgs-unstable {
system = "x86_64-darwin";
inherit (nixpkgsDefaults) config;
};
};
# Overlay that adds various additional utility functions to `vimUtils`
vimUtils = import ./overlays/vimUtils.nix;
# Overlay that adds some additional Neovim plugins
vimPlugins =
final: prev:
let
inherit (self.overlays.vimUtils final prev) vimUtils;
in
{
vimPlugins = prev.vimPlugins.extend (
_: _:
# Useful for testing/using Vim plugins that aren't in `nixpkgs`.
vimUtils.buildVimPluginsFromFlakeInputs inputs [
# Add flake input names here for a Vim plugin repos
]
// {
# Other Vim plugins
}
);
};
tweaks = final: _: {
# Add temporary overrides here
};
};
# }}}
# Modules -------------------------------------------------------------------------------- {{{
darwinModules = {
# My configurations
malo-bootstrap = import ./darwin/bootstrap.nix;
malo-defaults = import ./darwin/defaults.nix;
malo-general = import ./darwin/general.nix;
malo-homebrew = import ./darwin/homebrew.nix;
# Modules I've created
users-primaryUser = import ./modules/darwin/users.nix;
};
homeManagerModules = {
# My configurations
malo-colors = import ./home/colors.nix;
malo-config-files = import ./home/config-files.nix;
malo-fish = import ./home/fish.nix;
malo-git = import ./home/git.nix;
malo-git-aliases = import ./home/git-aliases.nix;
malo-gh-aliases = import ./home/gh-aliases.nix;
malo-kitty = import ./home/kitty.nix;
malo-neovim = import ./home/neovim.nix;
malo-packages = import ./home/packages.nix;
malo-starship = import ./home/starship.nix;
malo-starship-symbols = import ./home/starship-symbols.nix;
# Modules I've created
colors = import ./modules/home/colors;
programs-neovim-extras = import ./modules/home/programs/neovim/extras.nix;
programs-kitty-extras = import ./modules/home/programs/kitty/extras.nix;
home-user-info =
{ lib, ... }:
{
options.home.user-info =
(self.darwinModules.users-primaryUser {
inherit lib;
}).options.users.primaryUser;
};
# Other
_1password-shell-plugins = inputs._1password-shell-plugins.hmModules.default;
};
# }}}
# System configurations ------------------------------------------------------------------ {{{
darwinConfigurations = {
# Minimal macOS configurations to bootstrap systems
bootstrap-x86 = makeOverridable darwin.lib.darwinSystem {
system = "x86_64-darwin";
modules = [
./darwin/bootstrap.nix
{ nixpkgs = nixpkgsDefaults; }
];
};
bootstrap-arm = self.darwinConfigurations.bootstrap-x86.override {
system = "aarch64-darwin";
};
# My Apple Silicon macOS laptop config
MaloBookPro = makeOverridable self.lib.mkDarwinSystem (
primaryUserDefaults
// {
modules =
attrValues self.darwinModules
++ singleton {
nixpkgs = nixpkgsDefaults;
networking.computerName = "Malo’s 💻";
networking.hostName = "MaloBookPro";
networking.knownNetworkServices = [
"Wi-Fi"
"USB 10/100/1000 LAN"
];
nix.registry.my.flake = inputs.self;
};
extraModules = singleton {
nix.linux-builder = {
enable = true;
ephemeral = true;
maxJobs = 8;
config.virtualisation = {
cores = 8;
darwin-builder.memorySize = 16 * 1024;
};
};
};
inherit homeStateVersion;
homeModules = attrValues self.homeManagerModules;
}
);
# Config with small modifications needed/desired for CI with GitHub workflow
githubCI = self.darwinConfigurations.MaloBookPro.override {
username = "runner";
nixConfigDirectory = "/Users/runner/work/nixpkgs/nixpkgs";
extraModules = singleton {
environment.etc.shells.enable = mkForce false;
environment.etc."nix/nix.conf".enable = mkForce false;
homebrew.enable = mkForce false;
# TODO: Remove when VM on GitHub updates to Sonoma
ids.uids.nixbld = 300;
};
};
};
# Config I use with non-NixOS Linux systems (e.g., cloud VMs etc.)
# Build and activate on new system with:
# `nix build .#homeConfigurations.malo.activationPackage && ./result/activate`
homeConfigurations.malo = makeOverridable home-manager.lib.homeManagerConfiguration {
pkgs = import inputs.nixpkgs-unstable (nixpkgsDefaults // { system = "x86_64-linux"; });
modules =
attrValues self.homeManagerModules
++ singleton (
{ config, ... }:
{
home.username = config.home.user-info.username;
home.homeDirectory = "/home/${config.home.username}";
home.stateVersion = homeStateVersion;
home.user-info = primaryUserDefaults // {
nixConfigDirectory = "${config.home.homeDirectory}/.config/nixpkgs";
};
}
);
};
# Config with small modifications needed/desired for CI with GitHub workflow
homeConfigurations.runner = self.homeConfigurations.malo.override (old: {
modules =
old.modules
++ singleton {
home.username = mkForce "runner";
home.homeDirectory = mkForce "/home/runner";
home.user-info.nixConfigDirectory = mkForce "/home/runner/work/nixpkgs/nixpkgs";
};
});
# }}}
}
// flake-utils.lib.eachDefaultSystem (system: {
# Re-export `nixpkgs-unstable` with overlays.
# This is handy in combination with setting `nix.registry.my.flake = inputs.self`.
# Allows doing things like `nix run my#prefmanager -- watch --all`
legacyPackages = import inputs.nixpkgs-unstable (nixpkgsDefaults // { inherit system; });
# Development shells ----------------------------------------------------------------------{{{
# Shell environments for development
# With `nix.registry.my.flake = inputs.self`, development shells can be created by running,
# e.g., `nix develop my#python`.
devShells =
let
pkgs = self.legacyPackages.${system};
in
{
default = pkgs.mkShell {
name = "default";
buildInputs = attrValues { inherit (pkgs) nixd nixfmt-rfc-style; };
};
python = pkgs.mkShell {
name = "python310";
buildInputs = attrValues {
inherit (pkgs.pkgs-master.python310Packages) black isort;
inherit (pkgs) poetry python310 pyright;
};
};
};
# }}}
});
}
# vim: foldmethod=marker