Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdenv: force unaliased rm in default fixup (avoids prompt) #290775

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from

Conversation

hraban
Copy link
Contributor

@hraban hraban commented Feb 23, 2024

Description of changes

When running genericBuild interactively from a nix-shell, a bare rm without -f will cause a prompt to the user if they have rm aliased to rm -i. This is a pretty common alias.

Same would hold for cp, mv, etc.

Obviously a pretty painful patch in terms of rebuilds... :/

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 馃憤 reaction to pull requests you find important.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/3694

@@ -87,7 +87,7 @@ stripDirs() {
# be stripped, so ignore specifically this code.
[[ "$exit_code" = 123 || -z "$exit_code" ]] || (cat "$striperr" 1>&2 && exit 1)

rm "$striperr"
rm -f "$striperr"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-f also hides errors. I think a proper solution would be to unalias common aliases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also solve the problem with mv and cp not letting a -f override a -i 馃憤 But it'd have to be local to the function, because we can't suddenly turn off a alias rm='rm -i' in someone's dev shell

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rather remove all aliases in the beginning of genericBuild otherwise we could need to add \ to potentially many program executions and the cost of rebuilding stdenv everytime.

Copy link
Contributor Author

@hraban hraban Mar 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to design a POC but it turns out to be surprisingly difficult to do this for a function sourced by an interactive shell.

test.sh:

foo () {
	echo foo
}

foo_subshell () (
	echo foo
)

foo_unalias () {
	unalias -a
	echo foo
}

foo_unalias_subshell () (
	unalias -a
	echo foo
)

foo_shopt () {
	shopt -u expand_aliases
	echo foo
	shopt -s expand_aliases
}

foo_shopt_subshell () (
	shopt -u expand_aliases
	echo foo
	shopt -s expand_aliases
)

Result:

$ alias echo="echo aliased"
$ source test.sh
$ foo
aliased foo
$ foo_subshell
aliased foo
$ foo_unalias
aliased foo
$ foo_unalias_subshell
aliased foo
$ foo_shopt
aliased foo
$ foo_shopt_subshell
aliased foo
$ echo hello
hello

Do you have any other ideas?

(Edit: I agree with your point btw, I just can't think of a nice way to do it :/ )

When running `genericBuild` interactively from a nix-shell, a bare `rm` without
could be aliased to `rm -i`, which would cause a prompt to the user. This is a
pretty common alias.

Same would hold for cp, mv, etc.
@hraban hraban changed the title stdenv: use rm -f in default fixup (avoids prompt) stdenv: force unaliased rm in default fixup (avoids prompt) Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants