Non stop entertainment! The wackiest NixOS configuration to-date. thevoid.cafe/projects/puzzlevision
nixos flake flake-parts dotfiles home-manager nix
at develop 81 lines 2.1 kB view raw
1{ 2 lib, 3 self, 4 ... 5}: 6let 7 /* 8 Recursively find all .nix files in a directory tree. 9 10 This traverses a directory recursively and returns a flat list 11 of paths to every .nix file found. 12 13 Type: dirToModuleList :: Path -> [Path] 14 15 Example: 16 dirToModuleList ./modules/nixos 17 => [ 18 /path/to/modules/nixos/users/default.nix 19 /path/to/modules/nixos/networking/default.nix 20 ] 21 */ 22 dirToModuleList = 23 directory: 24 let 25 entries = builtins.readDir directory; 26 processEntry = 27 name: type: 28 if type == "directory" then 29 dirToModuleList "${directory}/${name}" 30 else if lib.hasSuffix ".nix" name then 31 [ "${directory}/${name}" ] 32 else 33 [ ]; 34 in 35 lib.flatten (lib.mapAttrsToList processEntry entries); 36 37 /* 38 Recursively import all .nix files from a directory into an attrset. 39 40 Traverses a directory tree, imports each .nix file with the provided 41 arguments, and merges all results into a single attribute set. 42 Subdirectories are recursively processed. 43 44 Type: dirToAttrset :: Path -> AttrSet -> AttrSet 45 46 Example: 47 Given directory structure: 48 lib/ 49 strings.nix -> { trim = s: ...; } 50 math.nix -> { add = a: b: ...; } 51 52 dirToAttrset ./lib { inherit lib; } 53 => { trim = ...; add = ...; } 54 55 Arguments: 56 directory: Path to scan for .nix files 57 importArgs: Attribute set to pass to each imported file 58 */ 59 dirToAttrset = 60 directory: importArgs: 61 let 62 entries = builtins.readDir directory; 63 processEntry = 64 name: type: 65 if type == "directory" then 66 dirToAttrset "${directory}/${name}" importArgs 67 else if lib.hasSuffix ".nix" name then 68 import "${directory}/${name}" importArgs 69 else 70 { }; 71 in 72 builtins.foldl' (acc: element: acc // element) { } (lib.mapAttrsToList processEntry entries); 73 74in 75{ 76 flake = { 77 lib = dirToAttrset ../../lib { inherit lib self; } // { 78 filesystem = { inherit dirToModuleList dirToAttrset; }; 79 }; 80 }; 81}