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

Cross-compiled NixOS #36187

Merged
merged 36 commits into from
Mar 2, 2018
Merged

Cross-compiled NixOS #36187

merged 36 commits into from
Mar 2, 2018

Conversation

shlevy
Copy link
Member

@shlevy shlevy commented Mar 1, 2018

This includes a slew of fixes to get NixOS cross-compiling. Highlights:

  1. Cross-building systemd
  2. Cross-building perl modules (306d5cd)
  3. Cross-compile safe ldd (897b7c7)
  4. pkgs.runtimeShell (e70f61f) and fixing NixOS scripts to use it (fec5434)
  5. The top-level switch to turn it on (3448794)

2018-03-01-134030_838x64_scrot

No need to cross-compile pure data...
This involved:

* Installing miniperl as $dev/bin/perl
* Setting miniperl to take INC from
  lib/perl5/{site_perl/,}cross_perl/${version} as well as
  lib/perl5/{site_perl/,}/${version}/${runtimeArch}, in that
  order. miniperl taking from runtimeArch is not really correct, but
  it works in some pure-perl cases (e.g. Config.pm) and can be
  overridden with the cross_perl variant.
* Installing perl-cross's stubs into
  $dev/lib/perl5/cross_perl/${version}
* Patching MakeMaker.pm to gracefully degrade (very slightly) if B.pm
  can't be loaded, which it can't in cross-compilation.
* Passing the right build-time and runtime perls to Makefile.PL
Also disable it when noXlibs in NixOS.
This is like stdenv.shell{,Package}, but for the runtime system. The
majority of uses of stdenv.shell probably want this instead.
@GrahamcOfBorg GrahamcOfBorg added 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 501+ 10.rebuild-linux: 501+ labels Mar 1, 2018
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did something between a read and skim, and it looks all good so far!

@@ -130,6 +130,18 @@ in
'';
};

crossSystem = mkOption {
type = types.nullOr types.attrs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't let me forget about this when I return to #34444

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a similar value for localSystem? O:).

Copy link
Member

@Ericson2314 Ericson2314 Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if system before is new in 18.03, it should be changed to local system instead. And the description of that config should in that case take into account crossSystem: "for which NixOS should be built" isn't generally true, should be "on which".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to do this in a follow-up PR though.

@thoughtpolice
Copy link
Member

FWIW I just took a quick look at this as well and it's all pretty rote stuff, so I'm 👍 as well and excited to see these pieces making it in!

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK reviewed all the nix stuff more thoroughly (didn't dive into every longer bash blob.)

@@ -24,6 +27,10 @@ stdenv.mkDerivation rec {

STD_CDEFINES = [ "-DDIG_SIGCHASE=1" ]; # support +sigchase

BUILD_CC = "cc";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also surprises me, I think the setup hook should also do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, will try again without these a bit later

@@ -13,6 +14,8 @@ stdenv.mkDerivation rec {
sha256 = "10iwkghl5g50b7wc17bsb9wa0dh2gd57bjlk6ynixhywz6dhx1r9";
};

preConfigure = "export AR=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}ar";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about? Is the setup hook not working?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permalink for posterity:

for cmd in \
ar as ld nm objcopy objdump readelf ranlib strip strings size windres
do
if
PATH=$_PATH type -p "@targetPrefix@${cmd}" > /dev/null
then
upper_case="$(echo "$cmd" | tr "[:lower:]" "[:upper:]")"
export "${role_pre}${upper_case}=@targetPrefix@${cmd}";
export "${upper_case}${role_post}=@targetPrefix@${cmd}";
fi
done

(Sorry for the necro)

@@ -25,6 +25,10 @@ stdenv.mkDerivation rec {
# Check that the udev plugin got built.
postInstall = stdenv.lib.optional (udev != null) "[ -e $out/lib/dhcpcd/dev/udev.so ]";

postFixup = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add TODO for fixed patched shebangs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@shlevy
Copy link
Member Author

shlevy commented Mar 1, 2018

@Ericson2314 Fixed


add_needed $1

while [ ''${#left[@]} -ne 0 ]; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sometimes like while (( ''${#left[@]} )); do

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total approval now (don't really care about my one bash nit). Thanks again for doing this! Really nice whenever I see my cross work so bearing fruit.

@shlevy shlevy merged commit 60c8c02 into NixOS:staging Mar 2, 2018
@shlevy shlevy deleted the cross-nixos branch March 2, 2018 00:31
@bgamari
Copy link
Contributor

bgamari commented Mar 2, 2018

Wow, great work!

@bjornfor
Copy link
Contributor

bjornfor commented Mar 2, 2018

@shlevy: Can you show the Nix expression(s) you used to build the system in the screenshot?

@shlevy
Copy link
Member Author

shlevy commented Mar 2, 2018

@bjornfor still have quite a bit of cleanup to do before "official" announcement, but https://github.com/shlevy/nixos-riscv-bootstrap/tree/589d1b3bb10909a268ada5d3542dbc844d086a92 (note that that repo has very little risc-v specific in it now and will be made more generic)

@bjornfor
Copy link
Contributor

bjornfor commented Mar 2, 2018

Thanks!

@@ -139,7 +139,7 @@ let

manual-combined = runCommand "nixos-manual-combined"
{ inherit sources;
buildInputs = [ libxml2 libxslt ];
nativeBuildInputs = [ buildPackages.libxml2 buildPackages.libxslt ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need both nativeBuildInputs and buildPackages? Isn`t

      nativeBuildInputs = [ libxml2 libxslt ];

enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dezgeg No, because the magic autoresolution for nativeBuildInputs essentially relies on being inside of a callPackaged function (this is an oversimplification, but I don't think it's misleading in this context. @Ericson2314 ?). Because we simply have a top-level with pkgs in this file, we don't get that benefit.

Note that we are working toward infrastructure that doesn't rely on the "splicing" hack that causes this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's all correct.

@oxij
Copy link
Member

oxij commented Sep 4, 2018 via email

@Ericson2314
Copy link
Member

@oxij stdenv.shell is the shell used at build time. That need not be the same as the shell used by the newly-built NixOS, and indeed must not be for cross-compiled NixOS.

@oxij
Copy link
Member

oxij commented Sep 4, 2018 via email

@Ericson2314
Copy link
Member

stdenv is not like the other packages.

  • buildPackages.stdenv.cc is usually buildPackages.buildPackages.gcc
  • buildPackages.stdenv.shell is usually buildPackages.buildPackages.bash
  • stdenv.cc is usually buildPackages.cc
  • stdenv.shell is usually buildPackages.bash
  • targetPackages.stdenv.cc is usually gcc
  • targetPackages.stdenv.shell is usually bash

But referring the successive (rather than previous) stages as in targetPackages.stdenv.shell is rarely a good idea. The simplest reason is that many stages could be bootstrapped from the same previous stage in principle, so there ought not to be a canonical next stage.

@Ericson2314
Copy link
Member

Also the notion of a "run-time shell" is arguably more of a NixOS one and nixpkgs one. You can see the only use in pkgs is to get around a patchShebangs bug. It would be nice to remove it from pkgs/ entirely.

@oxij
Copy link
Member

oxij commented Sep 4, 2018 via email

@Ericson2314
Copy link
Member

Ericson2314 commented Sep 4, 2018

I don't see any problems with referring to bash directly. I can't imagine the indirection buys us much. (If we ever get NixOS/nix#1080, that might be another matter, but we don't have it.)

@malte-v malte-v mentioned this pull request Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: emacs Text editor 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 501+ 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 10.rebuild-linux: 501+
Projects
None yet
Development

Successfully merging this pull request may close these issues.