forked from lucperkins/nix-home-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
171 lines (140 loc) · 4.5 KB
/
shell.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
# 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 && 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;
};
# zsh settings
programs.zsh = {
inherit shellAliases;
enable = true;
autosuggestion.enable = true;
enableCompletion = true;
history.extended = true;
initExtraFirst = ''
export ZSH=${pkgs.oh-my-zsh}/share/oh-my-zsh/
'';
# Called whenever zsh is initialized
initExtra = ''
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
# Start up Starship shell
eval "$(starship init zsh)"
# direnv setup
eval "$(direnv hook zsh)"
# direnv hook
eval "$(direnv hook zsh)"
function setCabalProjectLocalToBuild() {
echo "optimization: False" > cabal.project.local
echo "program-options" >> cabal.project.local
echo " ghc-options: -Wall" >> cabal.project.local
}
function setCabalProjectLocalToDebug() {
echo "optimization: False" > cabal.project.local
echo "program-options" >> cabal.project.local
echo " ghc-options: -Wwarn -Wunused-top-binds -Werror=unused-top-binds" >> cabal.project.local
}
function setCabalProjectLocalToCoverage() {
echo "package *" >> cabal.project.local
echo " coverage: True" >> cabal.project.local
echo " library-coverage: True" >> cabal.project.local
echo "package order-processing" >> cabal.project.local
echo " coverage: False" >> cabal.project.local
echo " library-coverage: False" >> cabal.project.local
}
# Build and test a Haskell project
function hbt() {
setCabalProjectLocalToBuild
TOOL_NAME=$1
clear && cabal --builddir=./dist-build build $TOOL_NAME && cabal --builddir=./dist-build test $TOOL_NAME
}
# Build, test, and install a Haskell tool
function hbti() {
setCabalProjectLocalToBuild
TOOL_NAME=$1
clear && cabal --builddir=./dist-build build $TOOL_NAME && cabal --builddir=./dist-build test $TOOL_NAME && cabal --builddir=./dist-build install $TOOL_NAME --overwrite-policy=always
}
# Debug a Haskell project with ghcid
function hdbg() {
setCabalProjectLocalToDebug
TOOL_NAME=$1
ghcid -c "cabal --builddir=./dist-debug repl $TOOL_NAME"
}
# Run the Haskell REPL
function hrepl() {
setCabalProjectLocalToDebug
TOOL_NAME=$1
cabal --builddir=./dist-debug repl $TOOL_NAME
}
# Run tests with coverage
function hbtc() {
setCabalProjectLocalToBuild
setCabalProjectLocalToCoverage
TOOL_NAME=$1
cabal --builddir=./dist-coverage build $TOOL_NAME && cabal --builddir=./dist-coverage test $TOOL_NAME
}
# Do cabal run
function hbr() {
setCabalProjectLocalToBuild
TOOL_NAME=$1
cabal --builddir=./dist-build run $TOOL_NAME -- ''${@:2}
}
PATH=$PATH:~/.local/bin
'';
oh-my-zsh = {
enable = true;
plugins = [
"git"
"bundler"
"gem"
"powder"
"rake"
"themes"
"history"
"z"
"brew"
];
theme = "muse";
};
};
}