{ config, pkgs, ... }: let home-rebuild = pkgs.writeShellScriptBin ".home-rebuild" '' set -e pushd ~/.nixos/ ${pkgs.alejandra}/bin/alejandra . &>/dev/null ${pkgs.git}/bin/git diff -U0 echo "NixOS Rebuilding..." ${pkgs.nh}/bin/nh home switch ~/.nixos gen=$(home-manager generations | head -n1 | ${pkgs.gawk}/bin/awk '{print "Gen" $5 " @ " $1 "-" $2}') ${pkgs.git}/bin/git commit --no-gpg-sign -am "Home $gen" popd ''; rebuild = pkgs.writeShellScriptBin ".nixos-rebuild" '' set -e pushd ~/.nixos/ ${pkgs.alejandra}/bin/alejandra . &>/dev/null ${pkgs.git}/bin/git diff -U0 echo "NixOS Rebuilding..." ${pkgs.nh}/bin/nh os switch ~/.nixos gen=$(sudo nix-env --list-generations --profile /nix/var/nix/profiles/system | ${pkgs.gnugrep}/bin/grep current | ${pkgs.gawk}/bin/awk '{print "Gen" $1 " @ " $2 "-" $3}') ${pkgs.git}/bin/git commit --no-gpg-sign -am "System $gen" popd ''; upgrade = pkgs.writeShellScriptBin ".nixos-upgrade" '' set -e pushd ~/.nixos/ if [ -n "$(${pkgs.git}/bin/git status --porcelain)" ]; then echo ".nixos is unclean!" exit 1 fi branch_staging="staging-update" if ${pkgs.git}/bin/git rev-parse --verify "$branch_staging" >/dev/null 2>&1; then echo "Using staging update branch." else echo "No staging update branch found." exit 1 fi ${pkgs.git}/bin/git checkout "$branch_staging" flake.lock echo "Updating nix-flake..." nix flake update --flake . echo "NixOS Rebuilding..." ${pkgs.nh}/bin/nh os switch ~/.nixos gen=$(sudo nix-env --list-generations --profile /nix/var/nix/profiles/system | ${pkgs.gnugrep}/bin/grep current | ${pkgs.gawk}/bin/awk '{print "Gen" $1 " @ " $2 "-" $3}') ${pkgs.git}/bin/git commit --no-gpg-sign -am "Upgrade $gen" ${pkgs.git}/bin/git branch -D "$branch_staging" popd ''; update = pkgs.writeShellScriptBin ".nixos-update" '' set -e pushd ~/.nixos/ if [ -n "$(${pkgs.git}/bin/git status --porcelain)" ]; then echo ".nixos is unclean!" exit 1 fi branch_staging="staging-update" branch_current="$(${pkgs.git}/bin/git branch --show-current)" if ${pkgs.git}/bin/git rev-parse --verify "$branch_staging" >/dev/null 2>&1; then echo "There is already a staging update branch." else echo "Creating a new staging update branch." ${pkgs.git}/bin/git switch -c "$branch_staging" nix flake update --verbose --flake . ${pkgs.git}/bin/git add flake.lock ${pkgs.git}/bin/git commit --no-gpg-sign -m "staging update" ${pkgs.git}/bin/git switch "$branch_current" fi nix store diff-closures \ '.?ref='"$branch_current"'#nixosConfigurations.'"$(${pkgs.hostname}/bin/hostname)"'.config.system.build.toplevel' \ '.?ref='"$branch_staging"'#nixosConfigurations.'"$(${pkgs.hostname}/bin/hostname)"'.config.system.build.toplevel' popd ''; in { environment.systemPackages = [ home-rebuild rebuild upgrade update ]; }