at 23.11-beta 901 B view raw
1# This overlay implements mocking of the lib.path.splitRoot function 2# It pretends that the last component named "mock-root" is the root: 3# 4# splitRoot /foo/mock-root/bar/mock-root/baz 5# => { 6# root = /foo/mock-root/bar/mock-root; 7# subpath = "./baz"; 8# } 9self: super: { 10 path = super.path // { 11 splitRoot = path: 12 let 13 parts = super.path.splitRoot path; 14 components = self.path.subpath.components parts.subpath; 15 count = self.length components; 16 rootIndex = count - self.lists.findFirstIndex 17 (component: component == "mock-root") 18 (self.length components) 19 (self.reverseList components); 20 root = self.path.append parts.root (self.path.subpath.join (self.take rootIndex components)); 21 subpath = self.path.subpath.join (self.drop rootIndex components); 22 in { 23 inherit root subpath; 24 }; 25 }; 26}