2025-01-08 12:04:28 -08:00
|
|
|
{ pkgs, vars, ... }: {
|
2024-12-12 13:12:24 -08:00
|
|
|
home.packages = with pkgs; [
|
2025-01-08 12:04:28 -08:00
|
|
|
( writeShellApplication {
|
|
|
|
name = "nixos";
|
2024-12-12 13:12:24 -08:00
|
|
|
runtimeInputs = [
|
|
|
|
libnotify
|
|
|
|
jq
|
|
|
|
git
|
|
|
|
];
|
|
|
|
text = ''
|
|
|
|
#!/bin/bash
|
2025-01-08 12:04:28 -08:00
|
|
|
# shellcheck disable=SC2088
|
|
|
|
FLAKE_DIR=${vars.flakeDir}
|
2024-12-12 13:12:24 -08:00
|
|
|
CURRENT_CONFIGURATION="desktop"
|
|
|
|
cd "$FLAKE_DIR"
|
|
|
|
|
|
|
|
handleUntracked() {
|
|
|
|
UNTRACKED=$(git ls-files -o --directory --exclude-standard --no-empty-directory)
|
|
|
|
if [[ $(echo "$UNTRACKED" | wc -l) -gt 0 ]]; then
|
|
|
|
git add -A
|
|
|
|
notify-send "Adding untracked files" "$UNTRACKED"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
rebuild() {
|
2025-01-08 12:04:28 -08:00
|
|
|
notify-send "Nixos: Beginning rebuild"
|
2024-12-12 13:12:24 -08:00
|
|
|
sudo nixos-rebuild switch \
|
|
|
|
--flake ".#$CURRENT_CONFIGURATION" \
|
|
|
|
--impure \
|
|
|
|
--show-trace &&\
|
2025-01-08 12:04:28 -08:00
|
|
|
notify-send "Nixos: Rebuilt successfully"
|
2024-12-12 13:12:24 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 14:46:55 -08:00
|
|
|
update() {
|
2025-01-08 12:04:28 -08:00
|
|
|
notify-send "Nixos: Beginning update" "Updating lockfile $FLAKE_DIR/flake.lock"
|
2024-12-13 14:46:55 -08:00
|
|
|
nix flake update --flake "$FLAKE_DIR"
|
2025-01-08 12:04:28 -08:00
|
|
|
notify-send "Nixos: Update complete" "Finished updating lockfile $FLAKE_DIR/flake.lock"
|
|
|
|
}
|
|
|
|
|
|
|
|
garbageCollect() {
|
|
|
|
notify-send "Nixos: Collecting garbage" "Deleting generations older than 7 days."
|
|
|
|
nix-env --delete-generations 7d &&\
|
|
|
|
nix-store --gc --print-dead
|
|
|
|
notify-send "Nixos: Garbage collection complete"
|
|
|
|
}
|
|
|
|
|
|
|
|
listGenerations() {
|
|
|
|
nixos-rebuild list-generations | less
|
|
|
|
}
|
|
|
|
|
|
|
|
edit() {
|
|
|
|
zeditor "${vars.flakeRepo}"
|
2024-12-13 14:46:55 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 13:12:24 -08:00
|
|
|
finish() {
|
|
|
|
mkdir -p "$HOME/.nixos"
|
|
|
|
nixos-rebuild list-generations --json > "$HOME/.nixos/nixos-generations.json"
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
notify-send "Nixos Script Error" "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
rebuild) handleUntracked && rebuild && finish;;
|
2024-12-13 14:46:55 -08:00
|
|
|
update) handleUntracked && update && finish;;
|
2025-01-08 12:04:28 -08:00
|
|
|
clean) garbageCollect && finish;;
|
|
|
|
ls) listGenerations;;
|
|
|
|
edit) edit;;
|
2024-12-12 13:12:24 -08:00
|
|
|
*) error "Unrecognized subcommand $1";;
|
|
|
|
esac
|
|
|
|
'';
|
|
|
|
} )
|
|
|
|
];
|
2025-01-08 12:04:28 -08:00
|
|
|
}
|