From b463c136ac2e0db3f0f455b1c4fc3f0e75ef9aac Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Wed, 14 Feb 2024 19:13:54 -0500 Subject: [PATCH] Fix resholve not resolving commands run by sudo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For whatever reason, when resholve encounters something like this: sudo echo hi it doesn’t resolve the echo command. I’m not sure why it doesn’t resolve that command, but I have a feeling that it’s related to this issue [1]. This commit works around that resholve limitation by pre-resolving commands that get executed by sudo. The main motivation behind this commit is to make creating a future commit easier. In order for that future commit to work, this command: sudo nixos-install must be transformed into this command: sudo because nixos-install won’t be on the PATH. [1]: --- .../deploy-jasons-nixos-config/package.nix | 7 ++++++- .../custom/install-using-jnc/package.nix | 17 +++++++++++------ .../custom/nicely-stop-session/package.nix | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/pkgCollections/custom/deploy-jasons-nixos-config/package.nix b/src/pkgCollections/custom/deploy-jasons-nixos-config/package.nix index 51c8575..3bd41ec 100644 --- a/src/pkgCollections/custom/deploy-jasons-nixos-config/package.nix +++ b/src/pkgCollections/custom/deploy-jasons-nixos-config/package.nix @@ -68,6 +68,11 @@ pkgs.resholve.writeScriptBin "deploy-jasons-nixos-config" { then nixos-rebuild "$@" --no-build-nix else - sudo --preserve-env=NIXOS_CONFIG,PATH nixos-rebuild "$@" --no-build-nix + sudo \ + --preserve-env=NIXOS_CONFIG,PATH \ + -- \ + ${pkgs.nixos-rebuild}/bin/nixos-rebuild \ + "$@" \ + --no-build-nix fi '' diff --git a/src/pkgCollections/custom/install-using-jnc/package.nix b/src/pkgCollections/custom/install-using-jnc/package.nix index a1afb1e..8fae61a 100644 --- a/src/pkgCollections/custom/install-using-jnc/package.nix +++ b/src/pkgCollections/custom/install-using-jnc/package.nix @@ -11,6 +11,11 @@ pkgs.resholve.writeScriptBin "install-using-jnc" { interpreter = "${pkgs.bash}/bin/bash"; } (let diskoDir = "${custom.jasons-nixos-config}/modules/disko"; + coreUtilPath = name: "${pkgs.coreutils}/bin/${name}"; + rm = coreUtilPath "rm"; + tee = coreUtilPath "tee"; + mkdir = coreUtilPath "mkdir"; + cp = coreUtilPath "cp"; in '' set -eu @@ -40,7 +45,7 @@ in '' function clean_up { echo Cleaning up… cd / - sudo rm --recursive --force "$temporary_config_dir" + sudo ${rm} --recursive --force "$temporary_config_dir" } trap clean_up EXIT trap clean_up SIGINT @@ -49,7 +54,7 @@ in '' function sudo_write { local -r to_write="$1" shift - echo "$to_write" | sudo tee "$*" > /dev/null + echo "$to_write" | sudo ${tee} "$*" > /dev/null } function machine_uses_disko { @@ -62,9 +67,9 @@ in '' --mode disko \ "$disko_config" fi - sudo mkdir -p "$temporary_config_dir" + sudo ${mkdir} -p "$temporary_config_dir" readonly dest="$temporary_config_dir/src" - sudo cp --recursive --remove-destination \ + sudo ${cp} --recursive --remove-destination \ "${custom.jasons-nixos-config}" \ "$dest" cd "$temporary_config_dir" @@ -73,7 +78,7 @@ in '' # jasons-hardware-configuration-generator does not write a new hardware # configuration file, then this command will make it so that # nixos-install fails. - sudo rm "$dest/modules/hardware-configuration.nix/$JNC_MACHINE_SLUG.nix" + sudo ${rm} "$dest/modules/hardware-configuration.nix/$JNC_MACHINE_SLUG.nix" sudo \ --preserve-env=JNC_MACHINE_SLUG \ JNC_INSTALLING=1 \ @@ -81,5 +86,5 @@ in '' sudo_write "$config" "$temporary_config_dir/configuration.nix" cd / - sudo nixos-install --no-root-password + sudo ${pkgs.nixos-install-tools}/bin/nixos-install --no-root-password '') diff --git a/src/pkgCollections/custom/nicely-stop-session/package.nix b/src/pkgCollections/custom/nicely-stop-session/package.nix index 3270223..a30c5e5 100644 --- a/src/pkgCollections/custom/nicely-stop-session/package.nix +++ b/src/pkgCollections/custom/nicely-stop-session/package.nix @@ -60,5 +60,5 @@ pkgs.resholve.writeScriptBin "nicely-stop-session" { readonly kde_shutdown_type systemctl_shutdown_type kde_shutdown logoutAnd"$kde_shutdown_type" || \ - sudo systemctl "$systemctl_shutdown_type" + sudo ${pkgs.systemd}/bin/systemctl "$systemctl_shutdown_type" ''