mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 04:35:41 +03:00
lib.fileset: Various updates relating to union/unions
Also some minor formatting improvements
This commit is contained in:
parent
f78d65067f
commit
c5ae093f13
4 changed files with 54 additions and 19 deletions
|
@ -9,7 +9,7 @@ File sets are easy and safe to use, providing obvious and composable semantics w
|
||||||
These sections apply to the entire library.
|
These sections apply to the entire library.
|
||||||
See the [function reference](#sec-functions-library-fileset) for function-specific documentation.
|
See the [function reference](#sec-functions-library-fileset) for function-specific documentation.
|
||||||
|
|
||||||
The file set library is currently very limited but is being expanded to include more functions over time.
|
The file set library is currently somewhat limited but is being expanded to include more functions over time.
|
||||||
|
|
||||||
## Implicit coercion from paths to file sets {#sec-fileset-path-coercion}
|
## Implicit coercion from paths to file sets {#sec-fileset-path-coercion}
|
||||||
|
|
||||||
|
|
|
@ -177,15 +177,9 @@ Arguments:
|
||||||
## To update in the future
|
## To update in the future
|
||||||
|
|
||||||
Here's a list of places in the library that need to be updated in the future:
|
Here's a list of places in the library that need to be updated in the future:
|
||||||
- > The file set library is currently very limited but is being expanded to include more functions over time.
|
- > The file set library is currently somewhat limited but is being expanded to include more functions over time.
|
||||||
|
|
||||||
in [the manual](../../doc/functions/fileset.section.md)
|
in [the manual](../../doc/functions/fileset.section.md)
|
||||||
- > Currently the only way to construct file sets is using implicit coercion from paths.
|
|
||||||
|
|
||||||
in [the `toSource` reference](./default.nix)
|
|
||||||
- > For now filesets are always paths
|
|
||||||
|
|
||||||
in [the `toSource` implementation](./default.nix), also update the variable name there
|
|
||||||
- Once a tracing function exists, `__noEval` in [internal.nix](./internal.nix) should mention it
|
- Once a tracing function exists, `__noEval` in [internal.nix](./internal.nix) should mention it
|
||||||
- If/Once a function to convert `lib.sources` values into file sets exists, the `_coerce` and `toSource` functions should be updated to mention that function in the error when such a value is passed
|
- If/Once a function to convert `lib.sources` values into file sets exists, the `_coerce` and `toSource` functions should be updated to mention that function in the error when such a value is passed
|
||||||
- If/Once a function exists that can optionally include a path depending on whether it exists, the error message for the path not existing in `_coerce` should mention the new function
|
- If/Once a function exists that can optionally include a path depending on whether it exists, the error message for the path not existing in `_coerce` should mention the new function
|
||||||
|
|
|
@ -58,16 +58,51 @@ in {
|
||||||
} -> SourceLike
|
} -> SourceLike
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
# Import the current directory into the store but only include files under ./src
|
# Import the current directory into the store
|
||||||
toSource { root = ./.; fileset = ./src; }
|
# but only include files under ./src
|
||||||
|
toSource {
|
||||||
|
root = ./.;
|
||||||
|
fileset = ./src;
|
||||||
|
}
|
||||||
=> "/nix/store/...-source"
|
=> "/nix/store/...-source"
|
||||||
|
|
||||||
# The file set coerced from path ./bar could contain files outside the root ./foo, which is not allowed
|
# Import the current directory into the store
|
||||||
toSource { root = ./foo; fileset = ./bar; }
|
# but only include ./Makefile and all files under ./src
|
||||||
|
toSource {
|
||||||
|
root = ./.;
|
||||||
|
fileset = union
|
||||||
|
./Makefile
|
||||||
|
./src;
|
||||||
|
}
|
||||||
|
=> "/nix/store/...-source"
|
||||||
|
|
||||||
|
# Trying to include a file outside the root will fail
|
||||||
|
toSource {
|
||||||
|
root = ./.;
|
||||||
|
fileset = unions [
|
||||||
|
./Makefile
|
||||||
|
./src
|
||||||
|
../LICENSE
|
||||||
|
];
|
||||||
|
}
|
||||||
=> <error>
|
=> <error>
|
||||||
|
|
||||||
|
# The root needs to point to a directory that contains all the files
|
||||||
|
toSource {
|
||||||
|
root = ../.;
|
||||||
|
fileset = unions [
|
||||||
|
./Makefile
|
||||||
|
./src
|
||||||
|
../LICENSE
|
||||||
|
];
|
||||||
|
}
|
||||||
|
=> "/nix/store/...-source"
|
||||||
|
|
||||||
# The root has to be a local filesystem path
|
# The root has to be a local filesystem path
|
||||||
toSource { root = "/nix/store/...-source"; fileset = ./.; }
|
toSource {
|
||||||
|
root = "/nix/store/...-source";
|
||||||
|
fileset = ./.;
|
||||||
|
}
|
||||||
=> <error>
|
=> <error>
|
||||||
*/
|
*/
|
||||||
toSource = {
|
toSource = {
|
||||||
|
@ -85,18 +120,24 @@ The only way to change which files get added to the store is by changing the `fi
|
||||||
root,
|
root,
|
||||||
/*
|
/*
|
||||||
(required) The file set whose files to import into the store.
|
(required) The file set whose files to import into the store.
|
||||||
Currently the only way to construct file sets is using [implicit coercion from paths](#sec-fileset-path-coercion).
|
File sets can be created using other functions in this library.
|
||||||
If a directory does not recursively contain any file, it is omitted from the store path contents.
|
This argument can also be a path,
|
||||||
|
which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
|
||||||
|
|
||||||
|
<!-- Ignore the indentation here, this is a nixdoc rendering bug that needs to be fixed -->
|
||||||
|
:::{.note}
|
||||||
|
If a directory does not recursively contain any file, it is omitted from the store path contents.
|
||||||
|
:::
|
||||||
|
|
||||||
*/
|
*/
|
||||||
fileset,
|
fileset,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
# We cannot rename matched attribute arguments, so let's work around it with an extra `let in` statement
|
# We cannot rename matched attribute arguments, so let's work around it with an extra `let in` statement
|
||||||
# For now filesets are always paths
|
maybeFileset = fileset;
|
||||||
filesetPath = fileset;
|
|
||||||
in
|
in
|
||||||
let
|
let
|
||||||
fileset = _coerce "lib.fileset.toSource: `fileset`" filesetPath;
|
fileset = _coerce "lib.fileset.toSource: `fileset`" maybeFileset;
|
||||||
rootFilesystemRoot = (splitRoot root).root;
|
rootFilesystemRoot = (splitRoot root).root;
|
||||||
filesetFilesystemRoot = (splitRoot fileset._internalBase).root;
|
filesetFilesystemRoot = (splitRoot fileset._internalBase).root;
|
||||||
filter = _toSourceFilter fileset;
|
filter = _toSourceFilter fileset;
|
||||||
|
|
|
@ -265,7 +265,7 @@ expectFailure 'toSource { root = ./.; fileset = "/some/path"; }' 'lib.fileset.to
|
||||||
expectFailure 'toSource { root = ./.; fileset = ./a; }' 'lib.fileset.toSource: `fileset` '"$work"'/a does not exist.'
|
expectFailure 'toSource { root = ./.; fileset = ./a; }' 'lib.fileset.toSource: `fileset` '"$work"'/a does not exist.'
|
||||||
|
|
||||||
# File sets cannot be evaluated directly
|
# File sets cannot be evaluated directly
|
||||||
expectFailure '_create ./. null' 'lib.fileset: Directly evaluating a file set is not supported. Use `lib.fileset.toSource` to turn it into a usable source instead.'
|
expectFailure 'union ./. ./.' 'lib.fileset: Directly evaluating a file set is not supported. Use `lib.fileset.toSource` to turn it into a usable source instead.'
|
||||||
|
|
||||||
# Past versions of the internal representation are supported
|
# Past versions of the internal representation are supported
|
||||||
expectEqual '_coerce "<tests>: value" { _type = "fileset"; _internalVersion = 0; _internalBase = ./.; }' \
|
expectEqual '_coerce "<tests>: value" { _type = "fileset"; _internalVersion = 0; _internalBase = ./.; }' \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue