-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
158 lines (131 loc) · 4.83 KB
/
justfile
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
#!/usr/bin/env -S just --justfile
# mod test
[private]
default:
@just --list --justfile {{ justfile() }} --list-heading $'Avalible Commands\n'
all: update-os update-home
update:
nix flake update
alias home := update-home
alias h := update-home
[linux]
update-home *additionalArgs:
home-manager switch --flake .#$USER@$HOSTNAME {{ additionalArgs }}
[macos]
update-home *additionalArgs:
home-manager switch --flake .#$USER@$(hostname -s) {{ additionalArgs }}
alias apply := update-os
alias os := update-os
alias o := update-os
[linux]
update-os *additionalArgs:
#!/usr/bin/env bash
git rev-parse HEAD
if [ "$EUID" -ne 0 ]
then
sudo nixos-rebuild switch --flake .#$HOSTNAME {{ additionalArgs }}
else
nixos-rebuild switch --flake .#$HOSTNAME {{ additionalArgs }}
fi
[macos]
update-os *additionalArgs:
#!/usr/bin/env zsh
git rev-parse HEAD
confilictingFile=("/etc/bashrc" "/etc/zshrc")
for file in $confilictingFile
do
if [ -f $file ] && [ ! -L $file ];
then
echo "Moving $file to $file.$(date +%s).bak"
sudo mv $file $file.$(date +%s).bak
fi
done
/run/current-system/sw/bin/darwin-rebuild switch --flake {{ justfile_directory() }} {{ additionalArgs }}
[unix]
lock:
git-crypt lock
[unix]
unlock:
#!/usr/bin/env bash
# set -euxo pipefail
git config --local --get filter.git-crypt.smudge > /dev/null
# check if the last command was successful
if [ $? -ne 0 ]; then
# check if there are changes that need to be stashed
if [ -n "$(git status --porcelain)" ]; then
echo "Stashing"
git stash push -k
STASHED=true
fi
echo "Unlocking"
gpg --decrypt local.key.asc | git-crypt unlock -
# check if there were changes that were stashed
if [ "$STASHED" = true ]; then
echo "Popping stash"
git stash pop
fi
else
echo "Already unlocked"
fi
pull: unlock
#!/usr/bin/env bash
export GH_TOKEN=$(nix eval --file ./nixos/sensitive.nix gh_token | tail -c +2 | head -c -2)
git -c credential.helper='!f() { sleep 1; echo "username=${GIT_USER}"; echo "password=${GH_TOKEN}"; }; f' pull --rebase
push: unlock
#!/usr/bin/env bash
export GIT_USER="bcnelson"
export GH_TOKEN=$(nix eval --file ./nixos/sensitive.nix gh_token | tail -c +2 | head -c -2)
git -c credential.helper='!f() { sleep 1; echo "username=${GIT_USER}"; echo "password=${GH_TOKEN}"; }; f' push
sync: pull update-os
[linux]
check *additionalArgs:
nix flake check {{ additionalArgs }}
alias fmt := format
[unix]
format:
nix fmt
isoCreate version='iso_desktop':
#!/usr/bin/env bash
set -euo pipefail
shopt -s extglob
nix build .#nixosConfigurations.{{version}}.config.system.build.isoImage -o {{ justfile_directory() }}/result
isoTest version='iso_desktop': (isoCreate version)
#!/usr/bin/env bash
DISK_IMAGE={{ justfile_directory() }}/test/working/{{version}}/iso.qcow2
mkdir -p $(dirname $DISK_IMAGE)
if test -n $DISK_IMAGE && ! test -e $DISK_IMAGE; then
mkdir -p {{ justfile_directory() }}/test_vm
qemu-img create -f qcow2 "$DISK_IMAGE" "32G"
fi
ISO=$(head -n1 {{ justfile_directory() }}/result/nix-support/hydra-build-products | cut -d'/' -f6)
qemu-system-x86_64-uefi -enable-kvm -m 8192 -cdrom {{ justfile_directory() }}/result/iso/$ISO -drive cache=writeback,file="$DISK_IMAGE",format=qcow2,media=disk
isoInstall version='iso_desktop': (isoCreate version)
#!/usr/bin/env bash
shopt -s extglob
ISO_PATH=$(awk '{print $3}' "{{justfile_directory()}}/result/nix-support/hydra-build-products")
if test -e /dev/disk/by-label/@(v|V)entoy; then
ventoy_Mount=$(findmnt -n -o TARGET /dev/disk/by-label/@(v|V)entoy)
if [ -n "$ventoy_Mount" ]; then
echo "Copying iso to ventoy drive"
cp "$ISO_PATH" $ventoy_Mount/Nixos_{{version}}.iso
else
echo "Ventoy drive not mounted"
fi
else
echo "No ventoy drive found"
fi
[macos]
setup:
#!/usr/bin/env bash
sudo mv /etc/bashrc /etc/bashrc.$(date +%s).bak
sudo mv /etc/zshrc /etc/zshrc.$(date +%s).bak
nix run nix-darwin -- switch --flake {{ justfile_directory() }}
build machine='vm_test' type='vm':
nix build .#nixosConfigurations.{{ machine }}.config.system.build.{{ type }} -o {{ justfile_directory() }}/result
test machine='vm_test' type='vm':
nix build .#nixosConfigurations.{{ machine }}.config.system.build.{{ type }} -o {{ justfile_directory() }}/result
mkdir -p {{ justfile_directory() }}/test/working/test_vm
NIX_DISK_IMAGE={{ justfile_directory() }}/test/working/test_vm/{{ machine }}.qcow2 ./result/bin/run-{{ machine }}-{{ type }}
rm -rf {{ justfile_directory() }}/test/working/test_vm
rekey:
agenix rekey -a