From e5ed2735616c95b151c069bf9c612cf292bc2ccb Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Thu, 29 Feb 2024 10:31:28 +0100 Subject: [PATCH] topgrade: Add script to update flake and continue on failed step --- homes/x86_64-linux/julian@aspi/default.nix | 1 + modules/home/topgrade/default.nix | 3 ++ packages/home-update-flake/default.nix | 41 ++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 packages/home-update-flake/default.nix diff --git a/homes/x86_64-linux/julian@aspi/default.nix b/homes/x86_64-linux/julian@aspi/default.nix index a76ce2a..582a11e 100644 --- a/homes/x86_64-linux/julian@aspi/default.nix +++ b/homes/x86_64-linux/julian@aspi/default.nix @@ -65,6 +65,7 @@ config, ... }: { ## My scripts pkgs.frajul.deploy-to-pianopi pkgs.frajul.edit-config + pkgs.frajul.home-update-flake ]; home.file = { diff --git a/modules/home/topgrade/default.nix b/modules/home/topgrade/default.nix index 5b80fd4..363aa13 100644 --- a/modules/home/topgrade/default.nix +++ b/modules/home/topgrade/default.nix @@ -31,6 +31,9 @@ in { misc.no_self_update = true; misc.pre_sudo = true; # Cache sudo password for 5 more minutes misc.assume_yes = true; + misc.no_retry = true; + + pre_commands."Update dotfiles flake" = "home-update-flake"; git = { # Additional git repositories to pull diff --git a/packages/home-update-flake/default.nix b/packages/home-update-flake/default.nix new file mode 100644 index 0000000..c6fff8f --- /dev/null +++ b/packages/home-update-flake/default.nix @@ -0,0 +1,41 @@ +{ +# Snowfall Lib provides a customized `lib` instance with access to your flake's library +# as well as the libraries available from your flake's inputs. +lib, +# You also have access to your flake's inputs. +inputs, + +# All other arguments come from NixPkgs. You can use `pkgs` to pull packages or helpers +# programmatically or you may add the named attributes as arguments here. +pkgs, stdenv, ... }: + +pkgs.writeShellApplication { + name = "home-update-flake"; + + runtimeInputs = with pkgs; [ ]; + + text = '' + # Exit when errors occur + set -e + + echo "Updating flake..." + nix flake update ~/.dotfiles + + set +e + git -C ~/.dotfiles diff --quiet flake.lock + LOCK_FILE_CHANGED=$? + set -e + if [[ $LOCK_FILE_CHANGED == 1 ]]; then + CURRENT_GENERATION=$(home-manager generations | head -n 1 | cut -d " " -f 5) + + echo "found current gen" + + MESSAGE="Update flake at home-manager generation $CURRENT_GENERATION" + + git -C ~/.dotfiles commit flake.lock -m "$MESSAGE" + echo "Updated flake.lock file committed to git!" + else + echo "No updates available." + fi + ''; +}