-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
379 lines (337 loc) · 12.1 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
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
{
description = "zupo's macOS/Darwin system configuration";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ self, nixpkgs, nix-darwin, home-manager }:
let
secrets = import /Users/zupo/.dotfiles/secrets.nix;
homeconfig = { pkgs, lib, ... }: {
home.homeDirectory = lib.mkForce "/Users/zupo";
home.stateVersion = "23.11";
programs.home-manager.enable = true;
# Software I can't live without
home.packages = with pkgs; [
pkgs.asciinema
pkgs.axel
pkgs.bat
pkgs.cachix
pkgs.devenv
pkgs.gnumake
pkgs.gnupg
pkgs.hyperfine
pkgs.inetutils # telnet
pkgs.jq
pkgs.keybase
pkgs.ncdu
pkgs.ngrok
pkgs.nmap
pkgs.pdfcrack
pkgs.pgweb
pkgs.prettyping
pkgs.pwgen
pkgs.python3
pkgs.s3cmd
pkgs.tailscale
pkgs.tldr
pkgs.unrar
pkgs.wget
pkgs.yt-dlp
pkgs.nixd
];
programs.vim.enable = true;
programs.direnv = {
enable = true;
nix-direnv.enable = true;
};
programs.ssh = {
enable = true;
addKeysToAgent = "yes";
extraConfig = ''
IgnoreUnknown UseKeychain
UseKeychain yes
Host linux-builder
User builder
Hostname localhost
HostKeyAlias linux-builder
IdentityFile /etc/nix/builder_ed25519
Port 31022
'';
};
programs.zsh = {
enable = true;
autosuggestion.enable = true;
enableCompletion = true;
oh-my-zsh = {
enable = true;
theme = "robbyrussell";
plugins = ["git" "python" "sudo" "direnv"];
};
sessionVariables = {
LC_ALL = "en_US.UTF-8";
LANG = "en_US.UTF-8";
EDITOR = "zed --wait";
# Needed for synologycloudsyncdecryptiontool
PATH = "$PATH:$HOME/bin";
# Enable a few neat OMZ features
HYPHEN_INSENSITIVE = "true";
COMPLETION_WAITING_DOTS = "true";
# Disable generation of .pyc files
# https://docs.python-guide.org/writing/gotchas/#disabling-bytecode-pyc-files
PYTHONDONTWRITEBYTECODE = "0";
};
shellAliases = {
axel = "axel -a";
rsync = "rsync -avzhP";
pwgen = "pwgen --ambiguous 20";
cat = "bat";
ping = "prettyping --nolegend";
diff = "diff-so-fancy";
man = "tldr";
subl = "code";
nixre = "darwin-rebuild switch --flake ~/.dotfiles#zbook --impure";
nixgc = "nix-collect-garbage -d";
nixcfg = "code ~/.dotfiles/flake.nix";
yt-dlp-lowres = "yt-dlp -S res:720";
};
history = {
append = true;
share = true;
};
initExtra = ''
function edithosts {
sudo vim /etc/hosts && echo "* Successfully edited /etc/hosts"
sudo dscacheutil -flushcache && echo "* Flushed local DNS cache"
}
'';
};
# Don't show the "Last login" message for every new terminal.
home.file.".hushlogin" = {
text = "";
};
programs.git = {
enable = true;
diff-so-fancy.enable = true;
userName = "Neyts Zupan";
userEmail = secrets.email;
attributes = [
"*.bmml binary" # Prevent XML diffs for Balsamiq Mockups files
];
aliases = {
ap = "add -p";
cdiff = "diff --cached";
sdiff = "diff --staged";
st = "status";
ci = "commit";
cia = "commit -v -a";
cp = "cherry-pick";
br = "branch --sort=-committerdate";
co = "checkout";
df = "diff";
dfs = "diff --staged";
l = "log";
ll = "log -p";
rehab = "reset origin/main --hard";
pom = "push origin main";
latest = "for-each-ref --sort=-committerdate refs/heads/";
cod = "checkout src/mayet/demo/";
addd = "add src/mayet/demo/";
# A log of commits indicating where various branches are currently pointing.
lga = "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative --branches --remotes";
# "git weburl" prints the URL of the github project page for repositories hosted on github.
weburl = "!git config --get remote.origin.url | sed -e 's/git:\\/\\/github.com/https:\\/\\/github.com/' -e 's/[email protected]:/https:\\/\\/github.com\\//' -e 's/\\.git$//'";
# "git browse" opens the github project page of this repository in the browser.
browse = "!open `git weburl`";
# search for a specific line of code in all commits in the repo.
# Example: to find when the line "constraint=someMethod," was commented out, use:
# git search '#constraint=someMethod,'
search = "!f() { git log -S$1 --pretty=oneline --abbrev-commit; }; f";
demo-start = "checkout demo-start";
demo-next = "!git checkout `git rev-list HEAD..demo-end | tail -1`";
demo-prev = "checkout HEAD^";
demo-diff = "diff HEAD^";
demo-msg = "log -1 --pretty=%B";
};
ignores = [
# Packages: it's better to unpack these files and commit the raw source
# git has its own built in compression methods
"*.7z"
"*.dmg"
"*.gz"
"*.iso"
"*.jar"
"*.rar"
"*.tar"
"*.zip"
# OS generated files
".DS_Store"
".DS_Store?"
"ehthumbs.db"
"Icon?"
"Thumbs.db"
# Sublime
"sublime/*.cache"
"sublime/oscrypto-ca-bundle.crt"
"sublime/Package Control.last-run"
"sublime/Package Control.merged-ca-bundle"
"sublime/Package Control.user-ca-bundle"
# VS Code
"vscode/History/"
"vscode/globalStorage/"
"vscode/workspaceStorage/"
# Secrets
"ssh_config_private"
];
extraConfig = {
branch = {
autosetuprebase = "always";
};
credential = {
helper = "osxkeychain";
};
github = {
user = "zupo";
token = secrets.github.token;
};
help = {
autocorrect = 1;
};
init = {
defaultBranch = "main";
};
push = {
default = "simple";
};
};
};
};
configuration = { pkgs, ... }: {
# Use nix from pinned nixpkgs
services.nix-daemon.enable = true;
nix.settings.trusted-users = [ "root" "zupo" ];
nix.package = pkgs.nix;
# Using flakes instead of channels
nix.settings.nix-path = ["nixpkgs=flake:nixpkgs"];
# Allow licensed binaries
nixpkgs.config.allowUnfree = true;
# Save disk space
nix.optimise.automatic = true;
# Longer log output on errors
nix.settings.log-lines = 25;
# Necessary for using flakes on this system.
nix.settings.experimental-features = "nix-command flakes";
# Configure Cachix
nix.settings.substituters = [
"https://cache.nixos.org"
"https://niteo.cachix.org"
];
nix.settings.trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"niteo.cachix.org-1:GUFNjJDCE199FDtgkG3ECLrAInFZEDJW2jq2BUQBFYY="
];
nix.settings.netrc-file = "/Users/zupo/.config/nix/netrc";
# Support for building Linux binaries
# Note: the `Host linux-builder` section in ssh config above is required
# for this to work.
# To test, run:
# nix build --impure --expr '(with import <nixpkgs> { system = "aarch64-linux"; }; runCommand "foo" {} "uname -a > $out")'
# Or:
# nix -L build github:tfc/nixos-integration-test-example
# To SSH directly into the builder, run:
# $ sudo chmod 644 /etc/nix/builder_ed25519
# $ ssh builder@linux-builder
# Then, to revert back to using it with nix build, run:
# $ sudo chmod 600 /etc/nix/builder_ed25519
nix.linux-builder = {
enable = true;
ephemeral = true;
maxJobs = 4;
config = {
virtualisation = {
darwin-builder = {
diskSize = 40 * 1024;
memorySize = 8 * 1024;
};
cores = 6;
};
};
};
# Enable logging for the linux builder
launchd.daemons.linux-builder = {
serviceConfig = {
StandardOutPath = "/var/log/darwin-builder.log";
StandardErrorPath = "/var/log/darwin-builder.log";
};
};
# Allow remote builders to use caches
nix.extraOptions = ''
builders-use-substitutes = true
'';
# Create /etc/zshrc that loads the nix-darwin environment.
programs.zsh.enable = true;
# Set Git commit hash for darwin-version.
system.configurationRevision = self.rev or self.dirtyRev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
# The platform the configuration will be used on.
nixpkgs.hostPlatform = "aarch64-darwin";
# Use TouchID for sudo
security.pam.enableSudoTouchIdAuth = true;
# make sure firewall is up & running
system.defaults.alf.globalstate = 1;
system.defaults.alf.stealthenabled = 1;
# Personalization
networking.hostName = "zbook";
system.defaults.dock.autohide = true;
system.defaults.dock.orientation = "right";
system.defaults.dock.tilesize = 35;
system.defaults.finder._FXShowPosixPathInTitle = true;
system.defaults.finder.AppleShowAllExtensions = true;
system.defaults.finder.AppleShowAllFiles = true;
system.defaults.finder.ShowPathbar = true;
system.defaults.finder.ShowStatusBar = true;
system.defaults.finder.FXPreferredViewStyle = "clmv";
system.defaults.loginwindow.GuestEnabled = true;
system.defaults.finder.FXDefaultSearchScope = "SCcf"; # search current folder by default
system.defaults.NSGlobalDomain.AppleShowScrollBars = "Always";
system.defaults.NSGlobalDomain.AppleScrollerPagingBehavior = true;
system.defaults.finder.FXEnableExtensionChangeWarning = false;
system.defaults.NSGlobalDomain.InitialKeyRepeat = 15;
system.defaults.NSGlobalDomain.KeyRepeat = 2;
system.defaults.NSGlobalDomain.AppleKeyboardUIMode = 3;
system.defaults.NSGlobalDomain.NSNavPanelExpandedStateForSaveMode = true;
system.defaults.NSGlobalDomain.NSNavPanelExpandedStateForSaveMode2 = true;
system.defaults.NSGlobalDomain.NSTableViewDefaultSizeMode = 2;
system.defaults.NSGlobalDomain.PMPrintingExpandedStateForPrint = true;
system.defaults.NSGlobalDomain.PMPrintingExpandedStateForPrint2 = true;
system.defaults.trackpad.FirstClickThreshold = 0;
system.defaults.trackpad.SecondClickThreshold = 0;
system.keyboard.enableKeyMapping = true;
system.keyboard.nonUS.remapTilde = true;
system.defaults.screencapture.disable-shadow = true;
system.defaults.screensaver.askForPasswordDelay = 10;
};
in
{
# Build darwin flake using:
# $ darwin-rebuild build --flake .
# $ nix run nix-darwin -- switch --flake .#zbook
darwinConfigurations."zbook" = nix-darwin.lib.darwinSystem {
modules = [
configuration
home-manager.darwinModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.zupo = homeconfig;
}
];
};
# Expose the package set, including overlays, for convenience.
darwinPackages = self.darwinConfigurations."zbook".pkgs;
};
}