Why does nixos-rebuild want me to install a library?

Trying to build a flake with gnupg for aarch64 on x86 and it fails:

error: builder for '/nix/store/sb333zfrc8fwmkqz9dds427pjm6c2g48-gnupg-aarch64-unknown-linux-gnu-2.4.5.drv' failed with exit code 1;
       last 10 log lines:
       > *** New Portable Threads Library (nPth). Please install this
       > *** library first.  The library is for example available at
       > ***   https://gnupg.org/ftp/gcrypt/npth/
       > *** (at least version 1.2 (API 1) is required).
       > ***
       > configure: error:
       > ***
       > *** Required libraries not found. Please consult the above messages
       > *** and install them before running configure again.
       > ***
       For full logs, run 'nix log /nix/store/sb333zfrc8fwmkqz9dds427pjm6c2g48-gnupg-aarch64-unknown-linux-gnu-2.4.5.drv'.
error (ignored): error: cannot unlink '/tmp/nix-build-tpm2-tss-aarch64-unknown-linux-gnu-4.0.1.drv-0/source': Directory not empty
error: 1 dependencies of derivation '/nix/store/ihk3hb17k246d3d1p1g1sg1in4cmxr36-systemd-aarch64-unknown-linux-gnu-255.4.drv' failed to build
error: 1 dependencies of derivation '/nix/store/1dvl02yqqgacdad3mcbg6mjk7rwryy57-util-linux-aarch64-unknown-linux-gnu-2.39.3.drv' failed to build
error: 1 dependencies of derivation '/nix/store/py658abgm23bc9xbpwnjiqpsdwsfwi1h-nixos-rebuild.drv' failed to build

This didn’t fail before I added this:

        modules = [
           {                                                                                                          
          nixpkgs.config.allowUnsupportedSystem = true;                                                            
          nixpkgs.hostPlatform.system = "aarch64-linux";                                                           
          nixpkgs.buildPlatform.system = "x86_64-linux";                                                           
        } 

, so I guess it must be related. I need those lines to get a working kernel, to my understanding.

And btw, it doesn’t help to actually install this library, neither on the host nor on the target;)

You’re cross-compiling to aarch64-linux and apparently gnupg is broken in cross.

ok, but why does it succeed if I remove those three lines?

Also, I don’t even have gnupg in any of my files, so something else is pulling this in. Any way to figure out what?

it says:

error: 1 dependencies of derivation '/nix/store/ihk3hb17k246d3d1p1g1sg1in4cmxr36-systemd-aarch64-unknown-linux-gnu-255.4.drv' failed to build
error: 1 dependencies of derivation '/nix/store/1dvl02yqqgacdad3mcbg6mjk7rwryy57-util-linux-aarch64-unknown-linux-gnu-2.39.3.drv' failed to build
error: 1 dependencies of derivation '/nix/store/py658abgm23bc9xbpwnjiqpsdwsfwi1h-nixos-rebuild.drv' failed to build

, so gnupg is a dependency of util-linux and systemd?

Because you’re then no longer cross-compiling but building natively for whatever hostPlatform that is set for the specific host.

Correct. Though likely many other pieces of software too.

Also note that most of the cross builds are not cached, requiring you to build them yourself.

I don’t understand that line;). I’m building on x86 for a Pi, but if I run a native compilier in emulation, then it’s not cross compiling, or something like that?:wink:

Yes, I experience that. It takes like 10 hours to build. Anyways, is there no way to get a higher kernel on the Pi, then?

Your PC has an x86 processor which can only execute binaries made of x86.
Your Pi has an ARM processor which can only execute binaries made for ARM.

What you’re attempting to do now is to produce ARM binaries on your x86 PC. For that to happen, you need a compiler built for the buildPlatform (x86) that produces binaries made for the hostPlatform (ARM). This is the process of cross-compiling. The tools ran during compilation are native to the platform the build is performed on but the resulting code is made for a different platform.

“native compiler in emulation” means that your processor gains the ability to execute another platform’s code via emulation. In that case the compiler that is ran during the build is itself an ARM executable and also produces code for ARM. It’s the same as if you ran a regular build on an actual ARM processor and is colloquially known as a “native” build. The emulation just makes it possible to perform it on a machine that otherwise couldn’t because its processor does not understand ARM.

Though do note that such emulation is very slow to the point where you might be better off just building on the Pi itself.

Should have known that this is an XY problem :wink:

What kernel are you running currently, which kernel do you want to run and what steps have you taken in order to do so?

The kernel on the Pi is the number of the beast, 6.6.6. I want to be running something more recent, like maybe 6.8.6

The steps I’ve taken to do so is

    kernelPackages = lib.mkForce pkgs.linuxPackages_latest;

Also, it’s cross compilation that works, but not native compilation, then.

So, I guess the only thing I can do now is file a bug report, then.

That’s quite old. 6.6 is fine (latest LTS kernel) but .6 was many months ago; current version is 6.6.28.

Which exact kernel is boot.kernelPackages and which revision of Nixpkgs are you using?

Why exactly do you need something newer than 6.6?

mkForce should not be necessary.

I’m also unsure about mainline kernel support for your SBC; they usually have vendor kernels.

What happens if you do this without cross-compiling?

Why?

In the OP you said that the build error occurs when you add the cross config.

