Considering splicing in bscpkgs #15

Open
opened 2025-09-05 17:46:20 +02:00 by arocanon · 4 comments
Collaborator

nixpkgs callPackage uses splicing to compute from which deps<host><target> set it should pull packages for each kind of deps<host><target> dependency. If we fix inputs in callPackage, splicing does not work.

For example:

clangOmpss2Nodes = callPackage ./default.nix { openmp = final.openmpv; }

Fixes the openmp dependency. Instead, we should always pass all possible inputs and use booleans to select the right inputs:

{stdenv, lib, openmp, openmpv, nanos6, nosv, useOpenmp, useOpenmpV, useNanos6, useNodes}

I have made a simple reproducer here:

$ nix build git+https://gitlab.bsc.es/arocanon/sysdev.git?ref=repro-splicing#sp.test && cat ./result
This system triplet is:
  x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu, riscv64-unknown-linux-gnu

The dependencies in depsBuildTarget should be (x86, x86, rv64):
  x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu

Lets see which are the triples of a depsBuildTarget dependency in three
different derivations:

test1: package without callPackage: splicing does not work:
  x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu, riscv64-unknown-linux-gnu
test2: package with callPackage with fixed dependencies, splicing does not work:
  x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu, riscv64-unknown-linux-gnu
test3: package with callPackage without fixed dependencies, splicing works:
  x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu

I have fixed clang derivation (MR pending to be sent), but we might need to update other derivations that use fixed stdenvs.

