{
  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.unstable.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.unstable.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
      echo "Updating nix-flake..."
      nix flake update .
      echo "NixOS Rebuilding..."
      ${pkgs.unstable.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"
      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
      echo "Updating nix-flake..."
      nix flake update .
      echo "NixOS Building..."
      ${pkgs.unstable.nh}/bin/nh os build ~/.nixos
      popd
    '';
in {
  environment.systemPackages = [
    pkgs.bash
    home-rebuild
    rebuild
    upgrade
    update
  ];
}
