Skip to content

refactor(system): make root cmd+flags a property of the command struct#181

Merged
water-sucks merged 1 commit intonix-community:mainfrom
water-sucks:refactor-run-as-root-mechanism
Feb 17, 2026
Merged

refactor(system): make root cmd+flags a property of the command struct#181
water-sucks merged 1 commit intonix-community:mainfrom
water-sucks:refactor-run-as-root-mechanism

Conversation

@water-sucks
Copy link
Copy Markdown
Collaborator

When running SSH commands with a root elevation command like sudo, this didn't quite work in all cases when passing environment variables. That is because the root command was simply getting replaced in the command's Name string and Args slice, rather than being treated specially.

This resulted in invocations of sh -c "export VAR=value; set -- <root cmd flags> <args>; sudo exec $@", which ended up wiping the set environment variables after elevation, rather than sudo <root cmd flags> sh -c "export VAR=value; set -- <args>; exec $@", which would preserve the set variables like VAR through SSH and through the root command env var sanitation process.

This PR refactors the root command and possible root command flags into specific Command fields so that this distinction can be made when creating the shell wrapper on SSH systems to preserve env vars.

Closes #180.

@water-sucks water-sucks force-pushed the refactor-run-as-root-mechanism branch from 22b663e to bb4577a Compare February 17, 2026 18:57
@water-sucks water-sucks merged commit 5d2d017 into nix-community:main Feb 17, 2026
2 checks passed
@water-sucks water-sucks deleted the refactor-run-as-root-mechanism branch February 17, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apply: necessary environment variables are not passed to switch-to-configuration with --local-root or --remote-root

1 participant