From abd2b8dfdf504722c2033961d11daba9f656584e Mon Sep 17 00:00:00 2001 From: Andre Date: Sat, 28 Sep 2024 13:18:26 -0400 Subject: [PATCH] General: update nixos upgrade helper script --- bin/nixos-upgrade-script.sh | 28 +++++++++++----------------- modules/common.nix | 3 +++ modules/system/nix.nix | 12 +----------- modules/users/aires/default.nix | 1 + 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/bin/nixos-upgrade-script.sh b/bin/nixos-upgrade-script.sh index a21f615..179a86e 100755 --- a/bin/nixos-upgrade-script.sh +++ b/bin/nixos-upgrade-script.sh @@ -1,15 +1,13 @@ #!/usr/bin/env bash # Wrapper script for nixos-rebuild -#set -e - # Configuration parameters operation="switch" # The nixos-rebuild operation to use hostname=$(hostname) # The name of the host to build -flakeDir="." # Path to the flake file (and optionally the hostname) -remainingArgs="" # All remaining arguments that haven't been processed -commit=true # Whether to update git (true by default) -buildHost="" # Which host to build the system on. +flakeDir="." # Path to the flake file (and optionally the hostname) +remainingArgs="" # All remaining arguments that haven't been processed +commit=true # Whether to update git (true by default) +buildHost="" # Which host to build the system on. function usage() { echo "Usage: nixos-upgrade-script.sh [-o|--operation operation] [-f|--flake path-to-flake-file] [extra nixos-rebuild parameters]" @@ -24,14 +22,15 @@ function usage() { } function run_operation { - echo "Full operation: nixos-rebuild $1 --flake $flakeDir#$hostname $( [ "$buildHost" != "" ] && echo "--build-host $buildHost" ) $remainingArgs" + echo "Full operation: nixos-rebuild $1 --flake $flakeDir#$hostname $( [ "$buildHost" != "" ] && echo "--build-host $buildHost" ) $remainingArgs --use-remote-sudo" + nixos-rebuild $operation --flake .#$hostname $remainingArgs --use-remote-sudo # Only request super-user permission if we're switching - if [[ "$1" =~ ^(switch|boot|test)$ ]]; then - sudo nixos-rebuild $operation --flake .#$hostname $remainingArgs - else - nixos-rebuild $operation --flake .#$hostname $remainingArgs - fi + #if [[ "$1" =~ ^(switch|boot|test)$ ]]; then + # nixos-rebuild $operation --flake .#$hostname $remainingArgs --use-remote-sudo + #else + # nixos-rebuild $operation --flake .#$hostname $remainingArgs + #fi } # Argument processing logic shamelessly stolen from https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash @@ -85,11 +84,6 @@ if [ $commit = true ]; then git push fi -# If this is a remote build, run the build as non-sudo first -if [[ "$buildHost" != "" ]]; then - run_operation "build" -fi - run_operation $operation exit 0 diff --git a/modules/common.nix b/modules/common.nix index 7561b26..0560761 100644 --- a/modules/common.nix +++ b/modules/common.nix @@ -17,6 +17,9 @@ zellij # Terminal multiplexer ]; + # Install the nos helper script + aux.system.nixos-upgrade-script.enable = true; + nixpkgs.overlays = [ (final: _prev: { # Allow packages from the unstable repo by using 'pkgs.unstable' diff --git a/modules/system/nix.nix b/modules/system/nix.nix index 5cf4d6b..4203a5c 100644 --- a/modules/system/nix.nix +++ b/modules/system/nix.nix @@ -23,17 +23,7 @@ in type = lib.types.str; default = "monthly"; }; - nixos-upgrade-script = { - enable = lib.mkEnableOption "Installs the nos (nixos-upgrade-script) helper script."; - configDir = lib.mkOption { - type = lib.types.str; - description = "Path to your NixOS configuration files."; - }; - user = lib.mkOption { - type = lib.types.str; - description = "The user to run the upgrade script as."; - }; - }; + nixos-upgrade-script.enable = lib.mkEnableOption "Installs the nos (nixos-upgrade-script) helper script."; }; }; config = { diff --git a/modules/users/aires/default.nix b/modules/users/aires/default.nix index 9ab5e93..f986df2 100644 --- a/modules/users/aires/default.nix +++ b/modules/users/aires/default.nix @@ -90,6 +90,7 @@ in theme = "gentoo"; }; shellAliases = { + nos = lib.mkIf config.aux.system.nixos-upgrade-script.enable "nixos-upgrade-script"; z = "zellij"; update = "upgrade"; upgrade = "nh os boot --update --ask";