ryan4yin / nixos-rk3588

Minimal NixOS running on RK3588/RK3588s based SBC(Orange Pi 5 Plus, Orange Pi 5, Rock 5A, etc)
MIT License
156 stars 28 forks source link

Kernel fails to build #58

Closed gnull closed 1 month ago

gnull commented 1 month ago

Hi!

I've encountered a kernel compile error when trying to build a system for Orange Pi 5 Plus. I'm using the following flake.nix (based on #57):

{
  description = "NixOS configuration";

  inputs = {
    unstable.url = "nixpkgs/nixos-unstable";
    nixpkgs.url = "nixpkgs/nixos-24.05";
    nixos-rk3588.url = "github:ryan4yin/nixos-rk3588";
  };

  outputs = { nixpkgs, nixos-rk3588, ... }: let
    # using the same nixpkgs as nixos-rk3588 to utilize the cross-compilation cache.
    inherit (nixos-rk3588.inputs) nixpkgs;
    system = "aarch64-linux";
  in {
    nixosConfigurations = {
      opi5plus = nixpkgs.lib.nixosSystem {
        inherit system;
        specialArgs = {
          rk3588 = {
            inherit nixpkgs;
            pkgsKernel = import nixpkgs {
              inherit system;
            };
          };
        };

        modules = [
          nixos-rk3588.nixosModules.boards.orangepi5plus.core
          ./system/configuration.nix
          ./system/hardware-configuration.nix
        ];
      };
    };
  };
}

The configuration.nix and hardware-configuration.nix are the files that were generated by nixos-generate-config while following the steps from here.

I've partitioned my SSD and mounted to /mnt as Nix manual suggests, and ran this command (with no flake.lock, so it would generate one):

nixos-install --flake /mnt/etc/nixos#opi5plus --root /mnt -v

The command starts with (there are some cached things, since I'm re-running it to record the logs):

warning: creating lock file '/mnt/etc/nixos/flake.lock'
building the flake in path:/mnt/etc/nixos?lastModified=1729524129&narHash=sha256-JfDZbS9aPugcmOWCuuPm9tHk9uX7m8EUX6xDMsMIYFE%3D...
copying path '/nix/store/6k9931glp8brpwrqnvgqihaca5bvja5v-source' to 'local'...
[1 copied (13.9 MiB)] evaluating derivation 'path:/mnt/etc/nixos?lastModified=17

these 6 derivations will be built:
  /nix/store/17l8mwjcaaa0a0l68kq6w1id48yc1r03-k.drv
  /nix/store/1fnvp6cgw1h1ri6nr0j35gvr366jcl3l-k-modules.drv
  /nix/store/8ffm72irgjiga2zkniy77zx64fwaia6h-k-modules-shrunk.drv
  /nix/store/6n4kh18al4k0gqpbgvx0h43nvqzpxvgv-initrd-k.drv
  /nix/store/sym2igl1manb05p2jg39495vgbb16sgr-boot.json.drv
  /nix/store/8ag5gfzx1w5rms4km3vkgripy5sz0jlx-nixos-system-nixos-24.05.20241009.d51c286.drv
building '/nix/store/17l8mwjcaaa0a0l68kq6w1id48yc1r03-k.drv'...

Then it prints CC/LD/... messages about building the kernel modules, until it fails (some 20-30 minutes later) with this:

k>   CC [M]  drivers/hwmon/w83l785ts.o
k>   CC [M]  drivers/hwmon/w83l786ng.o
k>   LD [M]  drivers/hwmon/nct6775.o
k>   AR      drivers/hwmon/built-in.a
k> /nix/store/f3l6xjrp2yf76crhqfgyl6645skmyjl8-binutils-2.41/bin/ld: warning: -z
 relro ignored
k> make[1]: *** [../scripts/Makefile.build:500: drivers] Error 2
k> make: *** [../Makefile:2012: .] Error 2
error: builder for '/nix/store/17l8mwjcaaa0a0l68kq6w1id48yc1r03-k.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/8ag5gfzx1w5rms4km3vkgripy5sz0jlx-nixos-system-nixos-24.05.20241009.d51c286.drv' failed to build
[root@orangepi5plus:/mnt/etc/nixos]#

Can anyone suggest what could be the next step to debug this? I've been unsuccessfully googling for a way to get the full Make error message from nixos-rebuild, but can't find one.

HeroBrine1st commented 1 month ago

First of all, you should use nixpkgs from your flake, not from this flake (so don't inherit it, or set follows). Don't forget to lock pkgsKernel to avoid rebuilding on every update.

You can probably use nix-store --read-log on failed kernel derivation. If you see segmentation faults and use SD card, try USB stick (it leaves you with UEFI only) - it will be much slower but for me it eventually built, and did not kill USB stick as with my SD cards (probably too cheap or counterfeit, idk).

gnull commented 1 month ago

Here's the updated flake:

{
  description = "NixOS configuration";

  inputs = {
    unstable.url = "nixpkgs/nixos-unstable";
    nixpkgs.url = "nixpkgs/nixos-24.05";
    nixpkgs.follows = "nixos-rk3588/nixpkgs";
    nixos-rk3588.url = "github:ryan4yin/nixos-rk3588";
  };

  outputs = { nixpkgs, nixos-rk3588, ... }: let
    system = "aarch64-linux";
  in {
    nixosConfigurations = {
      opi5plus = nixpkgs.lib.nixosSystem {
        inherit system;
        specialArgs = {
          rk3588 = { 
            inherit nixpkgs; 
            pkgsKernel = import nixpkgs { 
              inherit system;
            }; 
          };
        };

        modules = [
          nixos-rk3588.nixosModules.boards.orangepi5plus.core
          ./system/configuration.nix
          ./system/hardware-configuration.nix
        ];
      };
    };
  };
}

The build still fails. Here's some extra info:

n0rad commented 1 month ago

I had the same issue on my side, and was wondering why I was the only one.

Building with nixos 24.05 means building with gcc 13, which look more strict on checking function declaration against function body.

I created a patch and was about to open a PR upstream:

diff --git a/drivers/media/platform/rockchip/cif/capture.c b/drivers/media/platform/rockchip/cif/capture.c
index 442ee5a86..d5cd03237 100644
--- a/drivers/media/platform/rockchip/cif/capture.c
+++ b/drivers/media/platform/rockchip/cif/capture.c
@@ -4927,7 +4927,7 @@ static void rkcif_detach_sync_mode(struct rkcif_device *cif_dev)
 }

 void rkcif_do_stop_stream(struct rkcif_stream *stream,
-             unsigned int mode)
+             enum rkcif_stream_mode mode)
 {
    struct rkcif_vdev_node *node = &stream->vnode;
    struct rkcif_device *dev = stream->cifdev;
@@ -6087,7 +6087,7 @@ static void rkcif_attach_sync_mode(struct rkcif_device *cifdev)

 static void rkcif_monitor_reset_event(struct rkcif_device *dev);

-int rkcif_do_start_stream(struct rkcif_stream *stream, unsigned int mode)
+int rkcif_do_start_stream(struct rkcif_stream *stream, enum rkcif_stream_mode mode)
 {
    struct rkcif_vdev_node *node = &stream->vnode;
    struct rkcif_device *dev = stream->cifdev;
ryan4yin commented 1 month ago

The problem may be caused by #52, I didn't have time to test it at the time, so I just merged it.

You can try pinning nixos-rk3588 to the commit dc5e85f45ea3d832de04bbd7afec5c19e2128451 to see if the problem persists.

If this is the case, I think we can revert #52 first.

gnull commented 1 month ago

@ryan4yin pinning has fixed the compiler error and the system builds and boots now.