nix format
This commit is contained in:
@@ -15,109 +15,129 @@ let
|
|||||||
|
|
||||||
# installs raspberry's firmware independent of the nixos generations
|
# installs raspberry's firmware independent of the nixos generations
|
||||||
# sometimes referred to as "boot code"
|
# sometimes referred to as "boot code"
|
||||||
raspberryPiFirmware = ({ pkgs
|
raspberryPiFirmware = (
|
||||||
, firmware
|
{
|
||||||
, configTxt
|
pkgs,
|
||||||
}: pkgs.replaceVarsWith {
|
firmware,
|
||||||
src = ./generational/install-firmware.sh;
|
configTxt,
|
||||||
isExecutable = true;
|
}:
|
||||||
|
pkgs.replaceVarsWith {
|
||||||
|
src = ./generational/install-firmware.sh;
|
||||||
|
isExecutable = true;
|
||||||
|
|
||||||
replacements = {
|
replacements = {
|
||||||
inherit (pkgs) bash;
|
inherit (pkgs) bash;
|
||||||
path = pkgs.lib.makeBinPath [
|
path = pkgs.lib.makeBinPath [
|
||||||
pkgs.coreutils
|
pkgs.coreutils
|
||||||
];
|
];
|
||||||
|
|
||||||
inherit firmware configTxt;
|
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}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}}";
|
}
|
||||||
|
);
|
||||||
|
|
||||||
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;
|
inherit pkgs;
|
||||||
deviceTreeInstaller = let
|
inherit (cfg) nixosGenerationsDir;
|
||||||
cmd = deviceTree {
|
|
||||||
inherit pkgs;
|
firmwareInstaller = "${raspberryPiFirmware {
|
||||||
firmware = cfg.firmwarePackage;
|
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
|
# Builders used to write during system activation
|
||||||
|
|
||||||
@@ -130,20 +150,6 @@ let
|
|||||||
extlinuxConfBuilder = config.boot.loader.generic-extlinux-compatible.populateCmd;
|
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 {
|
uefiBuilder = import ./uefi-builder.nix {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
uefiPackage = (
|
uefiPackage = (
|
||||||
@@ -169,11 +175,6 @@ let
|
|||||||
firmware = pkgs.${namespace}.raspberrypifw;
|
firmware = pkgs.${namespace}.raspberrypifw;
|
||||||
};
|
};
|
||||||
|
|
||||||
populateKernelbootBuilder = import ./kernelboot-builder.nix {
|
|
||||||
pkgs = pkgs.buildPackages;
|
|
||||||
firmwareBuilder = firmwarePopulateCmd;
|
|
||||||
};
|
|
||||||
|
|
||||||
firmwarePopulateCmd = "${populateFirmwareBuilder} ${firmwareBuilderArgs}";
|
firmwarePopulateCmd = "${populateFirmwareBuilder} ${firmwareBuilderArgs}";
|
||||||
firmwareBuilderArgs = lib.optionalString (!true) " -r";
|
firmwareBuilderArgs = lib.optionalString (!true) " -r";
|
||||||
|
|
||||||
@@ -190,23 +191,9 @@ let
|
|||||||
"-c"
|
"-c"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
# firmware: caller must provide `-c <nixos configuration>` and `-f <firmware target path>`
|
# firmware: caller must provide `-c <nixos configuration>` and `-f <firmware target path>`
|
||||||
# boot: caller must provide `-c <nixos configuration>` and `-b <boot-dir>`
|
# 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
|
in
|
||||||
{
|
{
|
||||||
options.${namespace}.hardware.raspberry-pi = {
|
options.${namespace}.hardware.raspberry-pi = {
|
||||||
@@ -326,19 +313,28 @@ in
|
|||||||
};
|
};
|
||||||
kernel = lib.mkIf (cfg.bootType == "kernel" || cfg.bootType == "uboot") {
|
kernel = lib.mkIf (cfg.bootType == "kernel" || cfg.bootType == "uboot") {
|
||||||
enable = true;
|
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
|
extra-config =
|
||||||
# https://www.raspberrypi.com/documentation/computers/config_txt.html#initramfs
|
let
|
||||||
ramfsfile = "initrd";
|
# https://www.raspberrypi.com/documentation/computers/config_txt.html#initramfs
|
||||||
ramfsaddr = "followkernel"; # same as 0 = "after the kernel image"
|
ramfsfile = "initrd";
|
||||||
in ''
|
ramfsaddr = "followkernel"; # same as 0 = "after the kernel image"
|
||||||
[all]
|
in
|
||||||
initramfs ${ramfsfile} ${ramfsaddr}
|
''
|
||||||
'';
|
[all]
|
||||||
|
initramfs ${ramfsfile} ${ramfsaddr}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
# Common hardware settings
|
# Common hardware settings
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{ pkgs
|
{
|
||||||
, firmwareBuilder
|
pkgs,
|
||||||
|
firmwareBuilder,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
pkgs.replaceVarsWith {
|
pkgs.replaceVarsWith {
|
||||||
@@ -16,4 +17,4 @@ pkgs.replaceVarsWith {
|
|||||||
inherit firmwareBuilder;
|
inherit firmwareBuilder;
|
||||||
copyKernels = true;
|
copyKernels = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user