Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Linux build on Darwin #641

Merged
merged 1 commit into from Mar 15, 2019

Conversation

basvandijk
Copy link
Member

This is a fix for https://discourse.nixos.org/t/why-do-darwin-build-derivations-end-up-on-a-nixos-system/2416/2.

Without this patch running the following on MacOS:

nix-build release.nix -A build.x86_64-linux

results in the following error during the configuration phase (note that Nix should be configured with a x86_64-linux build machine):

building '/nix/store/jb6ca1gmplyb69ayd43z7fb0y9npxd53-hydra-0.1.2581.8b5948f4cf12424c04df67a6eb136c9846fb2cfd.drv' on 'ssh://my-linux-build-machine'...
...
checking whether /nix/store/s6bhdppx66bkgf741vk4d29hgsj1h1zp-hydra-perl-deps/bin/nix-store is recent enough... ./configure: line 16254: /nix/store/s6bhdppx66bkgf741vk4d29hgsj1h1zp-hydra-perl-deps/bin/nix-store: cannot execute binary file: Exec format error
no
configure: error: `/nix/store/s6bhdppx66bkgf741vk4d29hgsj1h1zp-hydra-perl-deps/bin/nix-store' doesn't support `--timeout'; please use a newer version.
build time elapsed:  0m1.624s 0m1.774s 0m9.366s 0m6.110s
builder for '/nix/store/jb6ca1gmplyb69ayd43z7fb0y9npxd53-hydra-0.1.2581.8b5948f4cf12424c04df67a6eb136c9846fb2cfd.drv' failed with exit code 1

This problem is that the nix dependency of hydra is selected from a nixpkgs set configured with a default system parameter, i.e. builtin.currentSystem. This means that the hydra derivation which is
build for and on Linux depends on the nix derivation build for Darwin.

The fix is to select nix from the nixpkgs set configured with a system specified by the user.

Without this patch running the following on MacOS:

  nix-build release.nix -A build.x86_64-linux

results in the following error during the configuration phase (note that Nix
should be configured with a x86_64-linux build machine):

  building '/nix/store/jb6ca1gmplyb69ayd43z7fb0y9npxd53-hydra-0.1.2581.8b5948f4cf12424c04df67a6eb136c9846fb2cfd.drv' on 'ssh://my-linux-build-machine'...
  ...
  checking whether /nix/store/s6bhdppx66bkgf741vk4d29hgsj1h1zp-hydra-perl-deps/bin/nix-store is recent enough... ./configure: line 16254: /nix/store/s6bhdppx66bkgf741vk4d29hgsj1h1zp-hydra-perl-deps/bin/nix-store: cannot execute binary file: Exec format error
  no
  configure: error: `/nix/store/s6bhdppx66bkgf741vk4d29hgsj1h1zp-hydra-perl-deps/bin/nix-store' doesn't support `--timeout'; please use a newer version.
  build time elapsed:  0m1.624s 0m1.774s 0m9.366s 0m6.110s
  builder for '/nix/store/jb6ca1gmplyb69ayd43z7fb0y9npxd53-hydra-0.1.2581.8b5948f4cf12424c04df67a6eb136c9846fb2cfd.drv' failed with exit code 1

This problem is that the `nix` dependency of hydra is selected from a nixpkgs
set configured with a default `system` parameter,
i.e. `builtin.currentSystem`. This means that the hydra derivation which is
build for and on Linux depends on the nix derivation build for Darwin.

The fix is to select nix from the nixpkgs set configured with a system specified
by the user.
@nixos-discourse
Copy link

This pull request has been mentioned on Nix community. There might be relevant details there:

https://discourse.nixos.org/t/why-do-darwin-build-derivations-end-up-on-a-nixos-system/2416/3

@Ninlives
Copy link

Hi, could you please explain what happened here? I don't see what's the semantic difference between the expression before and after your commit :-( Thanks! 😺

@basvandijk
Copy link
Member Author

Note that in master we have nix defined as nix = pkgs.nixUnstable or pkgs.nix; where pkgs is coming from an outer scope and defined as pkgs = import nixpkgs {};. This means that nix will always be build for the default system which is defined as the current system (builtins.currentSystem). So if you want to build hydra for a Linux system but you execute the nix-build on MacOS your nix binaries will be build for MacOS and not for Linux.

My patch redefines pkgs as pkgs = import nixpkgs { inherit system; }; where system will be specified by the user. As in, If the users wants to build: nix-build release.nix -A build.x86_64-linux, system will be defined as "x86_64-linux".

@edolstra edolstra merged commit be27913 into NixOS:master Mar 15, 2019
@Ninlives
Copy link

Note that in master we have nix defined as nix = pkgs.nixUnstable or pkgs.nix; where pkgs is coming from an outer scope and defined as pkgs = import nixpkgs {};. This means that nix will always be build for the default system which is defined as the current system (builtins.currentSystem). So if you want to build hydra for a Linux system but you execute the nix-build on MacOS your nix binaries will be build for MacOS and not for Linux.

My patch redefines pkgs as pkgs = import nixpkgs { inherit system; }; where system will be specified by the user. As in, If the users wants to build: nix-build release.nix -A build.x86_64-linux, system will be defined as "x86_64-linux".

Ah, I get it, so here we override the whole pkgs. Thanks for your explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants