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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nukeReferences: fix for store paths with special characters #60877

Merged
merged 1 commit into from
May 23, 2019

Conversation

veprbl
Copy link
Member

@veprbl veprbl commented May 3, 2019

Motivation for this change

I'm running nix with store directory in a custom path containing a '+' character. This prevents nukeReferences from working properly because some characters in the path get interpreted as a regular expression special characters. Broken nukeReferences will prevent python3 from building on my setup because it requires disallowedReferences = [ openssl.dev ];.

The proposed fix implements escaping of the special characters in the store path.

Things done

Tested with

with import <nixpkgs> {};

stdenvNoCC.mkDerivation {
  name = "nuke-refs-test";

  nativeBuildInputs = [ nukeReferences ];

  buildCommand = ''
    cat > $out <<EOF
    out: $out
    openssl: ${openssl}
    python: ${python}
    EOF
    nuke-refs -e ${openssl} $out
    echo
    echo "> Only out and python should be nuked:"
    cat "$out"

    echo
    echo "> This should fail:"
    nuke-refs -e /not/a/path $out
  '';
}
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

… or '.')

This introduces extra escaping for $NIX_STORE that gets interpolated
into a PCRE. The escaping is performed using a standard Perl function
"quotemeta" (see "perldoc -f quotemeta" for reference). The same value
is also used in sed regex which uses POSIX basic regular expressions
instead of PCRE, so it needs fewer characters to be escaped. It should
not cause much problem to not change sed invocation, but I replace it
with equivalent Perl expression (actually the behavior is changed to not
output a newline character after the matched output).
@veprbl
Copy link
Member Author

veprbl commented May 13, 2019

@volth Could you please look at this? I think this is correct, but I don't have much experience with Perl.

@veprbl veprbl merged commit 44f05df into NixOS:staging May 23, 2019
@veprbl veprbl deleted the pr/nuke-refs-quotemeta-fix branch December 1, 2020 17:02
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.

1 participant