Skip to content

gitMinimal: Fix wrong shell for cross compiled package#141959

Merged
Artturin merged 1 commit intoNixOS:stagingfrom
ck3d:fix-cross-git
Nov 5, 2021
Merged

gitMinimal: Fix wrong shell for cross compiled package#141959
Artturin merged 1 commit intoNixOS:stagingfrom
ck3d:fix-cross-git

Conversation

@ck3d
Copy link
Copy Markdown
Contributor

@ck3d ck3d commented Oct 17, 2021

The current package depends on the build hosts shell and therefor a lot of scripts can not be used on the target:

❯ nix-build -A pkgsCross.aarch64-multiplatform.gitMinimal
/nix/store/52lfla8dfp22520axc9jalz8bnp8l6xx-git-aarch64-unknown-linux-gnu-2.33.0

❯ nix-store -q --references ./result/
/nix/store/nrwmkyqhqczn61zrb3z05k31nnkqjqyb-glibc-aarch64-unknown-linux-gnu-2.33-50
/nix/store/hwzhnqhjgry727m5vkqy8zf9ppngbp3p-zlib-1.2.11-aarch64-unknown-linux-gnu
/nix/store/kkll2mjnj1dsdlhyvp78v9fjisvby86z-openssl-aarch64-unknown-linux-gnu-1.1.1l
/nix/store/2kjjiic8x1adyps4wn7p1w1ah404kdga-curl-aarch64-unknown-linux-gnu-7.76.1
/nix/store/7i3q6zdhwqfahyfm6a4lb7m4gh0m0ra4-aarch64-unknown-linux-gnu-stage-final-gcc-debug-9.3.0-lib
/nix/store/gixyqr6hc6d296ymgicklqnixv4dbfxd-expat-aarch64-unknown-linux-gnu-2.4.1
/nix/store/jwy7714ddm0yqzbii5hbj3ycn1xb7sdk-coreutils-aarch64-unknown-linux-gnu-8.32
/nix/store/k4ai6vqsqgixrbrjq14w5pg8z8pn9mfl-gettext-aarch64-unknown-linux-gnu-0.21
/nix/store/r7ag3jn3vgrr2s0jb5k9s98x7768dfgf-openssh-aarch64-unknown-linux-gnu-8.7p1
/nix/store/rgm0p4yrq6gl2475v779z25l355c9bdv-gnused-aarch64-unknown-linux-gnu-4.8
/nix/store/ss074bgk5fwz85mif0is1hwz6ig1mwaj-gnugrep-aarch64-unknown-linux-gnu-3.6
/nix/store/wadmyilr414n7bimxysbny876i2vlm5r-bash-5.1-p8
/nix/store/52lfla8dfp22520axc9jalz8bnp8l6xx-git-aarch64-unknown-linux-gnu-2.33.0

This patch fixed the dependency to the build hosts shell:

❯ nix-build -A pkgsCross.aarch64-multiplatform.gitMinimal
/nix/store/i08892l479l8yvbrlz64hh071kwky14r-git-aarch64-unknown-linux-gnu-2.33.0

❯ nix-store -q --references ./result/
/nix/store/nrwmkyqhqczn61zrb3z05k31nnkqjqyb-glibc-aarch64-unknown-linux-gnu-2.33-50
/nix/store/hwzhnqhjgry727m5vkqy8zf9ppngbp3p-zlib-1.2.11-aarch64-unknown-linux-gnu
/nix/store/kkll2mjnj1dsdlhyvp78v9fjisvby86z-openssl-aarch64-unknown-linux-gnu-1.1.1l
/nix/store/2kjjiic8x1adyps4wn7p1w1ah404kdga-curl-aarch64-unknown-linux-gnu-7.76.1
/nix/store/7i3q6zdhwqfahyfm6a4lb7m4gh0m0ra4-aarch64-unknown-linux-gnu-stage-final-gcc-debug-9.3.0-lib
/nix/store/gixyqr6hc6d296ymgicklqnixv4dbfxd-expat-aarch64-unknown-linux-gnu-2.4.1
/nix/store/jwy7714ddm0yqzbii5hbj3ycn1xb7sdk-coreutils-aarch64-unknown-linux-gnu-8.32
/nix/store/k4ai6vqsqgixrbrjq14w5pg8z8pn9mfl-gettext-aarch64-unknown-linux-gnu-0.21
/nix/store/r7ag3jn3vgrr2s0jb5k9s98x7768dfgf-openssh-aarch64-unknown-linux-gnu-8.7p1
/nix/store/rgm0p4yrq6gl2475v779z25l355c9bdv-gnused-aarch64-unknown-linux-gnu-4.8
/nix/store/ss074bgk5fwz85mif0is1hwz6ig1mwaj-gnugrep-aarch64-unknown-linux-gnu-3.6
/nix/store/i08892l479l8yvbrlz64hh071kwky14r-git-aarch64-unknown-linux-gnu-2.33.0
Motivation for this change

Want to use cross compiled gitMinimal package.

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 via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.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
  • Fits CONTRIBUTING.md.

@ck3d ck3d added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Oct 17, 2021
@ofborg ofborg bot requested review from globin, primeos and wmertens October 17, 2021 09:28
@ofborg ofborg bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Oct 17, 2021
@ck3d ck3d changed the title git: Fix wrong shell for cross compiled package gitMnimal: Fix wrong shell for cross compiled package Oct 18, 2021
@ck3d ck3d changed the title gitMnimal: Fix wrong shell for cross compiled package gitMinimal: Fix wrong shell for cross compiled package Oct 18, 2021
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. and removed 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Oct 18, 2021
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.

Don't we have a way to get the target shell at compile time? (runtimeShell?) Will git use that shell at build time as well as runtime?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, Git will use SHELL_PATH during build as well on the target.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The target shell can be access via targetPacages.bash.

@Artturin
Copy link
Copy Markdown
Member

setting the SHELL_PATH is a variable that has been there since at least 2007 and is not needed anymore.

80e42ed (#142602) fixes the build shell reference by adding bash to buildInputs

@ck3d
Copy link
Copy Markdown
Contributor Author

ck3d commented Oct 23, 2021

Removing SHELL_PATH is a regression for the native built package, since the fixup phase patches not all /bin/sh occurrences.

@Artturin
Copy link
Copy Markdown
Member

alright, should be fine now 69780f2 (#142602)

@ck3d
Copy link
Copy Markdown
Contributor Author

ck3d commented Oct 24, 2021

Your version do not build, since SHELL_PATH is executed during build:

nix-build -A pkgsCross.aarch64-multiplatform.gitMinimal
...
    CC hashmap.o
    GEN command-list.h
/nix/store/wadmyilr414n7bimxysbny876i2vlm5r-bash-5.1-p8/bin/bash: line 1: /nix/store/z1mid8asz0cnbpdd71h34k1slk9sypnm-bash-5.1-p8-aarch64-unknown-linux-gnu/bin/bash: cannot execute binary file: Exec format error
make: *** [Makefile:2256: command-list.h] Error 126

The Git package do not allow to specify build and target shell differently. On non NixOS systems, this doesn't matter, since the absolute paths to a shell is the same between build and target system.

@Artturin

This comment has been minimized.

@ck3d
Copy link
Copy Markdown
Contributor Author

ck3d commented Oct 24, 2021

I think you configured your system to emulate aarch64 via NixOS option boot.binfmt.emulatedSystems. Please disable this feature and re-build the same package.
From my point of view, this is a big impurity issue of Nix.

@Artturin
Copy link
Copy Markdown
Member

Thanks, that was indeed the case :/

@mohe2015
Copy link
Copy Markdown
Contributor

I think you configured your system to emulate aarch64 via NixOS option boot.binfmt.emulatedSystems. Please disable this feature and re-build the same package.
From my point of view, this is a big impurity issue of Nix.

I agree with you maybe open an issue for that?

@ck3d
Copy link
Copy Markdown
Contributor Author

ck3d commented Oct 24, 2021

I created #142778 to face the impurity problem.

So we can come back to gitMinimal, this PR is still valid and feedback is welcome. I hope we can get the cross compiled gitMinimal fixed, since it is a mandatory dependency for Nix flakes.

Copy link
Copy Markdown
Contributor

@r-burns r-burns left a comment

Choose a reason for hiding this comment

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

Thank you for this, I was not aware of this issue but have now verified locally that cross-compiled git uses incorrect shebangs because of SHELL_PATH.

To mitigate future regressions, how about adding something like this:

disallowedReferences = optionals (buildPlatform != hostPlatform) [
  stdenv.shell
]

Then the package will fail the build, instead of silently using bad shebangs

Comment on lines 101 to 102
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.

This is already an improvement, but I'd still like the cross-compiled git to refer exactly to its buildInputs in the store when possible. Can we add a postInstall patchShebangs --host step when cross-compiling?

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.

There are references which aren't shebangs

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.

Sure, would be good to patch those too if possible. If not, /bin/sh is at least better than a shell that can't be executed at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The path /bin/sh is embedded in binaries and I did not find an easy way to replace the path without breaking the executable.

@ck3d
Copy link
Copy Markdown
Contributor Author

ck3d commented Oct 25, 2021

Thanks, great idea, but when I set disallowedReferences then Nix complains:

checking for references to /build/ in /nix/store/fxcin2ismi5z8wpbvbnc65hvc5ldqjax-git-aarch64-unknown-linux-gnu-2.33.0...
error: derivation contains an illegal reference specifier '/nix/store/wadmyilr414n7bimxysbny876i2vlm5r-bash-5.1-p8/bin/bash'

That's weird, since nix-store doesn't show the dependency.
Has anyone an idea why Nix complains?

@github-actions github-actions bot added the 8.has: module (update) This PR changes an existing module in `nixos/` label Nov 1, 2021
@ck3d ck3d changed the base branch from master to staging November 1, 2021 12:33
@github-actions github-actions bot removed 6.topic: steam Steam game store/launcher (store.steampowered.com) 6.topic: vim Advanced text editor 6.topic: stdenv Standard environment 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 6.topic: python Python is a high-level, general-purpose programming language. 8.has: changelog This PR adds or changes release notes 6.topic: kernel The Linux kernel 6.topic: systemd Software suite that provides an array of system components for Linux operating systems. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: qt/kde Object-oriented framework for GUI creation 6.topic: TeX Issues regarding texlive and TeX in general 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: printing Drivers, CUPS & Co. labels Nov 1, 2021
@ck3d
Copy link
Copy Markdown
Contributor Author

ck3d commented Nov 1, 2021

Sorry for the noise, I only changed the target branch from master to staging.

@ofborg ofborg bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 8.has: clean-up This PR removes packages or removes other cruft 8.has: package (new) This PR adds a new package and removed 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. labels Nov 1, 2021
@Artturin
Copy link
Copy Markdown
Member

Artturin commented Nov 3, 2021

had to force push to fix the checks

@Synthetica9
Copy link
Copy Markdown
Member

I think this broke the NixOS option hardware.pulseaudio.support32Bit. At least, that's what my bisect shows.

@Artturin
Copy link
Copy Markdown
Member

in what way did it break?

@Artturin
Copy link
Copy Markdown
Member

this shouldn't have affected that at all?

@Synthetica9
Copy link
Copy Markdown
Member

I was getting error: a 'i686-linux' with features {} is required to build '/nix/store/xds3y616a8apx3y36s2dzsxx5qzdpdyf-builder.pl.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test}

But it looks like git bisect borked? I assumed it was right because this is also a cross-compiling thing, but the commit before this also fails... I'll investigate further

@Artturin
Copy link
Copy Markdown
Member

Artturin commented Nov 30, 2021

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

Labels

6.topic: cross-compilation Building packages on a different platform than they will be used on 8.has: clean-up This PR removes packages or removes other cruft 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: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants