Skip to content

Commit

Permalink
fix: work inside a flake
Browse files Browse the repository at this point in the history
While we don't want to encourage it, it would be helpful to ease
adoption if users could call this module function from inside their
flake.nix. The only thing preventing that was the path referencing
becoming a pure /nix/store path reference implicitly (via the flake)
and so failing because of the string context.

Fix this by simply removing the string context. This isn't actually
unsafe since if the absolute path literal refers to a store path and is
ever coerced back to a string, nix will readd the context automatically.
  • Loading branch information
nrdxp committed Aug 4, 2024
1 parent da202e3 commit 8007480
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion std/path/strToPath.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
str:
let
# strip off the first `/` of an absolute path
frag = std.substring 1 (-1) str;
# disgarding the string context of a store path should be safe here
# since if the path refers to a store path, the context will be readded
# if/when the path is turned back into a string
frag = std.unsafeDiscardStringContext (std.substring 1 (-1) str);
# will fail if the string does not represent an absolute path
# which is what we want since this function makes little sense otherwise
validate = std.toPath str;
Expand Down

0 comments on commit 8007480

Please sign in to comment.