1# friendship ended with Makefile
2# I LOVE justFILE!!!!!!
3
4# modules are unstable atm
5# mod utils
6
7true := "true"
8
9# build the current configuration
10build system="" +extra_args="":
11 nixos-rebuild -v -L --keep-going --accept-flake-config --log-format internal-json --flake .#{{system}} build \
12 {{extra_args}} |& nom --json
13 {{ if system == "" {"nvd diff /run/current-system result"} else {""} }}
14
15# evaluate the configuration for a system
16eval system:
17 nix eval .#nixosConfigurations.{{system}}.config.system.build.toplevel
18
19# build and test the configuration, but don't switch
20test system="":
21 nixos-rebuild -v -L test --flake .#{{system}} --accept-flake-config
22
23deploy system:
24 nixos-rebuild switch --flake .#{{system}} --target-host {{system}} --use-remote-sudo -v -L --use-substitutes
25
26dry-deploy system:
27 nixos-rebuild build --flake .#{{system}} --target-host {{system}} --use-remote-sudo -v -L --use-substitutes
28
29# switch to the current configuration
30switch system="": sudo_cache
31 sudo nixos-rebuild -v -L switch --flake .#{{system}} --accept-flake-config --keep-going
32
33sw: switch
34
35# literally nixos-rebuild boot with a different name
36defer system="": sudo_cache
37 sudo nixos-rebuild -v -L boot --flake .#{{system}} --accept-flake-config
38
39build-all: (for-all-systems 'build' 'true')
40deploy-all: (for-all-systems 'deploy' '!system.config.gensokyo.traits.sensitive && (system.config.nixpkgs.hostPlatform.system == builtins.currentSystem)' true)
41eval-all: (for-all-systems 'eval' 'true')
42
43# check the flake
44check:
45 nix flake check
46
47# delete old nixos generations and GCs the store.
48gc older_than="3d": sudo_cache
49 sudo nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than {{older_than}}
50 sudo nix store gc -vL
51
52# run utility programs
53utils recipe="list" +extras="":
54 @echo "Running utils/{{recipe}}"
55 @just -d utils -f utils/justfile {{recipe}} {{extras}}
56
57# commit ephemeral/auto-generated files
58ephemeral:
59 git commit --gpg-sign -m "chore: update ephemeral files" users/cassie/ephemeral/
60
61# update an input in the flake lockfile
62update-input input:
63 nix flake lock --update-input {{input}}
64
65# update everything in flake.lock and commit that
66flake-update:
67 nix flake update --commit-lock-file
68
69# list changes in the current config vs the system config
70diff:
71 nvd diff /run/current-system result
72
73# build a vm for a system
74vm system run="true" bootloader="false":
75 nixos-rebuild -v -L build-vm{{if bootloader == "true" {"-with-bootloader"} else {""} }} --flake .#{{system}}
76 {{if run == true {"./result/bin/run-"+system+"-vm"} else {""} }}
77
78[private]
79sudo_cache:
80 @sudo -v
81
82[private]
83for-all-systems recipe filter ignore_failure="false":
84 #!/usr/bin/env bash
85 set -euxo pipefail
86 for system in $(nix eval --impure --apply 'configs: builtins.map (system: system.config.networking.hostName) (builtins.filter (system: {{filter}}) (builtins.attrValues configs))' .#nixosConfigurations --json | jq '.[]' | xargs); do
87 set +e
88 just {{recipe}} ${system}
89 if [ {{ if ignore_failure == true {""} else {"$? -ne 0 -o"} }} $? -eq 130 ]; then
90 exit 1;
91 fi
92 set -e
93 done