Skip to content

Commit

Permalink
Fix resholve not resolving commands run by sudo
Browse files Browse the repository at this point in the history
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 <path-to-nixos-install>

because nixos-install won’t be on the PATH.

[1]: <abathur/resholve#113>
  • Loading branch information
Jayman2000 committed Feb 15, 2024
1 parent 75fca97 commit b463c13
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
''
17 changes: 11 additions & 6 deletions src/pkgCollections/custom/install-using-jnc/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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"
Expand All @@ -73,13 +78,13 @@ 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 \
"${custom.jasons-hardware-configuration-generator}/bin/jasons-hardware-configuration-generator"
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
'')
2 changes: 1 addition & 1 deletion src/pkgCollections/custom/nicely-stop-session/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
''

0 comments on commit b463c13

Please sign in to comment.