lib: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:
builtins=(
abort
baseNameOf
break
derivation
derivationStrict
dirOf
false
fetchGit
fetchMercurial
fetchTarball
fetchTree
fromTOML
import
isNull
map
null
placeholder
removeAttrs
scopedImport
throw
toString
true
)
fd --type file . lib --exec-batch sed --in-place --regexp-extended "
s/\<builtins\.($(
printf '%s\n' "${builtins[@]}" |
paste --delimiter '|' --serial -
))\>/\1/g
"
nix fmt
This commit is contained in:
@@ -47,7 +47,7 @@ rec {
|
||||
:::
|
||||
*/
|
||||
# TODO(Profpatsch): add tests that check stderr
|
||||
assertMsg = pred: msg: pred || builtins.throw msg;
|
||||
assertMsg = pred: msg: pred || throw msg;
|
||||
|
||||
/**
|
||||
Specialized `assertMsg` for checking if `val` is one of the elements
|
||||
|
||||
@@ -2149,7 +2149,7 @@ rec {
|
||||
chooseDevOutputs :: [Derivation] -> [Derivation]
|
||||
```
|
||||
*/
|
||||
chooseDevOutputs = builtins.map getDev;
|
||||
chooseDevOutputs = map getDev;
|
||||
|
||||
/**
|
||||
Make various Nix tools consider the contents of the resulting
|
||||
@@ -2230,7 +2230,7 @@ rec {
|
||||
intersection = builtins.intersectAttrs x y;
|
||||
collisions = lib.concatStringsSep " " (builtins.attrNames intersection);
|
||||
mask = builtins.mapAttrs (
|
||||
name: value: builtins.throw "unionOfDisjoint: collision on ${name}; complete list: ${collisions}"
|
||||
name: value: throw "unionOfDisjoint: collision on ${name}; complete list: ${collisions}"
|
||||
) intersection;
|
||||
in
|
||||
(x // y) // mask;
|
||||
|
||||
@@ -250,9 +250,9 @@ let
|
||||
# See https://github.com/NixOS/nixpkgs/pull/194391 for details.
|
||||
closePropagationFast =
|
||||
list:
|
||||
builtins.map (x: x.val) (
|
||||
map (x: x.val) (
|
||||
builtins.genericClosure {
|
||||
startSet = builtins.map (x: {
|
||||
startSet = map (x: {
|
||||
key = x.outPath;
|
||||
val = x;
|
||||
}) (builtins.filter (x: x != null) list);
|
||||
|
||||
@@ -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.
|
||||
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.
|
||||
Fetchers with such equivalent behavior include `builtins.fetchGit`, `builtins.fetchTree` (experimental), and `pkgs.fetchgit` when used without `leaveDotGit`.
|
||||
Fetchers with such equivalent behavior include `fetchGit`, `fetchTree` (experimental), and `pkgs.fetchgit` when used without `leaveDotGit`.
|
||||
|
||||
If you don't need the configuration,
|
||||
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).
|
||||
|
||||
:::{.warning}
|
||||
Currently this function is based on [`builtins.fetchGit`](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-fetchGit)
|
||||
Currently this function is based on [`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,
|
||||
without being re-usable by [`toSource`](#function-library-lib.fileset.toSource).
|
||||
|
||||
|
||||
@@ -932,13 +932,13 @@ rec {
|
||||
throw ''
|
||||
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 function currently does not support such a use case, since it currently relies on `builtins.fetchGit`.
|
||||
This function currently does not support such a use case, since it currently relies on `fetchGit`.
|
||||
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.''
|
||||
else
|
||||
# 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,
|
||||
# such as `builtins.fetchGit`, `pkgs.fetchgit` or others.
|
||||
# such as `fetchGit`, `pkgs.fetchgit` or others.
|
||||
# So we can just import the path in its entirety.
|
||||
_singleton path;
|
||||
|
||||
@@ -946,7 +946,7 @@ rec {
|
||||
tryFetchGit =
|
||||
let
|
||||
# This imports the files unnecessarily, which currently can't be avoided
|
||||
# because `builtins.fetchGit` is the only function exposing which files are tracked by Git.
|
||||
# because `fetchGit` is the only function exposing which files are tracked by Git.
|
||||
# With the [lazy trees PR](https://github.com/NixOS/nix/pull/6530),
|
||||
# the unnecessarily import could be avoided.
|
||||
# However a simpler alternative still would be [a builtins.gitLsFiles](https://github.com/NixOS/nix/issues/2944).
|
||||
@@ -960,7 +960,7 @@ rec {
|
||||
in
|
||||
# We can identify local working directories by checking for .git,
|
||||
# see https://git-scm.com/docs/gitrepository-layout#_description.
|
||||
# Note that `builtins.fetchGit` _does_ work for bare repositories (where there's no `.git`),
|
||||
# Note that `fetchGit` _does_ work for bare repositories (where there's no `.git`),
|
||||
# even though `git ls-files` wouldn't return any files in that case.
|
||||
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."
|
||||
|
||||
@@ -1406,16 +1406,16 @@ echo '{ fs }: fs.toSource { root = ./.; fileset = fs.gitTracked ./.; }' > defaul
|
||||
git add .
|
||||
|
||||
## We can evaluate it locally just fine, `fetchGit` is used underneath to filter git-tracked files
|
||||
expectEqual '(import ./. { fs = lib.fileset; }).outPath' '(builtins.fetchGit ./.).outPath'
|
||||
expectEqual '(import ./. { fs = lib.fileset; }).outPath' '(fetchGit ./.).outPath'
|
||||
|
||||
## We can also evaluate when importing from fetched store paths
|
||||
storePath=$(expectStorePath 'builtins.fetchGit ./.')
|
||||
storePath=$(expectStorePath 'fetchGit ./.')
|
||||
expectEqual '(import '"$storePath"' { fs = lib.fileset; }).outPath' \""$storePath"\"
|
||||
|
||||
## 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.
|
||||
[[: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 `builtins.fetchGit`.
|
||||
[[:blank:]]*This function currently does not support such a use case, since it currently relies on `fetchGit`.
|
||||
[[: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.'
|
||||
|
||||
@@ -1429,24 +1429,24 @@ echo '{ fs }: fs.toSource { root = ./.; fileset = fs.gitTracked ./.; }' > sub/de
|
||||
git -C sub add .
|
||||
|
||||
## We can evaluate it locally just fine, `fetchGit` is used underneath to filter git-tracked files
|
||||
expectEqual '(import ./. { fs = lib.fileset; }).outPath' '(builtins.fetchGit { url = ./.; submodules = true; }).outPath'
|
||||
expectEqual '(import ./sub { fs = lib.fileset; }).outPath' '(builtins.fetchGit ./sub).outPath'
|
||||
expectEqual '(import ./. { fs = lib.fileset; }).outPath' '(fetchGit { url = ./.; submodules = true; }).outPath'
|
||||
expectEqual '(import ./sub { fs = lib.fileset; }).outPath' '(fetchGit ./sub).outPath'
|
||||
|
||||
## We can also evaluate when importing from fetched store paths
|
||||
storePathWithSub=$(expectStorePath 'builtins.fetchGit { url = ./.; submodules = true; }')
|
||||
storePathWithSub=$(expectStorePath 'fetchGit { url = ./.; submodules = true; }')
|
||||
expectEqual '(import '"$storePathWithSub"' { fs = lib.fileset; }).outPath' \""$storePathWithSub"\"
|
||||
storePathSub=$(expectStorePath 'builtins.fetchGit ./sub')
|
||||
storePathSub=$(expectStorePath 'fetchGit ./sub')
|
||||
expectEqual '(import '"$storePathSub"' { fs = lib.fileset; }).outPath' \""$storePathSub"\"
|
||||
|
||||
## 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.
|
||||
[[: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 `builtins.fetchGit`.
|
||||
[[:blank:]]*This function currently does not support such a use case, since it currently relies on `fetchGit`.
|
||||
[[: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.'
|
||||
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 function currently does not support such a use case, since it currently relies on `builtins.fetchGit`.
|
||||
[[:blank:]]*This function currently does not support such a use case, since it currently relies on `fetchGit`.
|
||||
[[: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.'
|
||||
rm -rf -- *
|
||||
|
||||
@@ -150,7 +150,7 @@ rec {
|
||||
) intConstructors;
|
||||
in
|
||||
throw ''
|
||||
The GVariant type for number “${builtins.toString v}” is unclear.
|
||||
The GVariant type for number “${toString v}” is unclear.
|
||||
Please wrap the value with one of the following, depending on the value type in GSettings schema:
|
||||
|
||||
${lib.concatMapStringsSep "\n" (
|
||||
|
||||
@@ -399,7 +399,7 @@ rec {
|
||||
=> true
|
||||
lib.getLicenseFromSpdxIdOr "MY LICENSE" null
|
||||
=> null
|
||||
lib.getLicenseFromSpdxIdOr "MY LICENSE" (builtins.throw "No SPDX ID matches MY LICENSE")
|
||||
lib.getLicenseFromSpdxIdOr "MY LICENSE" (throw "No SPDX ID matches MY LICENSE")
|
||||
=> error: No SPDX ID matches MY LICENSE
|
||||
```
|
||||
:::
|
||||
|
||||
@@ -102,7 +102,7 @@ Decision: It should be `./.`.
|
||||
- (-) `./.` is rather long.
|
||||
- (-) 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)
|
||||
- (-) `builtins.dirOf "foo" == "."`, so `.` would be consistent with that.
|
||||
- (-) `dirOf "foo" == "."`, so `.` would be consistent with that.
|
||||
- (+) `./.` 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.
|
||||
|
||||
|
||||
@@ -1135,7 +1135,7 @@ rec {
|
||||
"."
|
||||
"~"
|
||||
];
|
||||
toEscape = builtins.removeAttrs asciiTable unreserved;
|
||||
toEscape = removeAttrs asciiTable unreserved;
|
||||
in
|
||||
replaceStrings (builtins.attrNames toEscape) (
|
||||
lib.mapAttrsToList (_: c: "%${fixedWidthString 2 "0" (lib.toHexString c)}") toEscape
|
||||
|
||||
@@ -75,7 +75,7 @@ let
|
||||
|
||||
# Those two will always be derived from "config", if given, so they should NOT
|
||||
# be overridden further down with "// args".
|
||||
args = builtins.removeAttrs allArgs [
|
||||
args = removeAttrs allArgs [
|
||||
"parsed"
|
||||
"system"
|
||||
];
|
||||
|
||||
@@ -326,7 +326,7 @@ in
|
||||
coerce_str_to_int_coercer_ouput = getMatrix {
|
||||
outerTypeName = "coercedTo";
|
||||
innerTypeName = "int->str";
|
||||
getType = a: b: a.coercedTo b.int builtins.toString a.str;
|
||||
getType = a: b: a.coercedTo b.int toString a.str;
|
||||
value = [ ];
|
||||
testAttrs = {
|
||||
expectedError = {
|
||||
|
||||
@@ -4487,8 +4487,8 @@ runTests {
|
||||
testPackagesFromDirectoryRecursiveStringDirectory = {
|
||||
expr = packagesFromDirectoryRecursive {
|
||||
callPackage = path: overrides: import path overrides;
|
||||
# Do NOT remove the `builtins.toString` call here!!!
|
||||
directory = builtins.toString ./packages-from-directory/plain;
|
||||
# Do NOT remove the `toString` call here!!!
|
||||
directory = toString ./packages-from-directory/plain;
|
||||
};
|
||||
expected = {
|
||||
a = "a";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{
|
||||
options = {
|
||||
value = lib.mkOption {
|
||||
type = lib.types.coercedTo lib.types.int builtins.toString lib.types.str;
|
||||
type = lib.types.coercedTo lib.types.int toString lib.types.str;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
options = {
|
||||
value = lib.mkOption {
|
||||
default = 42;
|
||||
type = lib.types.coercedTo lib.types.int builtins.toString lib.types.str;
|
||||
type = lib.types.coercedTo lib.types.int toString lib.types.str;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
_module.args.result =
|
||||
let
|
||||
r = builtins.removeAttrs config [ "_module" ];
|
||||
r = removeAttrs config [ "_module" ];
|
||||
in
|
||||
builtins.trace (builtins.deepSeq r r) (
|
||||
r == {
|
||||
|
||||
@@ -769,7 +769,7 @@ in
|
||||
importTOML :: path -> any
|
||||
```
|
||||
*/
|
||||
importTOML = path: builtins.fromTOML (builtins.readFile path);
|
||||
importTOML = path: fromTOML (builtins.readFile path);
|
||||
|
||||
/**
|
||||
`warn` *`message`* *`value`*
|
||||
@@ -975,7 +975,7 @@ in
|
||||
unexpected = lib.subtractLists valid given;
|
||||
in
|
||||
lib.throwIfNot (unexpected == [ ])
|
||||
"${msg}: ${builtins.concatStringsSep ", " (builtins.map builtins.toString unexpected)} unexpected; valid ones: ${builtins.concatStringsSep ", " (builtins.map builtins.toString valid)}";
|
||||
"${msg}: ${builtins.concatStringsSep ", " (map toString unexpected)} unexpected; valid ones: ${builtins.concatStringsSep ", " (map toString valid)}";
|
||||
|
||||
info = msg: builtins.trace "INFO: ${msg}";
|
||||
|
||||
@@ -1144,7 +1144,7 @@ in
|
||||
match = builtins.match "(0x)?([0-7]?[0-9A-Fa-f]{1,15})" str;
|
||||
in
|
||||
if match != null then
|
||||
(builtins.fromTOML "v=0x${builtins.elemAt match 1}").v
|
||||
(fromTOML "v=0x${builtins.elemAt match 1}").v
|
||||
else
|
||||
# TODO: Turn this into a `throw` in 26.05.
|
||||
assert lib.warn "fromHexString: ${
|
||||
@@ -1153,7 +1153,7 @@ in
|
||||
let
|
||||
noPrefix = lib.strings.removePrefix "0x" (lib.strings.toLower str);
|
||||
in
|
||||
(builtins.fromTOML "v=0x${noPrefix}").v;
|
||||
(fromTOML "v=0x${noPrefix}").v;
|
||||
|
||||
/**
|
||||
Convert the given positive integer to a string of its hexadecimal
|
||||
|
||||
@@ -1373,7 +1373,7 @@ let
|
||||
if builtins.isString v then
|
||||
''"${v}"''
|
||||
else if builtins.isInt v then
|
||||
builtins.toString v
|
||||
toString v
|
||||
else if builtins.isBool v then
|
||||
boolToString v
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user