-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathflake.nix
More file actions
405 lines (375 loc) · 13.9 KB
/
Copy pathflake.nix
File metadata and controls
405 lines (375 loc) · 13.9 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
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
{
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-25.11-darwin";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
determinate-nix.url = "https://flakehub.com/f/DeterminateSystems/determinate/3";
# Environment/system management
darwin = {
url = "github:nix-darwin/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";
};
nix-index-database = {
url = "github:nix-community/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
# Google Workspace CLI (gws) — pinned to our fixes branch until PRs land upstream
gws-cli = {
url = "github:malob/cli/gmail-fixes";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
# Color math
nix-colorizer.url = "github:nutsalhan87/nix-colorizer";
# 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";
};
};
outputs =
{
self,
darwin,
home-manager,
flake-utils,
...
}@inputs:
let
inherit (builtins) attrValues;
inherit (self.lib)
makeOverridable
mkForce
optionalAttrs
singleton
;
homeStateVersion = "26.05";
nixpkgsDefaults = {
config = {
allowUnfree = true;
};
overlays =
attrValues self.overlays
++ [
(_: prev: {
prefmanager = inputs.prefmanager.packages.${prev.stdenv.hostPlatform.system}.prefmanager;
})
]
++ singleton (
_: prev:
(optionalAttrs (prev.stdenv.hostPlatform.system == "aarch64-darwin") {
# Sub in x86 version of packages that don't build on Apple Silicon.
# inherit (final.pkgs-x86) [...];
})
// {
# Workaround for nixpkgs#513543: PR #508474 (apple-sdk → darwin
# stdenv migration) breaks zsh's autoconf sigsuspend probe, causing
# interactive zsh and `$(...)` reaping to hang. Fix landed in
# nixpkgs master (commit 19b2d2ace, 2026-04-27) but the unstable
# channel hasn't picked it up yet. Pin to master until it does.
inherit (prev.pkgs-master) zsh;
}
);
};
primaryUserDefaults = {
username = "malo";
fullName = "Malo Bourgon";
email = "mbourgon@gmail.com";
nixConfigDirectory = "/Users/malo/.config/nix-config";
};
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.hostPlatform) system;
inherit (nixpkgsDefaults) config;
};
};
pkgs-stable = _: prev: {
pkgs-stable = import inputs.nixpkgs-stable {
inherit (prev.stdenv.hostPlatform) system;
inherit (nixpkgsDefaults) config;
};
};
pkgs-unstable = _: prev: {
pkgs-unstable = import inputs.nixpkgs-unstable {
inherit (prev.stdenv.hostPlatform) system;
inherit (nixpkgsDefaults) config;
};
};
apple-silicon =
_: prev:
optionalAttrs (prev.stdenv.hostPlatform.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;
};
};
tweaks =
_: prev:
let
determinateNix = inputs.determinate-nix.inputs.nix.packages.${prev.stdenv.system}.default;
in
{
# Packages from external flake inputs
nix-colorizer = inputs.nix-colorizer;
gws = inputs.gws-cli.packages.${prev.stdenv.system}.gws;
# Override packages that use nix to use Determinate Nix
nix-update = prev.nix-update.override { nix = determinateNix; };
nixpkgs-review = prev.nixpkgs-review.override { nix = determinateNix; };
comma = prev.comma.override { nix = determinateNix; };
};
};
# Modules ------------------------------------------------------------------------------------
darwinModules = {
# My configurations
malo-bootstrap = import ./darwin/bootstrap.nix;
malo-claude-managed-settings = import ./darwin/claude-managed-settings.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;
# Other
determinate-nix = inputs.determinate-nix.darwinModules.default;
};
homeManagerModules = {
# My configurations
malo-claude = import ./home/claude.nix;
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-ghostty = import ./home/ghostty.nix;
malo-packages = import ./home/packages.nix;
malo-starship = import ./home/starship.nix;
malo-starship-symbols = import ./home/starship-symbols.nix;
malo-tmux = import ./home/tmux.nix;
# Modules I've created
colors = import ./modules/home/colors;
programs-starship-extras = import ./modules/home/programs/starship/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;
nix-index-database = inputs.nix-index-database.homeModules.nix-index;
};
# 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"
];
# Workaround for nix.registry not working with nix.enable = false
environment.etc."nix/registry.json".text = builtins.toJSON {
version = 2;
flakes = [
{
from = {
type = "indirect";
id = "my";
};
to = {
type = "path";
path = primaryUserDefaults.nixConfigDirectory;
};
}
];
};
};
# TODO: Re-enable linux-builder once compatible with Determinate Nix
# 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/nix-config/nix-config";
extraModules = singleton {
environment.etc.shells.enable = mkForce false;
homebrew.enable = mkForce false;
};
};
};
# 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/nix-config";
};
}
);
};
# 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/nix-config/nix-config";
};
});
}
// 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.mkShellNoCC {
name = "default";
packages = attrValues {
inherit (pkgs)
deadnix
nixd
nixfmt
statix
;
};
};
docx = pkgs.mkShell {
name = "docx";
packages = attrValues {
inherit (pkgs)
nodejs
pandoc
;
python = pkgs.python3.withPackages (
ps:
attrValues {
inherit (ps)
defusedxml
lxml
;
}
);
};
shellHook = ''
# LibreOffice from Homebrew (not available on Darwin in nixpkgs)
if [ -x "/Applications/LibreOffice.app/Contents/MacOS/soffice" ]; then
export PATH="/Applications/LibreOffice.app/Contents/MacOS:$PATH"
fi
# Auto-install docx npm package and expose via NODE_PATH
_docx_cache="$HOME/.cache/nix-devshell-docx"
if [ ! -d "$_docx_cache/node_modules/docx" ]; then
echo "Installing docx npm package..."
mkdir -p "$_docx_cache"
npm install --prefix "$_docx_cache" docx >/dev/null 2>&1
fi
export NODE_PATH="$_docx_cache/node_modules''${NODE_PATH:+:$NODE_PATH}"
'';
};
pdf = pkgs.mkShellNoCC {
name = "pdf";
packages = attrValues {
inherit (pkgs)
ghostscript
poppler-utils
qpdf
tesseract
;
python = pkgs.python3.withPackages (
ps:
attrValues {
inherit (ps)
pandas
pdf2image
pdfplumber
pillow
pypdf
pytesseract
reportlab
;
}
);
};
};
};
});
}