Build-time dependencies from string context?

So I wanted to submit a PR that removed the remarshal dependency from the iosevka package in the cases where remarshal did not get used.

What I tried to do was remove remarshal from nativeBuildInputs and instead refer to it only inside lib.optionalString, like this:

  nativeBuildInputs = [
    nodejs
    nodeIosevka
    ttfautohint-nox
    # remarshal
  ];

  configurePhase = ''
    runHook preConfigure

    # ${lib.optionalString (builtins.isAttrs privateBuildPlan) ''
    #   remarshal -i "$buildPlanPath" -o private-build-plans.toml -if json -of toml
    # ''}
    ${lib.optionalString (builtins.isAttrs privateBuildPlan) ''
      ${remarshal}/bin/remarshal -i "$buildPlanPath" -o private-build-plans.toml -if json -of toml
    ''}

    ...

    ln -s ${nodeIosevka}/lib/node_modules/iosevka/node_modules .
    runHook postConfigure
  '';

However, with this change then I went to see if this played nicely with cross compilation. And with a file iosevka-test.nix containing:

let
  pkgs = import ./. {
    crossSystem = {
      config = "aarch64-unknown-linux-gnu";
    };
  };
in pkgs.iosevka.override {
  set = "custom";
  privateBuildPlan = ''
    [buildPlans.iosevka-custom]
    family = "Iosevka"
  '';
}

the output of nix show-derivation "$(nix-instantiate ./iosevka-test.nix)" is