I’m pretty sure this is also fixed in nixos-unstable (as of sometime in the last few days). (Not that I was waiting for it eagerly.)

2 Likes
    kernelPackages = lib.mkForce pkgs.linuxPackages_latest;
$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.6, NixOS, 23.11 (Tapir), 23.11.6359.53a2c32bc66f`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"home-manager-23.11.tar.gz, nixos-23.11"`
 - channels(b0ef): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

I’m trying to get CEC working on the Pi.

I said that when I add this, it doesn’t work:

modules = [
           {                                                                                                          
          nixpkgs.config.allowUnsupportedSystem = true;                                                            
          nixpkgs.hostPlatform.system = "aarch64-linux";                                                           
          nixpkgs.buildPlatform.system = "x86_64-linux";                                                           
        } 

, but it does work if I don’t add those lines.

I always build like this:

nixos-rebuild switch --flake .#pi --target-host root@10.0.0.68 --option eval-cache false --impure

Right now I can’t remember why I added those lines;) Ok, I think it was because it built ok, but the kernel didn’t boot.

Also, I always build with nixos-rebuild on x86 for my Pi.

Hmm, it seems I’m already on unstable. This is my flake:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:nixos/nixos-hardware";
  };
  outputs = inputs @ { self, sops-nix, nixpkgs, nixos-hardware }: rec {
    images = {
      pi = (self.nixosConfigurations.pi.extendModules {
        modules = [
          "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
          {
            disabledModules = [ "profiles/base.nix" ];
          }
        ];
      }).config.system.build.sdImage;
    };

    sdImage.compressImage = false;
    
    packages.x86_64-linux.pi-image = images.pi;
    packages.aarch64-linux.pi-image = images.pi;
    nixosConfigurations = {
      pi = nixpkgs.lib.nixosSystem {
        system = "aarch64-linux";
        modules = [
           {                                                                                                          
          nixpkgs.config.allowUnsupportedSystem = true;                                                            
          nixpkgs.hostPlatform.system = "aarch64-linux";                                                           
          nixpkgs.buildPlatform.system = "x86_64-linux";                                                           
        } 
          nixos-hardware.nixosModules.raspberry-pi-4
          "${nixpkgs}/nixos/modules/profiles/minimal.nix"
          ./configuration.nix
          ./hydra.xorg.lightdm.kodi.nix
          ./base.nix
          ./user.nix
          ./home-manager.nix
          ./bytesized.nix
          /home/b0ef/ds/platform/conf/hydra.audio.nix
        ];
        specialArgs = { inherit inputs self; };
      };
    };
  };
}


You might need to update your inputs.

Here’s the fix I was carrying: gnupg: fix cross compilation by uninsane · Pull Request #298001 · NixOS/nixpkgs · GitHub

and if you check here, you’ll see that PR has landed into nixos-unstable: https://nixpk.gs/pr-tracker.html?pr=298001

I meant whatever is giving you 6.6.6.

These lines make your config cross-compile. It breaks when you enable that. Thus cross is broken, not native.

If you’re using flakes, you’ll have to look at its inputs/the lockfile to figure out which revision you’re using.

What happens if you do that rebuild without cross?

I first did

nix flake update

Now it seems it’s a new error;)

$ nixos-rebuild switch --flake .#pi --target-host root@10.0.0.68 --option eval-cache false --impure
building the system configuration...
error: builder for '/nix/store/c11qv38zqphrhf2d8dj12gswf8smrv6j-libftdi-aarch64-unknown-linux-gnu-1.5.drv' failed with exit code 2;
       last 10 log lines:
       > [ 18%] Built target docs
       > [ 20%] Generating ftdi1_doc.i
       > [ 22%] Linking CXX static library libftdipp1.a
       > [ 22%] Built target ftdipp1-static
       > [ 24%] Linking C shared library libftdi1.so
       > [ 26%] Linking C static library libftdi1.a
       > [ 26%] Built target ftdi1-static
       > [ 26%] Built target ftdi1
       > [ 26%] Built target doc_i
       > make: *** [Makefile:156: all] Error 2
       For full logs, run 'nix log /nix/store/c11qv38zqphrhf2d8dj12gswf8smrv6j-libftdi-aarch64-unknown-linux-gnu-1.5.drv'.
error: 1 dependencies of derivation '/nix/store/hzac8i15mdnpaqrky9z0l4qmnr3f2r54-lirc-aarch64-unknown-linux-gnu-0.10.2.drv' failed to build
error: 1 dependencies of derivation '/nix/store/sqblwfr13av3r5ykh31zfnlyqn90hhqh-kodi-aarch64-unknown-linux-gnu-21.0.drv' failed to build
error (ignored): error: cannot unlink '/tmp/nix-build-libdvdread-aarch64-unknown-linux-gnu-6.1.3.drv-0': Directory not empty
error: 1 dependencies of derivation '/nix/store/gfrpdlylz4i8ij7prj08dx95vm6ccpsl-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/maj9pxg9r8hnd9f7q5sna93aa9i6pqkb-xsession.drv' failed to build
error: 1 dependencies of derivation '/nix/store/rfiwwj92g6fz68pjsbzhgkzsm4l32wm1-nixos-system-pi-24.05.20240421.6143fc5.drv' failed to build

You’re going to want to run that and share it. I don’t see an obvious error in those last 10 lines shown.

1 Like