99 inherit ( inputs ) nixpkgs ;
1010in
1111nixpkgs . lib . extend (
12- lib : _ :
13- # some utils for importing trees
14- rec {
12+ lib : _ : {
1513 /*
1614 *
1715 Filters Nix packages based on the target system platform.
@@ -38,6 +36,7 @@ nixpkgs.lib.extend (
3836 - [system] Target system platform (e.g., "x86_64-linux").
3937 - [pkgsSet] a set of Nix packages.
4038 */
39+ # TODO should this be replaced with flake-parts pkgs-by-name
4140 platformPkgs =
4241 system :
4342 lib . filterAttrs (
@@ -54,113 +53,5 @@ nixpkgs.lib.extend (
5453 in
5554 lib . elem system platforms
5655 ) ;
57-
58- /*
59- *
60- Flattens a _tree_ of the shape that is produced by rakeLeaves.
61- An attrset with names in the spirit of the Reverse DNS Notation form
62- that fully preserve information about grouping from nesting.
63-
64- # Example
65-
66- ```
67- flattenTree {
68- a = {
69- b = {
70- c = <path>;
71- };
72- };
73- }
74- => { "a.b.c" = <path>; }
75- ```
76- */
77- flattenTree =
78- tree :
79- let
80- op =
81- sum : path : val :
82- let
83- pathStr = builtins . concatStringsSep "." path ; # dot-based reverse DNS notation
84- in
85- if builtins . isPath val then
86- # builtins.trace "${toString val} is a path"
87- ( sum // { "${ pathStr } " = val ; } )
88- else if builtins . isAttrs val then
89- # builtins.trace "${builtins.toJSON val} is an attrset"
90- # recurse into that attribute set
91- ( recurse sum path val )
92- else
93- # ignore that value
94- # builtins.trace "${toString path} is something else"
95- sum ;
96-
97- recurse =
98- sum : path : val :
99- builtins . foldl' ( sum : key : op sum ( path ++ [ key ] ) val . ${ key } ) sum ( builtins . attrNames val ) ;
100- in
101- recurse { } [ ] tree ;
102-
103- /*
104- *
105- Recursively collect the nix files of _path_ into attrs.
106- Return an attribute set where all `.nix` files and directories with `default.nix` in them
107- are mapped to keys that are either the file with .nix stripped or the folder name.
108- All other directories are recursed further into nested attribute sets with the same format.
109-
110- # Example
111-
112- Example file structure:
113-
114- ```
115- ./core/default.nix
116- ./base.nix
117- ./main/dev.nix
118- ./main/os/default.nix
119- ```
120-
121- ```nix
122- rakeLeaves .
123- => {
124- core = ./core;
125- base = base.nix;
126- main = {
127- dev = ./main/dev.nix;
128- os = ./main/os;
129- };
130- }
131- ```
132- */
133-
134- rakeLeaves =
135- dirPath :
136- let
137- seive =
138- file : type :
139- # Only rake `.nix` files or directories
140- ( type == "regular" && lib . hasSuffix ".nix" file ) || ( type == "directory" ) ;
141-
142- collect = file : type : {
143- name = lib . removeSuffix ".nix" file ;
144- value =
145- let
146- path = dirPath + "/${ file } " ;
147- in
148- if ( type == "regular" ) || ( type == "directory" && builtins . pathExists ( path + "/default.nix" ) ) then
149- path
150- # recurse on directories that don't contain a `default.nix`
151- else
152- rakeLeaves path ;
153- } ;
154-
155- files = lib . filterAttrs seive ( builtins . readDir dirPath ) ;
156- in
157- lib . filterAttrs ( _n : v : v != { } ) ( lib . mapAttrs' collect files ) ;
158-
159- importLeaves =
160- #
161- # Create an import stanza by recursing a directory to find all default.nix and <file.nix>
162- # files beneath withough manually having to list all the subsequent files.
163- #
164- path : builtins . attrValues ( lib . mapAttrs ( _ : import ) ( rakeLeaves path ) ) ;
16556 }
16657)
0 commit comments