-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.nix
358 lines (320 loc) · 10.6 KB
/
home.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
{ config, pkgs, ... }:
let
username = "jason";
homeDirectory = "/Users/${username}";
patchesDirectory = ../../../patches;
srcDirectory = "${homeDirectory}/src";
dotfilesSrcDirectory = "${srcDirectory}/dotfiles";
goodcoverSrcDirectory = "${srcDirectory}/goodcover";
goodcoverCoreDirectory = "${goodcoverSrcDirectory}/core";
# The path to this repository once it has been checked out.
dotFilesRepo = fetchGit {
url = "https://github.com/steinybot/dotfiles.git";
ref = "main";
};
# Use this if git/ssh is broken (such as when the PGP key expires).
#dotFilesRepo = ../../..;
repoHomeFilesDirectory = "${dotFilesRepo}/home";
# Add these manually so that we can specify custom onChange etc.
managedHomeFiles = {
# This may update itself so we might need to run again.
".config/home-manager/home.nix" = {
source = "${repoHomeFilesDirectory}/.config/home-manager/home.nix";
onChange = "home-manager --option tarball-ttl 0 -b backup switch";
};
# Run rebuild when the configuration changes.
".nixpkgs/darwin-configuration.nix" = {
source = "${repoHomeFilesDirectory}/.nixpkgs/darwin-configuration.nix";
onChange = "darwin-rebuild switch";
};
# Update the channels when they change.
# FIXME: This onChange needs to run first.
".nix-channels" = {
source = "${repoHomeFilesDirectory}/.nix-channels";
onChange = "nix-channel --update";
};
".gnupg/gpg-agent.conf" = {
text = ''
enable-ssh-support
pinentry-program ${pkgs.pinentry_mac}/Applications/pinentry-mac.app/Contents/MacOS/pinentry-mac
default-cache-ttl 600
max-cache-ttl 7200
default-cache-ttl-ssh 600
max-cache-ttl-ssh 7200
log-file ${homeDirectory}/.gnupg/gpg-agent.log
'';
};
# "Library/Java/JavaVirtualMachines/graalvm11-ce" = {
# source = toString intelPkgs.graalvm11-ce;
# };
};
managedHomeFileNames = builtins.attrNames managedHomeFiles;
# Add all the rest of the files in home automatically.
unmanagedHomeFileNames = builtins.removeAttrs (builtins.readDir repoHomeFilesDirectory) managedHomeFileNames;
unmanagedHomeFiles = builtins.mapAttrs (name: value: {
source = "${repoHomeFilesDirectory}/${name}";
# This has to be recursive otherwise we get an error saying:
# Error installing file '...' outside $HOME
# When using something like programs.git which will try and write
# to .config but if that directory is a symlink then it is outside
# of $HOME.
recursive = true;
}) unmanagedHomeFileNames;
# Prefer using pkgsCross but some packages do not cross build so we have to build the whole thing for x86_64.
# TODO: Where should <nixpkgs> come from?
intelPkgs = import <nixpkgs> {
system = "x86_64-darwin";
};
unstablePkgsRepo = fetchGit {
url = "https://github.com/nixos/nixpkgs.git";
ref = "nixpkgs-unstable";
};
unstablePkgs = import unstablePkgsRepo {
overlays = [
(self: super: {
bcompare = super.bcompare.overrideAttrs (old: {
postInstall =
''
${(old.postInstall or "")}
ln $out/Applications/BCompare.app/Contents/MacOS/bcomp bin/bcomp
'';
});
})
];
};
# customPkgsRepo = fetchGit {
# url = "https://github.com/steinybot/nixpkgs.git";
# ref = "dev";
# };
# customPkgs = import customPkgsRepo {};
shellAliases = {
nix-bootstrap = "sh <(curl -L https://raw.githubusercontent.com/steinybot/bootstrap/main/bootstrap.sh)";
home-update = "home-manager --option tarball-ttl 0 switch";
home-update-local = "home-manager -f '${dotfilesSrcDirectory}/home/.config/home-manager/home.nix' --option tarball-ttl 0 switch";
rm = "safe-rm";
};
in
{
home = {
# Home Manager needs a bit of information about you and the
# paths it should manage.
username = username;
homeDirectory = homeDirectory;
# Link home files.
file = managedHomeFiles // unmanagedHomeFiles;
# Install packages.
packages = with pkgs; [
ammonite
element-desktop
gnupg
graalvm-ce
jq
maven
pinentry_mac
ripgrep
scala
surfraw # This needs a browser such as w3m.
thefuck
w3m
yarn
];
sessionPath = [
# Add Keybase to the PATH.
#"${customPkgs.pkgsCross.x86_64-darwin.keybase-gui}/Applications/Keybase.app/Contents/SharedSupport/bin"
"${homeDirectory}/Library/Application Support/Coursier/bin"
"${homeDirectory}/bin"
"${homeDirectory}/.cargo/bin"
];
sessionVariables = {
CONDA_EXE = "/opt/homebrew/Caskroom/miniforge/base/bin/conda";
EDITOR = "vim";
LPASS_PINENTRY = "${pkgs.pinentry_mac}/Applications/pinentry-mac.app/Contents/MacOS/pinentry-mac";
# I don't know why we need this. Nix-darwin is supposed to manage the agent for us.
# See https://discourse.nixos.org/t/how-to-make-gpg-use-the-agent-from-programs-gnupg-agent/11834.
SSH_AUTH_SOCK = "$(gpgconf --list-dirs agent-ssh-socket)";
VI_MODE_SET_CURSOR = "true";
VI_MODE_CURSOR_NORMAL = 4;
VI_MODE_CURSOR_VISUAL = 2;
};
# This value determines the Home Manager release that your
# configuration is compatible with. This helps avoid breakage
# when a new Home Manager release introduces backwards
# incompatible changes.
#
# You can update Home Manager without changing this value. See
# the Home Manager release notes for a list of state version
# changes in each release.
stateVersion = "22.05";
};
launchd.agents = {
};
nixpkgs.overlays = [
(self: super: {
bcompare = super.bcompare.overrideAttrs (old: {
postInstall =
''
${(old.postInstall or "")}
ln $out/Applications/BCompare.app/Contents/MacOS/bcomp bin/bcomp
'';
});
})
];
programs = {
bash = {
enable = true;
# These go in ~/.bashrc.
initExtra = ''
source ~/.config/iterm2/.iterm2_shell_integration.bash
# >>> mamba initialize >>>
if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/mamba.sh" ]; then
. "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/mamba.sh"
fi
# <<< mamba initialize <<<
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
'';
# These go in ~/.profile.
profileExtra = ''
eval "$(/opt/homebrew/bin/brew shellenv)"
eval "$(nodenv init -)"
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
'';
shellAliases = shellAliases;
};
direnv = {
enable = true;
enableBashIntegration = true;
enableZshIntegration = true;
nix-direnv = {
enable = true;
};
};
# Let Home Manager install and manage itself.
home-manager.enable = true;
# Keep git even if you do not use it so that fetchGit works even
# if XCode is not installed.
git = {
enable = true;
delta = {
enable = true;
};
signing = {
key = "C4A8C75C7876F1B5";
signByDefault = true;
};
userName = "Jason Pickens";
userEmail = "[email protected]";
extraConfig = {
branch = {
# This needs git 2.37
#autoSetupMerge = "simple";
autoSetupMerge = false;
};
core = {
autocrlf = false;
excludesfile = "~/.config/git/.gitignore";
};
diff = {
tool = "bcomp";
};
difftool = {
prompt = false;
"bcomp" = {
cmd = ''bcomp "$LOCAL" "$REMOTE"'';
trustExitCode = true;
};
};
init = {
defaultBranch = "main";
};
merge = {
ff = false;
tool = "bcomp";
};
mergetool = {
keepBackup = false;
prompt = false;
"bcomp" = {
cmd = ''bcomp "$LOCAL" "$REMOTE" "$BASE" "$MERGED"'';
trustExitCode = true;
};
};
pull = {
ff = "only";
};
push = {
autoSetupRemote = true;
default = "simple";
};
url = {
"ssh://[email protected]" = {
insteadOf = "https://github.com";
};
};
};
includes = [
{
condition = "gitdir:${goodcoverSrcDirectory}";
contents = {
user.email = "[email protected]";
};
}
];
};
ssh = {
enable = true;
extraOptionOverrides = {
IgnoreUnknown = "UseKeychain";
# This will start the gpg agent when using SSH.
Match = "host * exec \"gpg-connect-agent UPDATESTARTUPTTY /bye\"";
UseKeychain = "yes";
};
};
zsh = {
enable = true;
# These go in ~/.zshrc.
initExtra = ''
source ~/.config/iterm2/.iterm2_shell_integration.zsh
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/homebrew/Caskroom/miniforge/base/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
. "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh"
else
export PATH="/opt/homebrew/Caskroom/miniforge/base/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# >>> mamba initialize >>>
if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/mamba.sh" ]; then
. "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/mamba.sh"
fi
# <<< mamba initialize <<<
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
'';
oh-my-zsh = {
enable = true;
plugins = [ "git" "thefuck" "vi-mode" ];
theme = "dst";
};
# These go in ~/.zprofile.
profileExtra = ''
eval "$(/opt/homebrew/bin/brew shellenv)"
eval "$(nodenv init -)"
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
'';
shellAliases = shellAliases;
};
};
}