Rename kboot-conf to petitboot and simplify a few things

This commit is contained in:
Josh Buker 2026-01-28 22:53:01 -08:00
parent cb8f383995
commit 1e1205f6f7
No known key found for this signature in database
GPG key ID: E077B96C5EFF10F2
4 changed files with 96 additions and 89 deletions

View file

@ -1,31 +1,36 @@
# Based on kboot-conf by original authors povik and sstent.
# I'm just porting things over. the original work can be viewed at:
# https://github.com/sstent/nixos-on-odroid-m1
# https://github.com/povik/nixos-on-odroid-n2
{ config, pkgs, lib, ... }:
{
imports = [
./kboot-conf
./petitboot
];
#boot.loader.grub.enable = false;
boot.loader.kboot-conf.enable = true;
boot.loader.petitboot.enable = lib.mkForce true;
# Fails to rebuild unless grub is explicitly disabled
boot.loader.grub.enable = lib.mkForce false;
# TODO: Can this be removed? Presumably anything built with 25.11 / unstable
# or later will be on a kernel >6.6
# Use kernel >6.6 The devicetree is missing from kernel versions older than this.
boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "6.6") (lib.mkDefault pkgs.linuxPackages_latest);
# TODO: Debug why removing this breaks booting from petitboot
boot.supportedFilesystems = lib.mkForce ["btrfs" "cifs" "f2fs" "jfs" "ntfs" "reiserfs" "vfat" "xfs"];
# I'm not completely sure if some of these could be omitted,
# but want to make sure disk access works
# TODO: Some of these could potentially be omitted, check which ones are
# actually necessary for disk access to function
boot.initrd.availableKernelModules = [
# Only nvme emitted when using nixos-generate-config on my odroid-m1
"nvme"
"nvme-core"
"phy-rockchip-naneng-combphy"
"phy-rockchip-snps-pcie3"
# "nvme-core"
# "phy-rockchip-naneng-combphy"
# "phy-rockchip-snps-pcie3"
];
# Petitboot uses this port and baud rate on the boards serial port,
# it's probably good to keep the options same for the running
# kernel for serial console access to work well
# Petitboot uses this port and baud rate on the board's serial port. It's
# probably good to keep the options same for the running kernel for serial
# console access to work well.
boot.kernelParams = ["console=ttyS2,1500000"];
hardware.deviceTree.name = "rockchip/rk3568-odroid-m1.dtb";
}

View file

@ -1,73 +0,0 @@
{ config, lib, pkgs, ... }:
let
cfg = config.boot.loader.kboot-conf;
# The builder used to write during system activation
builder = pkgs.replaceVarsWith {
src = ./generate-kboot-conf.sh;
replacements = {
bash = pkgs.bash;
path = lib.makeBinPath [
pkgs.coreutils
pkgs.gnused
pkgs.gnugrep
];
};
name = "system-activation-generate-kboot-conf";
isExecutable = true;
};
# The builder exposed in populateCmd, which runs when building the sdImage
populateBuilder = pkgs.buildPackages.replaceVarsWith {
src = ./generate-kboot-conf.sh;
replacements = {
bash = pkgs.buildPackages.bash;
path = lib.makeBinPath [
pkgs.buildPackages.coreutils
pkgs.buildPackages.gnused
pkgs.buildPackages.gnugrep
];
};
name = "build-image-generate-kboot-conf";
isExecutable = true;
};
in
{
options = {
boot.loader.kboot-conf = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to create petitboot-compatible /kboot.conf
'';
};
configurationLimit = lib.mkOption {
default = 10;
example = 5;
type = lib.types.int;
description = ''
Maximum number of configurations in the generated kboot.conf.
'';
};
populateCmd = lib.mkOption {
type = lib.types.str;
readOnly = true;
description = ''
Contains the builder command used to populate an image,
honoring all options except the <literal>-c &lt;path-to-default-configuration&gt;</literal>
argument.
Useful to have for sdImage.populateRootCommands
'';
};
};
};
config = let
args = "-g ${toString cfg.configurationLimit} -n ${config.hardware.deviceTree.name}";
in
lib.mkIf cfg.enable {
system.build.installBootLoader = lib.mkForce "${builder} ${args} -c";
system.boot.loader.id = "kboot-conf";
boot.loader.kboot-conf.populateCmd = "${populateBuilder} ${args}";
};
}

View file

@ -0,0 +1,75 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.boot.loader.petitboot;
args = "-g ${toString cfg.configurationLimit} -n ${config.hardware.deviceTree.name}";
# The installer used when running nixos-rebuild switch or similar
installer = pkgs.replaceVarsWith {
src = ./install-petitboot.sh;
replacements = {
bash = pkgs.bash;
path = lib.makeBinPath [
pkgs.coreutils
pkgs.gnused
pkgs.gnugrep
];
};
name = "install-petitboot";
isExecutable = true;
};
# The installer used to write to SD card images
sdImageInstaller = pkgs.buildPackages.replaceVarsWith {
src = ./install-petitboot.sh;
replacements = {
bash = pkgs.buildPackages.bash;
path = lib.makeBinPath [
pkgs.buildPackages.coreutils
pkgs.buildPackages.gnused
pkgs.buildPackages.gnugrep
];
};
name = "install-petitboot-sd-image";
isExecutable = true;
};
in
{
options = {
boot.loader.petitboot = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to enable the Petitboot bootloader.
'';
};
configurationLimit = lib.mkOption {
default = 10;
example = 5;
type = lib.types.int;
description = ''
Maximum number of configurations to display when booting.
'';
};
};
};
config = lib.mkMerge[
(lib.mkIf config.boot.loader.petitboot.enable {
system.build.installBootLoader = lib.mkForce "${installer} ${args} -c";
system.boot.loader.id = "petitboot";
})
(lib.mkIf config.boot.loader.petitboot.enable && options ? sdImage {
sdImage.populateRootCommands = lib.mkForce ''
${sdImageInstaller} ${args} -c ${config.system.build.toplevel} -d ./files/kboot.conf
''
})
];
}

View file

@ -57,7 +57,7 @@ addEntry() {
echo "'"
}
echo "# Auto-generated by generate-kboot-conf.sh, do not edit" > $tmp
echo "# Auto-generated by install-petitboot.sh, do not edit or remove" > $tmp
addEntry $default default >> $tmp
if [ "$numGenerations" -gt 0 ]; then