215: lib/pathsToImportedAttrs: discard string context in the names to prevent flake check error r=nrdxp a=Pacman99

So I learned about this myself while working on it. Nix has a thing called string context, where strings refer to various store paths that they used to contain. This is normally a good thing to guarantee purity, but flake outputs cannot contain store paths. So when `pathsToImportedAttrs` is passed a list of store paths, and is then used for a flake output, we get a very confusing error that the string refers to a store path - even though it doesn't look like it does! 
I think its good to review this as a separate Pr, since it requires calling an unsafe nix builtin.

Co-authored-by: Pacman99 <pachum99@gmail.com>
This commit is contained in:
bors[bot] 2021-03-26 21:30:04 +00:00 committed by GitHub
commit 3c772df5b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,9 @@ rec {
paths' = lib.filter (lib.hasSuffix ".nix") paths; paths' = lib.filter (lib.hasSuffix ".nix") paths;
in in
genAttrs' paths' (path: { genAttrs' paths' (path: {
name = lib.removeSuffix ".nix" (baseNameOf path); name = lib.removeSuffix ".nix"
# Safe as long this is just used as a name
(builtins.unsafeDiscardStringContext (baseNameOf path));
value = import path; value = import path;
}); });