Hi!
I’m trying to build a kernel from source for aarch64 for the Orange Pi Zero2 H616 using the provided nix flake.
However after changing the source, it seems that a tool is missing mkimage:
/nix/store/wim4mqpn8lxhhr10p2kd070hyj152lil-bash-5.1-p16/bin/bash: line 1: mkimage: command not found
My experience with Nix is quite limited but it feels like a build dependencies is missing so I tried to override buildLinux
to add ubootTools
which contains mkimage like so:
buildLinux.overrideAttrs(old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ nixpkgs.ubootTools ];
}) rec
{
kernelPatches = [];
src = fetchFromGitHub {
owner = "orangepi-xunlong";
repo = "linux-orangepi";
rev = "orange-pi-5.16-sunxi64";
sha256 = "sha256-VnniPfLyGXeuQRyhlq+b8QgXd7qFY52rFzG2J5WzPCg=";
};
version = "5.16.17";
modDirVersion = version;
extraMeta.branch = versions.majorMinor version;
defconfig = "orangepi_defconfig";
};
but this fails with error which I just don’t understand:
error: value is a function while a set was expected
at /nix/store/1cimm8vgpgrhh03cf4awb0dgqmwirs6x-source/flake.nix:25:7:
24| # }));
25| buildLinux.overrideAttrs(old: {
| ^
26| nativeBuildInputs = old.nativeBuildInputs ++ [ nixpkgs.ubootTools ];
Have I lost myself with the syntax?
Is this the correct approach?
Here is the full flake.nix for more context:
{
description = "Build image for OrangePi Zero 2";
inputs = {
nixpkgs.url = github:nixos/nixpkgs/nixos-22.11;
};
outputs = { self, nixpkgs }: let
system = "aarch64-linux";
#Build manipulation
stateVersion = "22.11"; # NixOS Version
useUnstableKernel = true; # Set to false to use mainline kernel
compressImage = true; # Set to false to disable image compressing
pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgsCross.aarch64-multiplatform;
# Build unstable kernel
kernel =
with pkgs;
with lib;
buildLinux.overrideAttrs(old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ nixpkgs.ubootTools ];
}) rec
{
kernelPatches = [
# linuxKernel.kernelPatches.bridge_stp_helper
# linuxKernel.kernelPatches.request_key_helper
];
src = fetchFromGitHub {
owner = "orangepi-xunlong";
repo = "linux-orangepi";
rev = "orange-pi-5.16-sunxi64";
sha256 = "sha256-VnniPfLyGXeuQRyhlq+b8QgXd7qFY52rFzG2J5WzPCg=";
};
version = "5.16.17";
modDirVersion = version;
extraMeta.branch = versions.majorMinor version;
defconfig = "orangepi_defconfig";
};
# Boot related configuration
bootConfig = let
bootloaderPackage = pkgs.ubootOrangePiZero2;
bootloaderSubpath = "/u-boot-sunxi-with-spl.bin";
# Disable ZFS support to prevent problems with fresh kernels.
filesystems = pkgs.lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs"
"ntfs" "cifs" /* "zfs" */ "ext4" "vfat"
];
in {
system.stateVersion = stateVersion;
boot.kernelPackages = if useUnstableKernel
then pkgs.linuxPackagesFor kernel
else pkgs.linuxPackages_latest;
boot.initrd.supportedFilesystems = filesystems;
sdImage = {
postBuildCommands = ''
# Emplace bootloader to specific place in firmware file
dd if=${bootloaderPackage}${bootloaderSubpath} of=$img \
bs=8 seek=1024 \
conv=notrunc # prevent truncation of image
'';
inherit compressImage;
};
};
# NixOS configuration
nixosSystem = nixpkgs.lib.nixosSystem rec {
inherit system;
modules = [
# Default aarch64 SOC System
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# Minimal configuration
"${nixpkgs}/nixos/modules/profiles/minimal.nix"
{ config = bootConfig; }
# Put your configuration here. e.g. ./configuration.nix
];
};
in {
inherit system;
# Run nix build .#images.orangePiZero2 to build image.
images = {
orangePiZero2 = nixosSystem.config.system.build.sdImage;
};
};
}