nixpkgs callPackage uses splicing to compute from which `deps<host><target>` set it should pull packages for each kind of `deps<host><target>` dependency. If we fix inputs in callPackage, splicing does not work. For example: `clangOmpss2Nodes = callPackage ./default.nix { openmp = final.openmpv; }` Fixes the openmp dependency. Instead, we should always pass all possible inputs and use booleans to select the right inputs: `{stdenv, lib, openmp, openmpv, nanos6, nosv, useOpenmp, useOpenmpV, useNanos6, useNodes}` I have made a simple reproducer [here](https://gitlab.bsc.es/arocanon/sysdev/-/blob/repro-splicing/pkgs.nix#L31): ``` $ nix build git+https://gitlab.bsc.es/arocanon/sysdev.git?ref=repro-splicing#sp.test && cat ./result This system triplet is: x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu, riscv64-unknown-linux-gnu The dependencies in depsBuildTarget should be (x86, x86, rv64): x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu Lets see which are the triples of a depsBuildTarget dependency in three different derivations: test1: package without callPackage: splicing does not work: x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu, riscv64-unknown-linux-gnu test2: package with callPackage with fixed dependencies, splicing does not work: x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu, riscv64-unknown-linux-gnu test3: package with callPackage without fixed dependencies, splicing works: x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu, riscv64-unknown-linux-gnu ``` I have fixed clang derivation (MR pending to be sent), but we might need to update other derivations that use fixed stdenvs.
Owner

Thanks, I understand the problem, but not why is happening. Is this perhaps because the overrided argument loses the __spliced attribute, then is taken as is?

dfcd5b901d/pkgs/stdenv/generic/make-derivation.nix (L442)

(map (drv: getDev drv.__spliced.hostTarget or drv) (checkDependencyList "buildInputs" buildInputs'))

I don't think the use* attributes are enough, as sometimes we need to override some things of the inputs of a particular derivation. I would prefer to fix the callPackage + mkDerivation problem by using the spliced package as input instead (if possible).

Thanks, I understand the problem, but not why is happening. Is this perhaps because the overrided argument loses the `__spliced` attribute, then is taken as is? https://github.com/NixOS/nixpkgs/blob/dfcd5b901dbab46c9c6e80b265648481aafb01f8/pkgs/stdenv/generic/make-derivation.nix#L442 ```nix (map (drv: getDev drv.__spliced.hostTarget or drv) (checkDependencyList "buildInputs" buildInputs')) ``` I don't think the `use*` attributes are enough, as sometimes we need to override some things of the inputs of a particular derivation. I would prefer to fix the callPackage + mkDerivation problem by using the spliced package as input instead (if possible).
Owner

Seems like it may be it:

hop% git diff
diff --git a/pkgs/llvm-ompss2/default.nix b/pkgs/llvm-ompss2/default.nix
index 1b53de3..ffa27e0 100644
--- a/pkgs/llvm-ompss2/default.nix
+++ b/pkgs/llvm-ompss2/default.nix
@@ -17,6 +17,7 @@ let
 in

 assert assertMsg (usingNodesAndOmpv -> sameNosv) "OpenMP-V and NODES must share the same nOS-V";
+assert assertMsg (ompss2rt != null -> ompss2rt ? __spliced) "Missing __spliced argument in ompss2rt";

 let
   homevar = if ompss2rt.pname == "nanos6" then "NANOS6_HOME" else "NODES_HOME";

hop% nix eval '.#clangOmpss2.outPath'
warning: Git tree '/home/ram/bsc/bscpkgs' is dirty
"/nix/store/as322n04nh7ijvh20vgn5p8ff7w3x5d4-clang-ompss2-wrapper-2025.06"

hop% nix eval '.#clangOmpss2Nanos6.outPath'
warning: Git tree '/home/ram/bsc/bscpkgs' is dirty
error:
       … while calling a functor (an attribute set with a '__functor' attribute)
         at /nix/store/zk8v61cpk1wprp9ld5ayc1g5fq4pdkwv-source/lib/customisation.nix:306:7:
          305|     if missingArgs == { } then
          306|       makeOverridable f allArgs
             |       ^
          307|     # This needs to be an abort so it can't be caught with `builtins.tryEval`,

       … while evaluating a branch condition
         at /nix/store/zk8v61cpk1wprp9ld5ayc1g5fq4pdkwv-source/lib/customisation.nix:173:7:
          172|       in
          173|       if isAttrs result then
             |       ^
          174|         result

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: Missing __spliced argument in ompss2rt
Seems like it may be it: ``` hop% git diff diff --git a/pkgs/llvm-ompss2/default.nix b/pkgs/llvm-ompss2/default.nix index 1b53de3..ffa27e0 100644 --- a/pkgs/llvm-ompss2/default.nix +++ b/pkgs/llvm-ompss2/default.nix @@ -17,6 +17,7 @@ let in assert assertMsg (usingNodesAndOmpv -> sameNosv) "OpenMP-V and NODES must share the same nOS-V"; +assert assertMsg (ompss2rt != null -> ompss2rt ? __spliced) "Missing __spliced argument in ompss2rt"; let homevar = if ompss2rt.pname == "nanos6" then "NANOS6_HOME" else "NODES_HOME"; hop% nix eval '.#clangOmpss2.outPath' warning: Git tree '/home/ram/bsc/bscpkgs' is dirty "/nix/store/as322n04nh7ijvh20vgn5p8ff7w3x5d4-clang-ompss2-wrapper-2025.06" hop% nix eval '.#clangOmpss2Nanos6.outPath' warning: Git tree '/home/ram/bsc/bscpkgs' is dirty error: … while calling a functor (an attribute set with a '__functor' attribute) at /nix/store/zk8v61cpk1wprp9ld5ayc1g5fq4pdkwv-source/lib/customisation.nix:306:7: 305| if missingArgs == { } then 306| makeOverridable f allArgs | ^ 307| # This needs to be an abort so it can't be caught with `builtins.tryEval`, … while evaluating a branch condition at /nix/store/zk8v61cpk1wprp9ld5ayc1g5fq4pdkwv-source/lib/customisation.nix:173:7: 172| in 173| if isAttrs result then | ^ 174| result (stack trace truncated; use '--show-trace' to show the full, detailed trace) error: Missing __spliced argument in ompss2rt ```
Owner

Interestingly:

hop% git diff overlay.nix
diff --git a/overlay.nix b/overlay.nix
index 52b0d17..bd9cd18 100644
--- a/overlay.nix
+++ b/overlay.nix
@@ -13,7 +13,7 @@ let
     bench6 = callPackage ./pkgs/bench6/default.nix { };
     bigotes = callPackage ./pkgs/bigotes/default.nix { };
     clangOmpss2 = callPackage ./pkgs/llvm-ompss2/default.nix { };
-    clangOmpss2Nanos6 = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nanos6; };
+    clangOmpss2Nanos6 = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.__splicedPackages.nanos6; };
     clangOmpss2Nodes = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nodes; openmp = final.openmp; };
     clangOmpss2NodesOmpv = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nodes; openmp = final.openmpv; };
     clangOmpss2Unwrapped = callPackage ./pkgs/llvm-ompss2/clang.nix { };

hop% nix eval '.#pkgsCross.riscv64.clangOmpss2Nanos6.outPath'
warning: Git tree '/home/ram/bsc/bscpkgs' is dirty
"/nix/store/vmh9yy5pci5c8xfxndvqib80i8b6cacc-clang-ompss2-wrapper-2025.06"

Given that:

dfcd5b901d/pkgs/top-level/splice.nix (L14-L17)

# For performance reasons, rather than uniformally splice in all cases, we only
# do so when `pkgs` and `buildPackages` are distinct. The `actuallySplice`
# parameter there the boolean value of that equality check.
lib: pkgs: actuallySplice:

Coud this be happening because somehow the packages don't contain the __spliced attribute in your case?

I did a quick test with bench6 and ovni, as it is easier to handle than wrapCCWith, and it seems to at least contain it:

nix-repl> outputs.legacyPackages.x86_64-linux.pkgsCross.riscv64.bench6.theOvni.__spliced
{
  buildBuild = «derivation /nix/store/zm8g2n8liyxvd8a4zmi2w3fzlhks8b63-ovni-1.12.0.drv»;
  buildHost = «derivation /nix/store/38y69f3db50ib2gih9zzx1dhga9y5lj5-ovni-1.12.0.drv»;
  buildTarget = «repeated»;
  hostHost = «derivation /nix/store/sq6cj25kixsb8fm4q27v6h4xhar55nmn-ovni-riscv64-unknown-linux-gnu-1.12.0.drv»;
  hostTarget = «repeated»;
}

