Skip to content

Commit

Permalink
WIP: Allow non-pkgs deps (needs test)
Browse files Browse the repository at this point in the history
Demo:

```diff
diff --git a/pkgs/by-name/he/hello/package.nix b/pkgs/by-name/he/hello/package.nix
index 0cf0ae493b72..69921e14ffc6 100644
--- a/pkgs/by-name/he/hello/package.nix
+++ b/pkgs/by-name/he/hello/package.nix
@@ -1,9 +1,13 @@
-{ mkPackageWithDeps, layers }: mkPackageWithDeps ({ stdenv, fetchurl, testers, lib, callPackage, nixos }: [
+{ mkPackageWithDeps, layers }: mkPackageWithDeps ({ stdenv, fetchurl, testers, lib, callPackage, nixos, haskellPackages, omnidoc }: [
   (layers.derivation { inherit stdenv; })
   (this: old: {
     name = "hello";
     version = "2.12.1";

+    deps = old.deps // {
+      omnidoc = haskellPackages.pandoc;
+    };
+
     setup = old.setup or {} // {
       src = fetchurl {
         url = "mirror://gnu/hello/hello-${this.version}.tar.gz";
@@ -24,6 +28,10 @@
       run = callPackage ./test.nix { hello = this.public; };
     };

+    public = old.public // {  # passthru, just to show that it works
+      inherit omnidoc;
+    };
+
     meta = with lib; {
       description = "A program that produces a familiar, friendly greeting";
       longDescription = ''
```
  • Loading branch information
roberth committed Jan 14, 2025
1 parent d690a22 commit 2aef03b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkgs/build-support/package/make-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,21 @@ let

layers.withDeps = f: this: old:
let
spy = lib.setFunctionArgs (args: { inherit args; }) (lib.functionArgs f);
fargs = lib.functionArgs f;
spy = lib.setFunctionArgs
(args: { inherit args; })
(lib.mapAttrs
(_k: _v:
# say we have a default, so that unknown attrs aren't a problem and
# they can be defined by a subsequent layer.
true)
fargs);
# TODO: make callPackage a parameter?
values = (callPackage spy { }).args;
old2 = old // {
deps = old.deps or {} // values;
};
r = f (lib.mapAttrs (name: value: this.deps.${name}) values);
r = f (lib.mapAttrs (name: value: this.deps.${name}) fargs);
r' = if lib.isList r then lib.composeManyExtensions r else r;
in
old2 //
Expand Down

0 comments on commit 2aef03b

Please sign in to comment.