summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKleidi Bujari <mail@4kb.net>2025-04-02 22:11:38 -0400
committerKleidi Bujari <mail@4kb.net>2025-04-02 22:11:38 -0400
commitc950f338c5720a132552863a35d1c7924df3d3a6 (patch)
treec3134c42e1618c255ca8e9e0698f90b0ae8b3563 /lib
parentb619ff9dd42eaa62569c8297142f0e4c719d40d2 (diff)
parent09c2b6de63a6ff35348fcb2c2eb57b974f0a8a52 (diff)
downloaddepot-c950f338c5720a132552863a35d1c7924df3d3a6.tar.gz
depot-c950f338c5720a132552863a35d1c7924df3d3a6.tar.bz2
depot-c950f338c5720a132552863a35d1c7924df3d3a6.zip
Merge remote-tracking branch 'origin/copy-blueprint'
Diffstat (limited to 'lib')
-rw-r--r--lib/depot-tools.nix84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/depot-tools.nix b/lib/depot-tools.nix
new file mode 100644
index 0000000..448055a
--- /dev/null
+++ b/lib/depot-tools.nix
@@ -0,0 +1,84 @@
+{ inputs
+, systems
+, nixpkgs ? inputs.nixpkgs
+, ...
+}:
+
+let
+ inherit (builtins)
+ match
+ head
+ readDir
+ ;
+
+ inherit (nixpkgs.lib)
+ callPackageWith
+ filterAttrs
+ genAttrs
+ makeScope
+ mapAttrs
+ mapAttrs'
+ ;
+
+ importDir =
+ path:
+ 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" ];
+ in
+ dirPaths // nixPaths;
+
+ # Memoize the args per system
+ systemArgs = genAttrs systems (
+ system:
+ let
+ # Resolve the packages for each input.
+ perSystem = mapAttrs
+ (_: flake: flake.legacyPackages.${system} or { } // flake.packages.${system} or { })
+ inputs;
+
+ # Handle nixpkgs specially.
+ pkgs =
+ if (nixpkgs.config or { }) == { } && (nixpkgs.overlays or [ ]) == [ ] then
+ perSystem.nixpkgs
+ else
+ import inputs.nixpkgs {
+ inherit system;
+ config = nixpkgs.config or { };
+ overlays = nixpkgs.overlays or [ ];
+ };
+
+ flake = inputs.self;
+ in
+ makeScope callPackageWith (_: { inherit inputs perSystem flake pkgs system; })
+ );
+
+ eachSystem = f: genAttrs systems (system: f systemArgs.${system});
+in
+{ inherit importDir systemArgs eachSystem; }