[Nix-dev] [nix language] strings that have paths/derivations embedded

Mathijs Kwik mathijs at bluescreen303.nl
Tue Oct 9 12:09:33 CEST 2012


Hi all,

I'm trying to escape a string using lib.escape.
My goals is to turn a string into a regex for grep that matches just
that string, so I need to escape regex special characters like . and
*.

All seems to works fine, but once the input string contains a
derivation path, it stops working.
If I manually just type the path, it works fine again.

so:
"${pkgs.findutils}/bin/find" -> escaping fails
"/nix/store/samepath-to-findutils/bin/find" -> escaping succeeds

I found the scary-sounding function "unsafeDiscardStringContext",
which seems to work around this problem.
Can someone please shed some light on what's going on (or nix
string/context handling in general) and if it that function is safe to
use for this case.

Thanks,
Mathijs


More information about the nix-dev mailing list