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

nixos/nix-ld: Support 32-bit portability #326948

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

KoviRobi
Copy link
Contributor

This is for i686-linux only, currently, due to pkgsi686Linux, not sure if there needs to be a more generic pkgs32Bit for e.g. arm 32-bit but perhaps precompiled binaries aren't so widely used on arm.

This improves current state of things anyway.

I have done the formatting in a separate commit so it can be dropped/use a different formatter etc.

I have tested it with some old 32-bit arm GCC (arm-eabi-gcc) that I needed to use for some embedded development.

Cross-referencing

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • 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/)
  • 24.11 Release Notes (or backporting 23.11 and 24.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.

Add a 👍 reaction to pull requests you find important.

@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 Jul 13, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jul 13, 2024
Copy link
Member

@zhaofengli zhaofengli left a comment

Choose a reason for hiding this comment

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

This is a good start.

Perhaps instead of special variants, this could be structured more generically as programs.nix-ld.systems.<system> where each system attribute is a submodule containing { package = ...; ldso = ...; libraries = ...; }. The existing package and libraries options are passed down to programs.nix-ld.systems.${pkgs.system}. This should make it more composable and support prebuilt binaries for boot.binfmt.emulatedSystems.

In this scheme, we can add support32Bit which would be a convenience shortcut that determines the corresponding 32-bit system (e.g., armv7l-linux), the package set (e.g., pkgsCross.armv7l-hf-multiplatform), and the default libraries to insert.

@KoviRobi
Copy link
Contributor Author

Thank you, I think I understand what you are saying, I'll have to try it out. I just haven't had the time/energy to do so yet, but it's not abandoned. And yes I think it'll help with non-Intel/AMD architectures e.g. nix-community/nix-ld#27

@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation 8.has: changelog 6.topic: flakes The experimental Nix feature labels Aug 23, 2024
@KoviRobi
Copy link
Contributor Author

KoviRobi commented Aug 23, 2024

@zhaofengli I'm sorry I'm struggling to figure out how to do this, I keep running into infinite recursion.

For reference, the builtins.toJSON line gives the following

$ nix build .#test
$ jq < result/etc/foo 
{
  "environment": {
    "ldso": "/nix/store/s76k7qxy3jj6giv2fzmlx5gycdc6ayy7-nix-ld-1.2.3/libexec/nix-ld",
    "pathsToLink": [
      "/share/nix-ld-x86_64-linux"
    ],
    "systemPackages": [
      "/nix/store/46wx8bbsdfb8r21wj6ddb85j4jkjzxc4-ld-library-path"
    ],
    "variables": {
      "NIX_LD_LIBRARY_PATH_x86_64_linux": "/run/current-system/sw/share/nix-ld-x86_64-linux/lib",
      "NIX_LD_x86_64_linux": "/run/current-system/sw/share/nix-ld-x86_64-linux/lib/ld.so"
    }
  },
  "programs": {
    "nix-ld": {
      "systems": {
        "x86_64-linux": {
          "libraries": [
            "/nix/store/rc18a8k50zmrif61250sfidkqvlg41ln-zlib-1.3.1",
            "/nix/store/w6ggciw9mj6r6w332dclhibwmyyv1v67-zstd-1.5.6-bin",
            "/nix/store/3s3rjkl3mx05wp0lmxgwkaqhbz9sy6kk-gcc-13.3.0",
            "/nix/store/did64gsb4sn6xvylw6cswa7697avdrsb-curl-8.8.0-bin",
            "/nix/store/ppfzl2wqzs7ljfj0dxypcvrhr9x6ka3f-openssl-3.0.14-bin",
            "/nix/store/f6vjq8dl0z6x1k7sxvzwnisbncbafnjy-attr-2.5.2-bin",
            "/nix/store/adjqi4kf1k736g7fz23hdqsk39zyjzf8-libssh-0.10.6",
            "/nix/store/wr6x94hzs5ggmpql0qx5j8q2rpfrhm7q-bzip2-1.0.8-bin",
            "/nix/store/iyaxbb5c472akzpbsn3wpmfmh8xzw7k4-libxml2-2.12.7-bin",
            "/nix/store/9xw9hxlmxkjcv02x9d4wrj3sl8gwmkl9-acl-2.3.2-bin",
            "/nix/store/8kd6icdk2025jmvhvxhi6rc3ahhj2qc4-libsodium-1.0.20",
            "/nix/store/kwa0akdagjw0hmv3mam65gmz8f1v8c8k-util-linux-2.39.4-bin",
            "/nix/store/0rlbqq6p9wwb7wbn5vnpck40c76czid3-xz-5.6.2-bin",
            "/nix/store/sbqf71kqhlgaff1ajd8zak09g4wn8ymd-systemd-255.6"
          ]
        }
      }
    }
  }
}

but if I uncomment the # recursive at the bottom of the WIP commit's nix-ld.nix, then I get an infinite recursion, even if I remove the programs.nix-ld.systems.${system}.libraries bit.

@ofborg ofborg bot added 10.rebuild-darwin: 1-10 and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin labels Aug 23, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: flakes The experimental Nix feature 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants