lib: add builtins prefixes for prelude functions to improve clarity

This commit is contained in:
NAHO
2025-09-30 09:36:35 +02:00
parent 6177c4ad72
commit e8f998c3bc
5 changed files with 11 additions and 11 deletions

View File

@@ -947,7 +947,7 @@ in
`gitTrackedWith` does not perform any filtering when the path is a [Nix store path](https://nixos.org/manual/nix/stable/store/store-path.html#store-path) and not a repository. `gitTrackedWith` does not perform any filtering when the path is a [Nix store path](https://nixos.org/manual/nix/stable/store/store-path.html#store-path) and not a repository.
In this way, it accommodates the use case where the expression that makes the `gitTracked` call does not reside in an actual git repository anymore, In this way, it accommodates the use case where the expression that makes the `gitTracked` call does not reside in an actual git repository anymore,
and has presumably already been fetched in a way that excludes untracked files. and has presumably already been fetched in a way that excludes untracked files.
Fetchers with such equivalent behavior include `fetchGit`, `fetchTree` (experimental), and `pkgs.fetchgit` when used without `leaveDotGit`. Fetchers with such equivalent behavior include `builtins.fetchGit`, `builtins.fetchTree` (experimental), and `pkgs.fetchgit` when used without `leaveDotGit`.
If you don't need the configuration, If you don't need the configuration,
you can use [`gitTracked`](#function-library-lib.fileset.gitTracked) instead. you can use [`gitTracked`](#function-library-lib.fileset.gitTracked) instead.
@@ -956,7 +956,7 @@ in
(which uses [`--cached`](https://git-scm.com/docs/git-ls-files#Documentation/git-ls-files.txt--c) by default). (which uses [`--cached`](https://git-scm.com/docs/git-ls-files#Documentation/git-ls-files.txt--c) by default).
:::{.warning} :::{.warning}
Currently this function is based on [`fetchGit`](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-fetchGit) Currently this function is based on [`builtins.fetchGit`](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-fetchGit)
As such, this function causes all Git-tracked files to be unnecessarily added to the Nix store, As such, this function causes all Git-tracked files to be unnecessarily added to the Nix store,
without being re-usable by [`toSource`](#function-library-lib.fileset.toSource). without being re-usable by [`toSource`](#function-library-lib.fileset.toSource).

View File

@@ -932,13 +932,13 @@ rec {
throw '' throw ''
lib.fileset.${function}: The ${argument} (${toString path}) is a store path within a working tree of a Git repository. lib.fileset.${function}: The ${argument} (${toString path}) is a store path within a working tree of a Git repository.
This indicates that a source directory was imported into the store using a method such as `import "''${./.}"` or `path:.`. This indicates that a source directory was imported into the store using a method such as `import "''${./.}"` or `path:.`.
This function currently does not support such a use case, since it currently relies on `fetchGit`. This function currently does not support such a use case, since it currently relies on `builtins.fetchGit`.
You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository. You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository.
If you can't avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.'' If you can't avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.''
else else
# Otherwise we're going to assume that the path was a Git directory originally, # Otherwise we're going to assume that the path was a Git directory originally,
# but it was fetched using a method that already removed files not tracked by Git, # but it was fetched using a method that already removed files not tracked by Git,
# such as `fetchGit`, `pkgs.fetchgit` or others. # such as `builtins.fetchGit`, `pkgs.fetchgit` or others.
# So we can just import the path in its entirety. # So we can just import the path in its entirety.
_singleton path; _singleton path;
@@ -946,7 +946,7 @@ rec {
tryFetchGit = tryFetchGit =
let let
# This imports the files unnecessarily, which currently can't be avoided # This imports the files unnecessarily, which currently can't be avoided
# because `fetchGit` is the only function exposing which files are tracked by Git. # because `builtins.fetchGit` is the only function exposing which files are tracked by Git.
# With the [lazy trees PR](https://github.com/NixOS/nix/pull/6530), # With the [lazy trees PR](https://github.com/NixOS/nix/pull/6530),
# the unnecessarily import could be avoided. # the unnecessarily import could be avoided.
# However a simpler alternative still would be [a builtins.gitLsFiles](https://github.com/NixOS/nix/issues/2944). # However a simpler alternative still would be [a builtins.gitLsFiles](https://github.com/NixOS/nix/issues/2944).
@@ -960,7 +960,7 @@ rec {
in in
# We can identify local working directories by checking for .git, # We can identify local working directories by checking for .git,
# see https://git-scm.com/docs/gitrepository-layout#_description. # see https://git-scm.com/docs/gitrepository-layout#_description.
# Note that `fetchGit` _does_ work for bare repositories (where there's no `.git`), # Note that `builtins.fetchGit` _does_ work for bare repositories (where there's no `.git`),
# even though `git ls-files` wouldn't return any files in that case. # even though `git ls-files` wouldn't return any files in that case.
if !pathExists (path + "/.git") then if !pathExists (path + "/.git") then
throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to point to a local working tree of a Git repository, but it's not." throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to point to a local working tree of a Git repository, but it's not."

View File

@@ -1415,7 +1415,7 @@ expectEqual '(import '"$storePath"' { fs = lib.fileset; }).outPath' \""$storePat
## But it fails if the path is imported with a fetcher that doesn't remove .git (like just using "${./.}") ## But it fails if the path is imported with a fetcher that doesn't remove .git (like just using "${./.}")
expectFailure 'import "${./.}" { fs = lib.fileset; }' 'lib.fileset.gitTracked: The argument \(.*\) is a store path within a working tree of a Git repository. expectFailure 'import "${./.}" { fs = lib.fileset; }' 'lib.fileset.gitTracked: The argument \(.*\) is a store path within a working tree of a Git repository.
[[:blank:]]*This indicates that a source directory was imported into the store using a method such as `import "\$\{./.\}"` or `path:.`. [[:blank:]]*This indicates that a source directory was imported into the store using a method such as `import "\$\{./.\}"` or `path:.`.
[[:blank:]]*This function currently does not support such a use case, since it currently relies on `fetchGit`. [[:blank:]]*This function currently does not support such a use case, since it currently relies on `builtins.fetchGit`.
[[:blank:]]*You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository. [[:blank:]]*You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository.
[[:blank:]]*If you can'\''t avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.' [[:blank:]]*If you can'\''t avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.'
@@ -1441,12 +1441,12 @@ expectEqual '(import '"$storePathSub"' { fs = lib.fileset; }).outPath' \""$store
## But it fails if the path is imported with a fetcher that doesn't remove .git (like just using "${./.}") ## But it fails if the path is imported with a fetcher that doesn't remove .git (like just using "${./.}")
expectFailure 'import "${./.}" { fs = lib.fileset; }' 'lib.fileset.gitTrackedWith: The second argument \(.*\) is a store path within a working tree of a Git repository. expectFailure 'import "${./.}" { fs = lib.fileset; }' 'lib.fileset.gitTrackedWith: The second argument \(.*\) is a store path within a working tree of a Git repository.
[[:blank:]]*This indicates that a source directory was imported into the store using a method such as `import "\$\{./.\}"` or `path:.`. [[:blank:]]*This indicates that a source directory was imported into the store using a method such as `import "\$\{./.\}"` or `path:.`.
[[:blank:]]*This function currently does not support such a use case, since it currently relies on `fetchGit`. [[:blank:]]*This function currently does not support such a use case, since it currently relies on `builtins.fetchGit`.
[[:blank:]]*You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository. [[:blank:]]*You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository.
[[:blank:]]*If you can'\''t avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.' [[:blank:]]*If you can'\''t avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.'
expectFailure 'import "${./.}/sub" { fs = lib.fileset; }' 'lib.fileset.gitTracked: The argument \(.*/sub\) is a store path within a working tree of a Git repository. expectFailure 'import "${./.}/sub" { fs = lib.fileset; }' 'lib.fileset.gitTracked: The argument \(.*/sub\) is a store path within a working tree of a Git repository.
[[:blank:]]*This indicates that a source directory was imported into the store using a method such as `import "\$\{./.\}"` or `path:.`. [[:blank:]]*This indicates that a source directory was imported into the store using a method such as `import "\$\{./.\}"` or `path:.`.
[[:blank:]]*This function currently does not support such a use case, since it currently relies on `fetchGit`. [[:blank:]]*This function currently does not support such a use case, since it currently relies on `builtins.fetchGit`.
[[:blank:]]*You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository. [[:blank:]]*You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository.
[[:blank:]]*If you can'\''t avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.' [[:blank:]]*If you can'\''t avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.'
rm -rf -- * rm -rf -- *

View File

@@ -102,7 +102,7 @@ Decision: It should be `./.`.
- (-) `./.` is rather long. - (-) `./.` is rather long.
- (-) We don't require users to type this though, as it's only output by the library. - (-) We don't require users to type this though, as it's only output by the library.
As inputs all three variants are supported for subpaths (and we can't do anything about absolute paths) As inputs all three variants are supported for subpaths (and we can't do anything about absolute paths)
- (-) `dirOf "foo" == "."`, so `.` would be consistent with that. - (-) `builtins.dirOf "foo" == "."`, so `.` would be consistent with that.
- (+) `./.` is consistent with the [decision to have leading `./`][leading-dots]. - (+) `./.` is consistent with the [decision to have leading `./`][leading-dots].
- (+) `./.` is a valid Nix path expression, although this property does not hold for every relative path or subpath. - (+) `./.` is a valid Nix path expression, although this property does not hold for every relative path or subpath.

View File

@@ -4487,7 +4487,7 @@ runTests {
testPackagesFromDirectoryRecursiveStringDirectory = { testPackagesFromDirectoryRecursiveStringDirectory = {
expr = packagesFromDirectoryRecursive { expr = packagesFromDirectoryRecursive {
callPackage = path: overrides: import path overrides; callPackage = path: overrides: import path overrides;
# Do NOT remove the `toString` call here!!! # Do NOT remove the `builtins.toString` call here!!!
directory = toString ./packages-from-directory/plain; directory = toString ./packages-from-directory/plain;
}; };
expected = { expected = {