diff options
| author | Kleidi Bujari <mail@4kb.net> | 2026-10-24 22:52:35 -0700 |
|---|---|---|
| committer | Kleidi Bujari <mail@4kb.net> | 2026-10-24 22:59:09 -0700 |
| commit | 48c8a4145c5a73874797a6de3f05ce584b1d1798 (patch) | |
| tree | bd4c627e8c8944fb7082b7a9982e8d3677c2a2c4 /lib | |
| parent | 1a181be93f37a94b347b2f5f97a1fef57e11cf89 (diff) | |
| parent | 27db59cac4f3c3e7a1e4187a5f56d4ec61895c5a (diff) | |
| download | depot-48c8a4145c5a73874797a6de3f05ce584b1d1798.tar.gz depot-48c8a4145c5a73874797a6de3f05ce584b1d1798.tar.bz2 depot-48c8a4145c5a73874797a6de3f05ce584b1d1798.zip | |
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/depot-tools.nix | 68 | ||||
| -rw-r--r-- | lib/importDir.nix | 44 |
2 files changed, 81 insertions, 31 deletions
diff --git a/lib/depot-tools.nix b/lib/depot-tools.nix index 7c2fc6b..8e5a16e 100644 --- a/lib/depot-tools.nix +++ b/lib/depot-tools.nix @@ -1,7 +1,8 @@ -{ inputs -, systems -, nixpkgs ? inputs.nixpkgs -, ... +{ + inputs, + systems, + nixpkgs ? inputs.nixpkgs, + ... }: let @@ -27,30 +28,25 @@ let # Get paths to directories onlyDirs = filterAttrs (_name: type: type == "directory") entries; - dirPaths = mapAttrs - (name: type: { - path = path + "/${name}"; - inherit type; - }) - onlyDirs; + dirPaths = mapAttrs (name: type: { + path = path + "/${name}"; + inherit type; + }) onlyDirs; # Get paths to nix files, where the name is the basename of the file without the .nix extension - nixPaths = removeAttrs - (mapAttrs' - ( - name: type: - let - nixName = match "(.*)\\.nix" name; - in - { - name = if type == "directory" || nixName == null then "__junk" else (head nixName); - value = { - path = path + "/${name}"; - type = type; - }; - } - ) - entries) [ "__junk" ]; + nixPaths = removeAttrs (mapAttrs' ( + name: type: + let + nixName = match "(.*)\\.nix" name; + in + { + name = if type == "directory" || nixName == null then "__junk" else (head nixName); + value = { + path = path + "/${name}"; + type = type; + }; + } + ) entries) [ "__junk" ]; combined = dirPaths // nixPaths; in @@ -61,9 +57,9 @@ let system: let # Resolve the packages for each input. - perSystem = mapAttrs - (_: flake: flake.legacyPackages.${system} or { } // flake.packages.${system} or { }) - inputs; + perSystem = mapAttrs ( + _: flake: flake.legacyPackages.${system} or { } // flake.packages.${system} or { } + ) inputs; # Handle nixpkgs specially. pkgs = @@ -78,7 +74,17 @@ let flake = inputs.self; in - makeScope callPackageWith (_: { inherit inputs perSystem flake pkgs system; }) + makeScope callPackageWith (_: { + inherit + inputs + perSystem + flake + pkgs + system + ; + }) ); in -{ inherit importDir systemArgs; } +{ + inherit importDir systemArgs; +} diff --git a/lib/importDir.nix b/lib/importDir.nix new file mode 100644 index 0000000..794d3e7 --- /dev/null +++ b/lib/importDir.nix @@ -0,0 +1,44 @@ +{ lib, ... }: +let + inherit (builtins) + head + mapAttrs + match + readDir + ; + + inherit (lib) + mapAttrs' + filterAttrs + ; +in + +path: fn: +let + entries = readDir path; + + # Get paths to directories + onlyDirs = filterAttrs (_name: type: type == "directory") entries; + dirPaths = mapAttrs (name: type: { + path = path + "/${name}"; + inherit type; + }) onlyDirs; + + # Get paths to nix files, where the name is the basename of the file without the .nix extension + nixPaths = removeAttrs (mapAttrs' ( + name: type: + let + nixName = match "(.*)\\.nix" name; + in + { + name = if type == "directory" || nixName == null then "__junk" else (head nixName); + value = { + path = path + "/${name}"; + type = type; + }; + } + ) entries) [ "__junk" ]; + + combined = dirPaths // nixPaths; +in +fn combined |
