Arcayr / orangepizero3-nix

kernel source and uboot configuration for linux 6.1.31 for the orange pi zero 3. mirror of https://forgejo.rascals.net/arcayr/orangepizero3-nix
https://forgejo.rascals.net/arcayr/orangepizero3-nix
3 stars 1 forks source link

How to setup pkgs.orangePiZero3? #2

Open pablohirafuji opened 9 months ago

pablohirafuji commented 9 months ago

Hey, thank you for sharing your configuration.

I'm trying to build an image to use on my own orange pi zero 3 and I can't get it to work. Mainly this line of the example:

# your shiny custom kernel.
  boot.kernelPackages = pkgs.orangePiZero3; # however you get the package here is up to you - overlay or directly from the flake.

I tried using directly from the flake:

boot.kernelPackages = opiz3-nix.packages.aarch64-linux.linuxOrangePiZero3;

But it gives me this error:

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nixos-sd-image-24.05.20240131.b8b232a-aarch64-linux.img'
         whose name attribute is located at /nix/store/mcm21fbi7i6m3f189pkm7zcdn4c9xl40-source/pkgs/stdenv/generic/make-derivation.nix:352:7

       … while evaluating attribute 'buildCommand' of derivation 'nixos-sd-image-24.05.20240131.b8b232a-aarch64-linux.img'

         at /nix/store/mcm21fbi7i6m3f189pkm7zcdn4c9xl40-source/nixos/modules/installer/sd-card/sd-image.nix:182:7:

          181|
          182|       buildCommand = ''
             |       ^
          183|         mkdir -p $out/nix-support $out/sd-image

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'extend' missing

       at /nix/store/mcm21fbi7i6m3f189pkm7zcdn4c9xl40-source/nixos/modules/system/boot/kernel.nix:43:31:

           42|       type = types.raw;
           43|       apply = kernelPackages: kernelPackages.extend (self: super: {
             |                               ^
           44|         kernel = super.kernel.override (originalArgs: {

I've also tried using pkgs.linuxPackagesFor opiz3-nix.packages.aarch64-linux.linuxOrangePiZero3 with no success. Can you give me an example on how to setup the pkgs.orangePiZero3 overlay?

deftdawg commented 4 months ago

@pablohirafuji did you get this going?

I'm struggling with understanding how it's supposed to build, feel like the instructions are missing something.

Perhaps there was a repo with more commits at forgejo (mentioned in the project description), but it appears to be toast now.

@Arcayr can you advise if there's more that we're missing?

Arcayr commented 4 months ago

interestingly i didn't get a notif when the issue was opened, sorry gang.

i've since left the nix ecosystem, however the last time i used it, i had the following in flake.nix, in my inputs:

# orange pi sanity saving apparatus.
opiz3-nix = {
  url = "github:arcayr/orangepizero3-nix";
  inputs.nixpkgs.follows = "nixpkgs";
};

the overlay from this flake is then added to the nixpkgs of the host i was using it on:

nixpkgs = {
  config = {
    allowUnfree = true;
  };

  overlays = [
    inputs.opiz3-nix.overlays.pkgs;
  ];
};

and the following in the configuration for the board:

nixpkgs.hostPlatform = "aarch64-linux";

# dodge "module ahci not found" error for socs.
hardware.enableRedistributableFirmware = false;
nixpkgs.overlays = [
  (final: super: {
    makeModulesClosure = x:
      super.makeModulesClosure (x // { allowMissing = true; });
  })
];

# u-boot, no grub, no efi.
boot.loader.grub.enable = false;
boot.loader.generic-extlinux-compatible.enable = true;
boot.loader.efi.canTouchEfiVariables = false;

# slim supported filesystems.
boot.supportedFilesystems = pkgs.lib.mkForce ["vfat" "ext4"];
boot.initrd.supportedFilesystems = pkgs.lib.mkForce ["vfat" "ext4"];

# opi z3 custom kernel.
# TODO: move to mainline 6.6 when released.
boot.kernelPackages = let 
crossPkgs = import pkgs.path { # force cross-compile from x86_64.
  localSystem.system  = "x86_64-linux";
  crossSystem.system = "aarch64-linux";
}; in crossPkgs.linuxPackagesFor pkgs.linuxOrangePiZero3; # this comes in via the orangepizero3-nix flake, from its package - https://github.com/Arcayr/orangepizero3-nix/blob/main/flake.nix#L15

# opi needs the uboot image written to a specific part of the firmware.
sdImage.postBuildCommands = ''dd if=${pkgs.ubootOrangePiZero3}/u-boot-sunxi-with-spl.bin of=$img bs=8 seek=1024 conv=notrunc'';

# this gets burned straight onto an sd. no point in zstd.
sdImage.compressImage = false;

the above is all from memory so it might be a little bit off, apologies if so.

i believe linux 6.6+ actually supports this board in mainline, so you may be able to simply use upstream now. i'd recommend chatting to the people in the nixos on arm channel on matrix for information on the intricacies of compiling custom kernels for aarch64; they are very helpful.

forgejo is actually coming back today, i am right in the middle of migrating it from vultr to fly.io :)

Arcayr commented 4 months ago

if you're compiling from an aarch64 laptop (e.g., an m* macbook) you may need to remove this part from the board config:

crossPkgs = import pkgs.path { # force cross-compile from x86_64.
  localSystem.system  = "x86_64-linux";
  crossSystem.system = "aarch64-linux";
}; in crossPkgs.linuxPackagesFor pkgs.linuxOrangePiZero3;

and replace it with

pkgs.linuxPackagesFor pkgs.linuxOrangePiZero3;
pablohirafuji commented 4 months ago

@deftdawg No, I was not able to make it work. I didn't test with the new instructions tho.

@Arcayr Thanks for the detailed instructions, I will try when I have the time.