Skip to content

Cross compilation from x86_64 to x86_64 with custom gcc arch/tune fails #268767

@jys1670

Description

@jys1670

Steps to reproduce

I have small VPS which could benefit greatly from AES-NI and other fancy instructions. It can't be used for building due to load limitations, so I've attempted to do compilation on local machine and push that on remote target:

nixos-rebuild --flake .#myServer \
  --target-host servername \
  --build-host localhost \
  boot

Wiki suggest tweaking configuration for such scenario in this way:

nixpkgs = {
    # building ON
    localSystem = {
        system = "x86_64-linux";
    };
    # building FOR
    crossSystem = {
        gcc.arch = "znver2";
        gcc.tune = "znver2";
        system = "x86_64-linux";
    };
};

However it fails while trying to compile bash:

checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu

Beginning configuration for bash-5.2-release for x86_64-unknown-linux-gnu

checking for x86_64-unknown-linux-gnu-gcc... x86_64-unknown-linux-gnu-gcc
checking whether the C compiler works... no
configure: error: in `/build/bash-5.2':
configure: error: C compiler cannot create executables

After that I've tried alternative approach that doesn't touch localSystem / crossSystem and modifies compiler wrapper instead:

crossOverlays = [
    (final: prev: {
        wrapCC = cc: prev.wrapCCWith {
            inherit cc;
            extraBuildCommands = ''
                echo "-O3 -march=znver2 -mtune=znver2" >> "$out/nix-support/cc-cflags"
            '';
        };
    })
];

Sadly that failed on python (bash worked though):

Found duplicated packages in closure for dependency 'setuptools':
        setuptools 68.2.2.post0 (/nix/store/rk7kwr8c0v8dwk64442q8c0lp7car7qn-python3.11...
        setuptools 68.2.2.post0 (/nix/store/y8yq448xka665bqyd5gvdhajqdbsnyys-python3.11...

Notify maintainers

I've seen @amjoseph-nixpkgs working on cross compilation a lot, I assume it's his area of expertise

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.62, NixOS, 23.11 (Tapir), 23.11.20231117.c757e9b`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `""`
 - nixpkgs: `/nix/store/rj6pqzx66pliiwdfk2wjnnlk40rm3mpd-source`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions