Skip to content

Cross-compiled NixOS#36187

Merged
shlevy merged 36 commits intoNixOS:stagingfrom
shlevy:cross-nixos
Mar 2, 2018
Merged

Cross-compiled NixOS#36187
shlevy merged 36 commits intoNixOS:stagingfrom
shlevy:cross-nixos

Conversation

@shlevy
Copy link
Copy Markdown
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 on Darwin and must target a staging branch. 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. labels Mar 1, 2018
Copy link
Copy Markdown
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!

};

crossSystem = mkOption {
type = types.nullOr types.attrs;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.)


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

BUILD_CC = "cc";
Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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

sha256 = "10iwkghl5g50b7wc17bsb9wa0dh2gd57bjlk6ynixhywz6dhx1r9";
};

preConfigure = "export AR=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}ar";
Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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)

# Check that the udev plugin got built.
postInstall = stdenv.lib.optional (udev != null) "[ -e $out/lib/dhcpcd/dev/udev.so ]";

postFixup = ''
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

shlevy commented Mar 1, 2018

@Ericson2314 Fixed


add_needed $1

while [ ''${#left[@]} -ne 0 ]; do
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

bgamari commented Mar 2, 2018

Wow, great work!

@bjornfor
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

bjornfor commented Mar 2, 2018

Thanks!

manual-combined = runCommand "nixos-manual-combined"
{ inherit sources;
buildInputs = [ libxml2 libxslt ];
nativeBuildInputs = [ buildPackages.libxml2 buildPackages.libxslt ];
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

oxij commented Sep 4, 2018 via email

@Ericson2314
Copy link
Copy Markdown
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
Copy Markdown
Member

oxij commented Sep 4, 2018 via email

@Ericson2314
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

oxij commented Sep 4, 2018 via email

@Ericson2314
Copy link
Copy Markdown
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+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.