-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.envrc
79 lines (66 loc) · 1.7 KB
/
.envrc
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
if [ -f flake.nix ]; then
use flake
fi
root_dir=$(git rev-parse --show-toplevel)
nixos_switch() {
local target=".#$1"
local mode="$2"
if [ "$mode" = "debug" ]; then
nixos-rebuild switch --flake "$target" --show-trace --verbose
elif [ "$mode" = "update" ]; then
nix flake update
nixos-rebuild switch --recreate-lock-file --flake "$target"
else
nix flake update datsnvim
nix flake update unix-scripts
nixos-rebuild switch --flake "$target"
fi
}
nixos_build() {
local target=".#$1"
local mode="$2"
if [ "$mode" = "debug" ]; then
nixos-rebuild build --flake "$target" --show-trace --verbose
elif [ "$mode" = "update" ]; then
pushd "$root_dir"
./scripts/update-nupkgs.sh ./modules/nupkgs
nix flake update
nixos-rebuild build --flake "$target"
popd || exit 1
else
nixos-rebuild build --flake "$target"
fi
}
export_function() {
local name=$1
local alias_dir=$PWD/.direnv/aliases
mkdir -p "$alias_dir"
PATH_add "$alias_dir"
local target="$alias_dir/$name"
if declare -f "$name" >/dev/null; then
echo "#!$SHELL" > "$target"
declare -f "$name" >> "$target"
echo "$name \"\$@\"" >> "$target"
chmod +x "$target"
fi
}
generate_flake() {
if [ -f flake.nix ]; then
if ! command -v trash &> /dev/null; then
rm flake.nix
else
trash flake.nix
fi
fi
nix eval --raw -f templates/flake.template.nix flake > flake.nix
alejandra flake.nix
}
run_lib_tests() {
pushd "$root_dir" || exit 1
nix-shell -p nix-unit --run "nix-unit ./lib/spec.nix --gc-roots-dir ./.result-test"
popd || exit 1
}
export_function nixos_switch
export_function nixos_build
export_function generate_flake
export_function run_lib_tests