-
Notifications
You must be signed in to change notification settings - Fork 0
/
.envrc
56 lines (50 loc) · 1.89 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
if ! has nix_direnv_version || ! nix_direnv_version 2.1.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.1.1/direnvrc" "sha256-b6qJ4r34rbE23yWjMqbmu3ia2z4b2wIlZUksBke/ol0="
fi
export_alias() {
local name=$1
shift
local alias_dir=$PWD/.direnv/aliases
local target="$alias_dir/$name"
local oldpath="$PATH"
mkdir -p "$alias_dir"
if ! [[ ":$PATH:" == *":$alias_dir:"* ]]; then
PATH_add "$alias_dir"
fi
echo "#!/bin/sh" > "$target"
echo "PATH=$oldpath" >> "$target"
echo "$@" >> "$target"
chmod +x "$target"
}
export_alias "usrbuild" "if [ ! -z \"\$1\" ]; then \
home-manager switch --flake .#\$1; \
else \
home-manager switch --flake .#default; \
fi"
export_alias "sysbuild" "if [ ! -z \"\$1\" ]; then \
nixos-rebuild switch --flake .#\$1 --use-remote-sudo; \
else \
nixos-rebuild switch --flake .#default --use-remote-sudo; \
fi"
export_alias "rebuild" "if [ ! -z \"\$1\" ]; then \
sysbuild \$1 && usrbuild \$1; \
else \
sysbuild && usrbuild; \
fi"
export_alias "update" "if [ ! -z \"\$1\" ]; then \
nix flake lock --update-input \$1; \
else \
nix flake update; \
fi"
# use this to show why a certain package is required
export_alias "why" "NIXPKGS_ALLOW_INSECURE=1 NIXPKGS_ALLOW_UNFREE=1 nix why-depends .\#homeConfigurations.laptop.activationPackage nixpkgs#\$1 --inputs-from . --impure"
echo -e "You can apply this flake to your system with \e[1mrebuild\e[0m"
echo -e "And update it with \e[1mupdate\e[0m"
echo -e "And apply user configuration with \e[1musrbuild\e[0m and system configuration with \e[1msysbuild\e[0m"
echo -e "\n"
echo -e "update = \e[1mnix flake update\e[0m"
echo -e "usrbuild = \e[1mhome-manager switch --flake .\e[0m"
echo -e "sysbuild = \e[1m nixos-rebuild switch --use-remote-sudo --flake .\e[0m"
echo -e "rebuild = \e[1msysbuild && usrbuild\e[0m"
# using the flake causes source to be cached with direnv
use flake