{
  "/nix/store/11nqq3kvn4rqf3nsdnaf3qfci4c8jiqf-iosevka-custom-5.0.2-aarch64-unknown-linux-gnu.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/kc6c45ca264wm4nnzxm2p3hiiw2cfzqw-iosevka-custom-5.0.2-aarch64-unknown-linux-gnu"
      }
    },
    "inputSrcs": [
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh",
      "/nix/store/r3macm5r48lnri9qb0dly590j9mrmix6-cross-file.conf"
    ],
    "inputDrvs": {
      "/nix/store/0ygh7j0g2dx9kphcd87ky0y0dqh9yqw0-iosevka-5.0.2.tar.gz.drv": [
        "out"
      ],
      "/nix/store/j0z97xpbh769z6kma2glxkgbc2qbb130-ttfautohint-1.8.3.drv": [
        "out"
      ],
      "/nix/store/j43d6yv93kq17vzhms8k0wffpdd11mns-stdenv-linux.drv": [
        "out"
      ],
      "/nix/store/m3glx30vnhwld01x74gh48blkp2h26jz-remarshal-0.14.0-aarch64-unknown-linux-gnu.drv": [
        "out"
      ],
      "/nix/store/n8dvdg4sq18yky8ibm4z2cl6ymkggypg-node_iosevka-5.0.2-aarch64-unknown-linux-gnu.drv": [
        "out"
      ],
      "/nix/store/q2fgazzfxhl26d1v7rixy43g3h7vbc3c-bash-4.4-p23.drv": [
        "out"
      ],
      "/nix/store/y6jwm0gzyjh36psml7y8s8lra5nbfhj0-nodejs-14.16.0.drv": [
        "out"
      ]
    },
    "system": "x86_64-linux",
    "builder": "/nix/store/p886sbvvzpqpxnb8a60djpp8dir9zfp9-bash-4.4-p23/bin/bash",
    "args": [
      "-e",
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "env": {
      "buildInputs": "",
      "buildPhase": "runHook preBuild\nnpm run build --no-update-notifier -- --jCmd=$NIX_BUILD_CORES ttf::$pname >/dev/null\nrunHook postBuild\n",
      "buildPlan": "[buildPlans.iosevka-custom]\nfamily = \"Iosevka\"\nspacing = \"fixed\"\nno-cv-ss = true\n\n[buildPlans.iosevka-custom.variants.design]\ng = \"double-storey-open\"\nasterisk = \"low\" # Renamed to penta-low in v6.0\nnumber-sign = \"upright-open\"\nat = \"short\"\n\n[buildPlans.iosevka-custom.weights.regular]\nshape = 400\nmenu = 400\ncss = 400\n[buildPlans.iosevka-custom.weights.bold]\nshape = 700\nmenu = 700\ncss = 700\n[buildPlans.iosevka-custom.slopes]\nupright = \"normal\"\nitalic = \"italic\"\n[buildPlans.iosevka-custom.widths.normal]\nshape = 500\nmenu = 5\ncss = \"normal\"\n",
      "builder": "/nix/store/p886sbvvzpqpxnb8a60djpp8dir9zfp9-bash-4.4-p23/bin/bash",
      "cmakeFlags": "-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_HOST_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_PROCESSOR=x86_64",
      "configureFlags": "--build=x86_64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu",
      "configurePhase": "runHook preConfigure\n/nix/store/xvhlxl1rgq4ibmwnk6d7510gviwg8w5z-remarshal-0.14.0-aarch64-unknown-linux-gnu/bin/remarshal -i \"$buildPlanPath\" -o private-build-plans.toml -if json -of toml\n\ncp \"$buildPlanPath\" private-build-plans.toml\n\n\nln -s /nix/store/7b9sw6nnrkl0xkbz4c8898dbakb577zs-node_iosevka-5.0.2-aarch64-unknown-linux-gnu/lib/node_modules/iosevka/node_modules .\nrunHook postConfigure\n",
      "depsBuildBuild": "",
      "depsBuildBuildPropagated": "",
      "depsBuildTarget": "",
      "depsBuildTargetPropagated": "",
      "depsHostHost": "",
      "depsHostHostPropagated": "",
      "depsTargetTarget": "",
      "depsTargetTargetPropagated": "",
      "doCheck": "",
      "doInstallCheck": "",
      "enableParallelBuilding": "1",
      "enableParallelChecking": "1",
      "installPhase": "runHook preInstall\nfontdir=\"$out/share/fonts/truetype\"\ninstall -d \"$fontdir\"\ninstall \"dist/$pname/ttf\"/* \"$fontdir\"\nrunHook postInstall\n",
      "mesonFlags": "--cross-file=/nix/store/r3macm5r48lnri9qb0dly590j9mrmix6-cross-file.conf",
      "name": "iosevka-custom-5.0.2-aarch64-unknown-linux-gnu",
      "nativeBuildInputs": "/nix/store/aiws68m5jpsgmql4bq55hxw23782yds7-nodejs-14.16.0 /nix/store/7b9sw6nnrkl0xkbz4c8898dbakb577zs-node_iosevka-5.0.2-aarch64-unknown-linux-gnu /nix/store/k8129847dwvm6pjm2nvaqcwswq2hvkhb-ttfautohint-1.8.3",
      "out": "/nix/store/kc6c45ca264wm4nnzxm2p3hiiw2cfzqw-iosevka-custom-5.0.2-aarch64-unknown-linux-gnu",
      "outputs": "out",
      "passAsFile": "buildPlan extraParameters",
      "patches": "",
      "pname": "iosevka-custom",
      "propagatedBuildInputs": "",
      "propagatedNativeBuildInputs": "",
      "src": "/nix/store/7a2njk5174j3237mpglkg576mqz5yfra-iosevka-5.0.2.tar.gz",
      "stdenv": "/nix/store/9k9zqvc9r51wr4qll2vyms7yc3487idc-stdenv-linux",
      "strictDeps": "1",
      "system": "x86_64-linux",
      "version": "5.0.2"
    }
  }
}

where we see that aarch64 versions of the remarshal and nodeIosevka packages are among the inputs. I have zero experience with Nix cross compilation, but this is wrong, right?, since the build output of the iosevka package is just a couple TTF font files, which will not need any run-time dependencies. (Though in this case it should not matter, since neither remarshal nor nodeIosevka compile to native code, right?)

So is there a way to fix this so that only native versions of build-time dependencies are used when derivation inputs are added from string contexts?

1 Like