From 162045b8d7d618e4b7525df704842d9ccd7e4d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alper=20=C3=87elik?= Date: Mon, 6 Mar 2023 01:40:35 +0300 Subject: [PATCH] default: add unit packages (#26) --- callUnitRoot.nix | 10 ++++++++++ default.nix | 4 ++-- flake.nix | 14 +------------- 3 files changed, 13 insertions(+), 15 deletions(-) create mode 100644 callUnitRoot.nix diff --git a/callUnitRoot.nix b/callUnitRoot.nix new file mode 100644 index 0000000..5490d15 --- /dev/null +++ b/callUnitRoot.nix @@ -0,0 +1,10 @@ +{ pkgs, lib ? pkgs.lib, unitDir ? "unit", packageFun ? "package.nix", root ? "${./pkgs}/${unitDir}" }: +let + shards = lib.attrNames (builtins.readDir root); + namesForShard = shard: lib.mapAttrs' + (name: _: { inherit name; value = "${root}/${shard}/${name}"; }) + (builtins.readDir "${root}/${shard}"); + namesToPath = lib.foldl' lib.recursiveUpdate { } (map namesForShard shards); + units = lib.mapAttrs (_: path: pkgs.callPackage "${path}/${packageFun}" { }) namesToPath; +in +units diff --git a/default.nix b/default.nix index ef496d5..42a0f68 100644 --- a/default.nix +++ b/default.nix @@ -9,9 +9,9 @@ { pkgs ? import { } }: import ./pkgs/top-level/all-packages.nix { inherit pkgs; } - // { +// { # The `lib`, `modules`, and `overlay` names are special lib = import ./lib { inherit pkgs; }; # functions modules = import ./modules; # NixOS modules overlays = import ./overlays; # nixpkgs overlays -} +} // import ./callUnitRoot.nix { inherit pkgs; } diff --git a/flake.nix b/flake.nix index a21531a..71090fc 100644 --- a/flake.nix +++ b/flake.nix @@ -20,23 +20,11 @@ # Unstable names are variables. packages = let - unitDir = "unit"; - packageFun = "package.nix"; - callUnitRoot = root: - let - shards = lib.attrNames (builtins.readDir root); - namesForShard = shard: lib.mapAttrs' - (name: _: { inherit name; value = "${root}/${shard}/${name}"; }) - (builtins.readDir "${root}/${shard}"); - namesToPath = lib.foldl' lib.recursiveUpdate { } (map namesForShard shards); - units = lib.mapAttrs (_: path: pkgs.callPackage "${path}/${packageFun}" { }) namesToPath; - in - units; legacyPackages = import ./pkgs/top-level/all-packages.nix { inherit pkgs; }; onlyAvailable = lib.filterAttrs (_: drv: builtins.elem system (drv.meta.platforms or [ ])); in - onlyAvailable (legacyPackages // callUnitRoot "${./pkgs}/${unitDir}"); + onlyAvailable (legacyPackages // import ./callUnitRoot.nix { inherit pkgs; }); checks = { nixpkgs-fmt = pkgs.writeShellScriptBin "nixpkgs-fmt-check" ''