nix format

This commit is contained in:
mjallen18
2026-01-03 09:28:28 -06:00
parent 4a6a68dad4
commit 105ed3bcb8
2 changed files with 137 additions and 140 deletions

View File

@@ -15,109 +15,129 @@ let
# installs raspberry's firmware independent of the nixos generations
# sometimes referred to as "boot code"
raspberryPiFirmware = ({ pkgs
, firmware
, configTxt
}: pkgs.replaceVarsWith {
src = ./generational/install-firmware.sh;
isExecutable = true;
raspberryPiFirmware = (
{
pkgs,
firmware,
configTxt,
}:
pkgs.replaceVarsWith {
src = ./generational/install-firmware.sh;
isExecutable = true;
replacements = {
inherit (pkgs) bash;
path = pkgs.lib.makeBinPath [
pkgs.coreutils
];
replacements = {
inherit (pkgs) bash;
path = pkgs.lib.makeBinPath [
pkgs.coreutils
];
inherit firmware configTxt;
};
});
kernelbootGenBuilder = ({ pkgs
, deviceTreeInstaller
}: pkgs.replaceVarsWith {
src = ./generational/kernelboot-gen-builder.sh;
isExecutable = true;
replacements = {
inherit (pkgs) bash;
path = pkgs.lib.makeBinPath [
pkgs.coreutils
];
installDeviceTree = deviceTreeInstaller;
};
});
deviceTree = ({ pkgs
, firmware
}: pkgs.replaceVarsWith {
src = ./generational/install-device-tree.sh;
isExecutable = true;
replacements = {
inherit (pkgs) bash;
path = pkgs.lib.makeBinPath [
pkgs.coreutils
];
inherit firmware;
};
});
mkBootloader = pkgs: bootloader {
inherit pkgs;
inherit (cfg) nixosGenerationsDir;
firmwareInstaller = "${raspberryPiFirmware {
inherit pkgs;
firmware = pkgs.${namespace}.raspberrypifw;
configTxt = pkgs.writeTextFile {
name = "config.txt";
text = ''
# Do not edit!
# This configuration file is generated from NixOS configuration
# options `hardware.raspberry-pi.config`.
# Any manual changes will be overwritten on the next configuration
# switch.
${config.${namespace}.hardware.raspberry-pi.config-generated}
'';
inherit firmware configTxt;
};
}}";
}
);
nixosGenBuilder = "${kernelbootGenBuilder {
kernelbootGenBuilder = (
{
pkgs,
deviceTreeInstaller,
}:
pkgs.replaceVarsWith {
src = ./generational/kernelboot-gen-builder.sh;
isExecutable = true;
replacements = {
inherit (pkgs) bash;
path = pkgs.lib.makeBinPath [
pkgs.coreutils
];
installDeviceTree = deviceTreeInstaller;
};
}
);
deviceTree = (
{
pkgs,
firmware,
}:
pkgs.replaceVarsWith {
src = ./generational/install-device-tree.sh;
isExecutable = true;
replacements = {
inherit (pkgs) bash;
path = pkgs.lib.makeBinPath [
pkgs.coreutils
];
inherit firmware;
};
}
);
mkBootloader =
pkgs:
bootloader {
inherit pkgs;
deviceTreeInstaller = let
cmd = deviceTree {
inherit pkgs;
firmware = cfg.firmwarePackage;
inherit (cfg) nixosGenerationsDir;
firmwareInstaller = "${raspberryPiFirmware {
inherit pkgs;
firmware = pkgs.${namespace}.raspberrypifw;
configTxt = pkgs.writeTextFile {
name = "config.txt";
text = ''
# Do not edit!
# This configuration file is generated from NixOS configuration
# options `hardware.raspberry-pi.config`.
# Any manual changes will be overwritten on the next configuration
# switch.
${config.${namespace}.hardware.raspberry-pi.config-generated}
'';
};
args = lib.optionalString (!cfg.useGenerationDeviceTree) " -r";
in "${cmd} ${args}";
}}";
}}";
};
nixosGenBuilder = "${kernelbootGenBuilder {
inherit pkgs;
deviceTreeInstaller =
let
cmd = deviceTree {
inherit pkgs;
firmware = cfg.firmwarePackage;
};
args = lib.optionalString (!cfg.useGenerationDeviceTree) " -r";
in
"${cmd} ${args}";
}}";
bootloader = ({ pkgs
, nixosGenerationsDir
, firmwareInstaller
, nixosGenBuilder
}: pkgs.replaceVarsWith {
src = ./generational/nixos-generations-builder.sh;
isExecutable = true;
replacements = {
inherit (pkgs) bash;
path = pkgs.lib.makeBinPath [
pkgs.coreutils
pkgs.gnused
];
# NixOS-generations -independent
installFirmwareBuilder = firmwareInstaller;
# NixOS-generations -dependent
inherit nixosGenerationsDir nixosGenBuilder;
};
});
bootloader = (
{
pkgs,
nixosGenerationsDir,
firmwareInstaller,
nixosGenBuilder,
}:
pkgs.replaceVarsWith {
src = ./generational/nixos-generations-builder.sh;
isExecutable = true;
replacements = {
inherit (pkgs) bash;
path = pkgs.lib.makeBinPath [
pkgs.coreutils
pkgs.gnused
];
# NixOS-generations -independent
installFirmwareBuilder = firmwareInstaller;
# NixOS-generations -dependent
inherit nixosGenerationsDir nixosGenBuilder;
};
}
);
# Builders used to write during system activation
@@ -130,20 +150,6 @@ let
extlinuxConfBuilder = config.boot.loader.generic-extlinux-compatible.populateCmd;
};
populateUbootBuilder = import ./uboot-builder.nix {
pkgs = pkgs.buildPackages;
ubootPackage = (
if (cfg.variant == "5") then pkgs.${namespace}.uboot-pi5 else pkgs.${namespace}.uboot-pi4
);
firmwareBuilder = firmwarePopulateCmd;
extlinuxConfBuilder = config.boot.loader.generic-extlinux-compatible.populateCmd;
};
kernelbootBuilder = import ./kernelboot-builder.nix {
inherit pkgs;
firmwareBuilder = firmwarePopulateCmd;
};
uefiBuilder = import ./uefi-builder.nix {
inherit pkgs;
uefiPackage = (
@@ -169,11 +175,6 @@ let
firmware = pkgs.${namespace}.raspberrypifw;
};
populateKernelbootBuilder = import ./kernelboot-builder.nix {
pkgs = pkgs.buildPackages;
firmwareBuilder = firmwarePopulateCmd;
};
firmwarePopulateCmd = "${populateFirmwareBuilder} ${firmwareBuilderArgs}";
firmwareBuilderArgs = lib.optionalString (!true) " -r";
@@ -190,23 +191,9 @@ let
"-c"
];
};
# firmware: caller must provide `-c <nixos configuration>` and `-f <firmware target path>`
# boot: caller must provide `-c <nixos configuration>` and `-b <boot-dir>`
populateCmds = {
uboot = {
firmware = "${populateUbootBuilder}";
boot = "${populateUbootBuilder}";
};
kernel = let cmd = builtins.concatStringsSep " " [
"${mkBootloader pkgs.buildPackages}"
"-g ${toString cfg.configurationLimit}"
];
in {
firmware = "${cmd}";
boot = "${cmd}";
};
};
in
{
options.${namespace}.hardware.raspberry-pi = {
@@ -326,19 +313,28 @@ in
};
kernel = lib.mkIf (cfg.bootType == "kernel" || cfg.bootType == "uboot") {
enable = true;
value = (if cfg.bootType == "uboot" then "u-boot.bin" else if cfg.bootType == "kernel" then "kernel.img" else "");
value = (
if cfg.bootType == "uboot" then
"u-boot.bin"
else if cfg.bootType == "kernel" then
"kernel.img"
else
""
);
};
};
};
};
extra-config = let
# https://www.raspberrypi.com/documentation/computers/config_txt.html#initramfs
ramfsfile = "initrd";
ramfsaddr = "followkernel"; # same as 0 = "after the kernel image"
in ''
[all]
initramfs ${ramfsfile} ${ramfsaddr}
'';
extra-config =
let
# https://www.raspberrypi.com/documentation/computers/config_txt.html#initramfs
ramfsfile = "initrd";
ramfsaddr = "followkernel"; # same as 0 = "after the kernel image"
in
''
[all]
initramfs ${ramfsfile} ${ramfsaddr}
'';
};
# Common hardware settings

View File

@@ -1,5 +1,6 @@
{ pkgs
, firmwareBuilder
{
pkgs,
firmwareBuilder,
}:
pkgs.replaceVarsWith {
@@ -16,4 +17,4 @@ pkgs.replaceVarsWith {
inherit firmwareBuilder;
copyKernels = true;
};
}
}