diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-08-17 00:55:32 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-09-01 15:46:04 +0200 |
commit | 465e05c0c5f63d48b3257b0a42e7739a235aa775 (patch) | |
tree | 367613b236fe223624ff239f779c2c3894d4767f /lib/fileset/mock-splitRoot.nix | |
parent | e6e55010858023a048cf36b4dd422a483878a581 (diff) | |
download | nixpkgs-465e05c0c5f63d48b3257b0a42e7739a235aa775.tar nixpkgs-465e05c0c5f63d48b3257b0a42e7739a235aa775.tar.gz nixpkgs-465e05c0c5f63d48b3257b0a42e7739a235aa775.tar.bz2 nixpkgs-465e05c0c5f63d48b3257b0a42e7739a235aa775.tar.lz nixpkgs-465e05c0c5f63d48b3257b0a42e7739a235aa775.tar.xz nixpkgs-465e05c0c5f63d48b3257b0a42e7739a235aa775.tar.zst nixpkgs-465e05c0c5f63d48b3257b0a42e7739a235aa775.zip |
lib.fileset.toSource: init
Diffstat (limited to 'lib/fileset/mock-splitRoot.nix')
-rw-r--r-- | lib/fileset/mock-splitRoot.nix | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/fileset/mock-splitRoot.nix b/lib/fileset/mock-splitRoot.nix new file mode 100644 index 00000000000..3c18ab1b1af --- /dev/null +++ b/lib/fileset/mock-splitRoot.nix @@ -0,0 +1,26 @@ +# This overlay implements mocking of the lib.path.splitRoot function +# It pretends that the last component named "mock-root" is the root: +# +# splitRoot /foo/mock-root/bar/mock-root/baz +# => { +# root = /foo/mock-root/bar/mock-root; +# subpath = "./baz"; +# } +self: super: { + path = super.path // { + splitRoot = path: + let + parts = super.path.splitRoot path; + components = self.path.subpath.components parts.subpath; + count = self.length components; + rootIndex = count - self.lists.findFirstIndex + (component: component == "mock-root") + (self.length components) + (self.reverseList components); + root = self.path.append parts.root (self.path.subpath.join (self.take rootIndex components)); + subpath = self.path.subpath.join (self.drop rootIndex components); + in { + inherit root subpath; + }; + }; +} |