hop% git diff pkgs/bench6/
diff --git a/pkgs/bench6/default.nix b/pkgs/bench6/default.nix
index 0c7872c..03aff6e 100644
--- a/pkgs/bench6/default.nix
+++ b/pkgs/bench6/default.nix
@@ -21,6 +21,8 @@ stdenv.mkDerivation rec {
   pname = "bench6";
   version = "${src.shortRev}";

+  theOvni = ovni;
+
   src = builtins.fetchGit {
     url = gitURL;
     ref = gitBranch;
Interestingly: ``` hop% git diff overlay.nix diff --git a/overlay.nix b/overlay.nix index 52b0d17..bd9cd18 100644 --- a/overlay.nix +++ b/overlay.nix @@ -13,7 +13,7 @@ let bench6 = callPackage ./pkgs/bench6/default.nix { }; bigotes = callPackage ./pkgs/bigotes/default.nix { }; clangOmpss2 = callPackage ./pkgs/llvm-ompss2/default.nix { }; - clangOmpss2Nanos6 = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nanos6; }; + clangOmpss2Nanos6 = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.__splicedPackages.nanos6; }; clangOmpss2Nodes = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nodes; openmp = final.openmp; }; clangOmpss2NodesOmpv = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nodes; openmp = final.openmpv; }; clangOmpss2Unwrapped = callPackage ./pkgs/llvm-ompss2/clang.nix { }; hop% nix eval '.#pkgsCross.riscv64.clangOmpss2Nanos6.outPath' warning: Git tree '/home/ram/bsc/bscpkgs' is dirty "/nix/store/vmh9yy5pci5c8xfxndvqib80i8b6cacc-clang-ompss2-wrapper-2025.06" ``` Given that: https://github.com/NixOS/nixpkgs/blob/dfcd5b901dbab46c9c6e80b265648481aafb01f8/pkgs/top-level/splice.nix#L14-L17 ``` # For performance reasons, rather than uniformally splice in all cases, we only # do so when `pkgs` and `buildPackages` are distinct. The `actuallySplice` # parameter there the boolean value of that equality check. lib: pkgs: actuallySplice: ``` Coud this be happening because somehow the packages don't contain the `__spliced` attribute in your case? I did a quick test with bench6 and ovni, as it is easier to handle than wrapCCWith, and it seems to at least contain it: ``` nix-repl> outputs.legacyPackages.x86_64-linux.pkgsCross.riscv64.bench6.theOvni.__spliced { buildBuild = «derivation /nix/store/zm8g2n8liyxvd8a4zmi2w3fzlhks8b63-ovni-1.12.0.drv»; buildHost = «derivation /nix/store/38y69f3db50ib2gih9zzx1dhga9y5lj5-ovni-1.12.0.drv»; buildTarget = «repeated»; hostHost = «derivation /nix/store/sq6cj25kixsb8fm4q27v6h4xhar55nmn-ovni-riscv64-unknown-linux-gnu-1.12.0.drv»; hostTarget = «repeated»; } hop% git diff pkgs/bench6/ diff --git a/pkgs/bench6/default.nix b/pkgs/bench6/default.nix index 0c7872c..03aff6e 100644 --- a/pkgs/bench6/default.nix +++ b/pkgs/bench6/default.nix @@ -21,6 +21,8 @@ stdenv.mkDerivation rec { pname = "bench6"; version = "${src.shortRev}"; + theOvni = ovni; + src = builtins.fetchGit { url = gitURL; ref = gitBranch; ```
Owner

Fixed?

diff --git a/overlay.nix b/overlay.nix
index 52b0d17..2a57f62 100644
--- a/overlay.nix
+++ b/overlay.nix
@@ -1,10 +1,11 @@
-final: /* Future last stage */
+finalUnspliced: /* Future last stage */
 prev:  /* Previous stage */

-with final.lib;
+with finalUnspliced.lib;

 let
   callPackage = final.callPackage;
+  final = finalUnspliced.__splicedPackages or finalUnspliced;

   mkDeps = name: pkgs: final.runCommand name { }
     "printf '%s\n' ${toString (collect (x: x ? outPath) pkgs)} > $out";
Fixed? ```patch diff --git a/overlay.nix b/overlay.nix index 52b0d17..2a57f62 100644 --- a/overlay.nix +++ b/overlay.nix @@ -1,10 +1,11 @@ -final: /* Future last stage */ +finalUnspliced: /* Future last stage */ prev: /* Previous stage */ -with final.lib; +with finalUnspliced.lib; let callPackage = final.callPackage; + final = finalUnspliced.__splicedPackages or finalUnspliced; mkDeps = name: pkgs: final.runCommand name { } "printf '%s\n' ${toString (collect (x: x ? outPath) pkgs)} > $out"; ```
This repo is archived. You cannot comment on issues.
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rarias/bscpkgs#15
No description provided.