feat: add nix-update+nvd script

This commit is contained in:
Jacob Bachmann 2024-01-22 00:11:16 +01:00
parent 307ae1bac9
commit d3150b5a5a
Signed by: bchmnn
GPG key ID: 732A612DAD28067D
7 changed files with 56 additions and 11 deletions

View file

@ -8,6 +8,7 @@
./keyd.nix
./neovim
./packages.nix
./scripts
./ssh.nix
./tmux.nix
./xdg.nix

View file

@ -0,0 +1,5 @@
{ pkgs, nixosConfig, ... }: {
home.packages = [
(import ./nix-update.nix { inherit pkgs nixosConfig; })
];
}

View file

@ -0,0 +1,35 @@
{ pkgs, nixosConfig }:
pkgs.writeShellScriptBin "nuf" ''
reset="\e[0m"
red="\e[31m"
green="\e[32m"
yellow="\e[33m"
white_bold="\e[1;37m"
function error {
echo ""
echo -e "''${red}>>>Error: $1''${reset}"
exit 1
}
FLAKE=$(readlink -f /etc/nixos)
echo -e "''${green}>>> Updating flake $FLAKE ...''${reset}"
${nixosConfig.nix.package}/bin/nix flake update --flake "$FLAKE" || error "Updating failed"
cd $(mktemp -d)
echo ""
echo -e "''${green}>>> Building configuration ...''${reset}"
nixos-rebuild build --flake "$FLAKE" || error "Building failed"
echo ""
echo -e "''${green}>>> Running diff ...''${reset}";
${pkgs.nvd}/bin/nvd diff /run/current-system result || error "Diff failed"
cd - > /dev/null
echo ""
echo -e "''${yellow}>>> The new configuration has not been activated.''${reset}"
echo -e "''${yellow}>>> Use ''${white_bold}nixos-rebuild switch''${reset}''${yellow} to activate.''${reset}"
''