forked from lucperkins/nix-home-config
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshell.nix
More file actions
198 lines (168 loc) · 5.1 KB
/
shell.nix
File metadata and controls
198 lines (168 loc) · 5.1 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
# Shell configuration for zsh (frequently used)
{
config,
lib,
pkgs,
...
}:
let
# Set all shell aliases programatically
shellAliases = {
# Aliases for commonly used tools
grep = "grep --color=auto";
ll = "ls -lh";
tf = "terraform";
hms = "home-manager switch";
# Reload zsh
szsh = "source ~/.zshrc";
# Reload home manager and zsh
reload = "NIXPKGS_ALLOW_UNFREE=1 home-manager switch --impure --extra-experimental-features nix-command && source ~/.zshrc";
# Nix garbage collection
garbage = "nix-collect-garbage -d";
# Bundle Rails C
brc = "bundle exec rails c";
# Bundle Rails S
brs = "bundle exec rails s";
# Database MigrAte
dma = "bundle exec rake db:migrate";
# Database (M) Rollback
dmr = "bundle exec rake db:rollback";
# Visual Studio Code
vsc = "code .";
# HooGLe server
hgl = "hoogle server --local --port 8080 &";
};
in
{
# Fancy filesystem navigator
programs.broot = {
enable = true;
enableZshIntegration = true;
};
programs.starship = {
enable = true;
enableZshIntegration = true;
settings = {
time = {
disabled = false;
format = "[$time]($style) ";
time_format = "%T"; # 24-hour format HH:MM:SS
style = "bold yellow";
};
right_format = "$time";
};
};
# zsh settings
programs.zsh = {
inherit shellAliases;
enable = true;
autosuggestion.enable = true;
enableCompletion = true;
history.extended = true;
# Called whenever zsh is initialized
initContent = lib.mkBefore ''
export ZSH=${pkgs.oh-my-zsh}/share/oh-my-zsh/
export TERM="xterm-256color"
bindkey -e
# Nix setup (environment variables, etc.)
# https://discourse.nixos.org/t/how-to-restore-nix-and-home-manager-after-macos-upgrade/25474
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# Load environment variables from a file; this approach allows me to not
# commit secrets like API keys to Git
if [ -e ~/.env ]; then
. ~/.env
fi
# direnv setup
eval "$(direnv hook zsh)"
# Build and test a Haskell project
function hbt() {
TOOL_NAME=$1
clear && cabal build $TOOL_NAME && cabal test $TOOL_NAME
}
# Build, test, and install a Haskell tool
function hbti() {
TOOL_NAME=$1
clear && cabal build $TOOL_NAME && cabal test $TOOL_NAME && cabal install $TOOL_NAME --overwrite-policy=always
}
# Debug a Haskell project with ghcid
function hdbg() {
TOOL_NAME=$1
ghcid -c "cabal repl --enable-multi-repl --ghc-options=-Wwarn --builddir=./dist-debug $TOOL_NAME"
}
# Run the Haskell REPL
function hrepl() {
TOOL_NAME=$1
cabal repl --enable-multi-repl --ghc-options=-Wwarn --builddir=./dist-debug $TOOL_NAME
}
# Do cabal run
function hbr() {
TOOL_NAME=$1
cabal run $TOOL_NAME -- ''${@:2}
}
# Create git worktree with Haskell project files
function gt() {
# Check if we're in a git repository root
if [[ ! -d .git ]]; then
echo "Error: Not in a git repository root directory"
return 1
fi
# Require branch name argument
if [[ -z "$1" ]]; then
echo "Usage: gt <branch-name>"
echo "Creates a git worktree and copies Haskell build artifacts if present"
return 1
fi
local branch_name="$1"
local worktree_path=".worktrees/$branch_name"
# Create the git worktree
echo "Creating git worktree for branch '$branch_name'..."
git worktree add -b "$branch_name" "$worktree_path"
if [[ $? -ne 0 ]]; then
echo "Failed to create git worktree"
return 1
fi
echo "Worktree created at: $worktree_path"
# Copy cabal.project.local if it exists
if [[ -f cabal.project.local ]]; then
echo "Copying cabal.project.local..."
cp cabal.project.local "$worktree_path/"
fi
# Copy dist directory if it exists
if [[ -d dist-newstyle ]]; then
echo "Copying dist-newstyle..."
cp -r dist-newstyle "$worktree_path/"
fi
# Copy vendor directory if it exists
if [[ -d vendor ]]; then
echo "Copying vendor..."
cp -r vendor "$worktree_path/"
fi
# Copy pre-commit config symlink if it exists
if [[ -L .pre-commit-config.yaml ]]; then
echo "Copying .pre-commit-config.yaml symlink..."
local target=$(readlink .pre-commit-config.yaml)
ln -sf "$target" "$worktree_path/.pre-commit-config.yaml"
fi
echo "Git worktree setup complete!"
}
PATH=$PATH:~/.local/bin
'';
oh-my-zsh = {
enable = true;
plugins = [
"git"
"bundler"
"gem"
"powder"
"rake"
"themes"
"history"
"z"
"brew"
];
theme = "muse";
};
};
}