From df00e58bd93103af641894d0e2b6855ffff801c9 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Fri, 14 Mar 2025 09:16:50 +0100 Subject: [PATCH] Add sos script for faster nixos-updates This uses the remote builder as nix store, so the build dependencies for the new system do not have to be present locally. Therefore, if hydra built the system it should be possible to just download the output derivation. --- modules/home/suites/cli/default.nix | 1 + packages/sos/default.nix | 38 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 packages/sos/default.nix diff --git a/modules/home/suites/cli/default.nix b/modules/home/suites/cli/default.nix index 41d8f0c..b10ec69 100644 --- a/modules/home/suites/cli/default.nix +++ b/modules/home/suites/cli/default.nix @@ -74,6 +74,7 @@ in ## My scripts frajul.edit-config frajul.lntocp + frajul.sos ]; }; } diff --git a/packages/sos/default.nix b/packages/sos/default.nix new file mode 100644 index 0000000..894de16 --- /dev/null +++ b/packages/sos/default.nix @@ -0,0 +1,38 @@ +{ + # 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 = "sos"; + + runtimeInputs = with pkgs; [ + nix-output-monitor + jq + ]; + + # TODO: somehow avoid --no-check-sigs?? + text = '' + #!/usr/bin/env sh + # This script performs a nixos system update using the remote builder as remote store. + # This should improve the system update performance drastically + + echo "########## building... ##########" + OUT=$(nom build "$FLAKE#nixosConfigurations.$(hostname).config.system.build.toplevel" --store ssh-ng://nix@builder.julian-mutter.de --eval-store auto --json | jq -r '.[0].outputs.out') + echo "########## output is: $OUT ##########" + echo "########## downloading... ##########" + nix copy --no-check-sigs --from ssh-ng://nix@builder.julian-mutter.de "$OUT" + + echo "########## activating... ##########" + sudo "$OUT"/bin/switch-to-configuration switch + ''; +}