From 3919c7abb6a1b46c9ccb63d1eed0d7c70cf10837 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 11 Nov 2022 14:08:34 +0100 Subject: [PATCH] Add nixos update command --- home/packages.nix | 1 + .../custom/update-nixos-system/default.nix | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 home/packages/custom/update-nixos-system/default.nix diff --git a/home/packages.nix b/home/packages.nix index a15eaa1..730350f 100644 --- a/home/packages.nix +++ b/home/packages.nix @@ -14,6 +14,7 @@ with pkgs; [ # TODO: Create one `./packages/custom/default.nix which includes all other? (callPackage ./packages/custom/dmenu-scripts { }) (callPackage ./packages/custom/update-system { }) + (callPackage ./packages/custom/update-nixos-system { }) (callPackage ./packages/custom/update-ubuntu-system { }) (callPackage ./packages/custom/push-etckeeper { }) (callPackage ./packages/custom/backup { }) diff --git a/home/packages/custom/update-nixos-system/default.nix b/home/packages/custom/update-nixos-system/default.nix new file mode 100644 index 0000000..6eaadda --- /dev/null +++ b/home/packages/custom/update-nixos-system/default.nix @@ -0,0 +1,19 @@ +{ writeShellApplication }: + +writeShellApplication { + name = "custom-update-nixos-system"; + + # Including this doesn't work + + text = '' + sudo nixos-rebuild switch --upgrade-all + + # shellcheck disable=SC2010 + oldVersion=$(ls -vr /nix/var/nix/profiles/ | grep system | head -n 2 | tail -n 1) + nvd diff "/nix/var/nix/profiles/$oldVersion" "/nix/var/nix/profiles/system" + + sudo nix-env -p /nix/var/nix/profiles/system --delete-generations +5 + nix store gc + nix store optimise + ''; +}