Skip to content

nixos: Fix cross compilation of derivations defined in NixOS via pkgs#190358

Merged
Artturin merged 2 commits intoNixOS:masterfrom
ck3d:fix-nixos-cross
Sep 14, 2022
Merged

nixos: Fix cross compilation of derivations defined in NixOS via pkgs#190358
Artturin merged 2 commits intoNixOS:masterfrom
ck3d:fix-nixos-cross

Conversation

@ck3d
Copy link
Contributor

@ck3d ck3d commented Sep 8, 2022

Description of changes

Fixes #190289

Following example will fail without this patch:

(import ./nixos/lib/eval-config.nix {
  modules = [
    ({ pkgs, ... }: {
      config = {
        nixpkgs.crossSystem.system = "aarch64-linux";
        system.build = pkgs.runCommand "test"
          { nativeBuildInputs = [ pkgs.jq ]; } "jq > $out";
      };
    })
  ];
}).config.system.build
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Sep 8, 2022
@ck3d ck3d requested a review from Artturin September 8, 2022 16:40
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Sep 8, 2022
@ck3d ck3d requested a review from Ericson2314 September 9, 2022 05:21
@SuperSandro2000
Copy link
Member

Would this make changes like #190215 obsolete?

@ck3d
Copy link
Contributor Author

ck3d commented Sep 9, 2022

After this PR, you have to write it like:

pkgs.runCommand "validate-vector-conf" { nativeBuildInputs = [ pkgs.vector ]; } ''
  vector validate --no-environment "${file}"
  ln -s "${file}" "$out"
''

You do not need to add buildPackages, but you have to put vector into nativeBuildInputs.

@SuperSandro2000
Copy link
Member

You do not need to add buildPackages, but you have to put vector into nativeBuildInputs.

Would you be so kind to add a fix for this to this PR? Otherwise with my limited knowledge I think this sounds good.

@ck3d
Copy link
Contributor Author

ck3d commented Sep 11, 2022

Existing code will not break with this PR. Your PR is compatible with this PR. If you want, you can do a cleanup in one line
from

nativeBuildInputs = [ pkgs.buildPackages.vector ];

to

nativeBuildInputs = [ pkgs.vector ];

This PR allows you to write derivations as you do it for nixpkgs.

@Artturin
Copy link
Member

I didn't receive an answer from @Ericson2314 so lets try it

@Artturin Artturin merged commit dbc00be into NixOS:master Sep 14, 2022
@ck3d
Copy link
Contributor Author

ck3d commented Sep 14, 2022

Thanks! We will see if we face issues.

@ncfavier
Copy link
Member

ncfavier commented Jan 5, 2023

I'd like to understand this. @ck3d can you explain why __splicedPackages is needed?

@Artturin
Copy link
Member

Artturin commented Jan 5, 2023

I'd like to understand this. @ck3d can you explain why __splicedPackages is needed?

So that the packages will have a __spliced attrset which contains buildHost hostTarget etc which are then selected by mkDerivation

With callPackage the packages are gotten from the spliced set

@ncfavier
Copy link
Member

ncfavier commented Jan 5, 2023

Ah I see now, normally packages are obtained via callPackage ({ hello, ... }: ...) which takes care of the splicing.

Is there a reason that import nixpkgs { ... } does not return the spliced packages by default? Does this affect performance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NixOS: nativeBuildInputs do not work

4 participants