diff --git a/modules/nixos/hardware/raspberry-pi/default.nix b/modules/nixos/hardware/raspberry-pi/default.nix index 2cfb035..0cdb2e9 100644 --- a/modules/nixos/hardware/raspberry-pi/default.nix +++ b/modules/nixos/hardware/raspberry-pi/default.nix @@ -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 ` and `-f ` # boot: caller must provide `-c ` and `-b ` - 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 diff --git a/modules/nixos/hardware/raspberry-pi/kernelboot-builder.nix b/modules/nixos/hardware/raspberry-pi/kernelboot-builder.nix index 6ba27a6..a2b4a22 100644 --- a/modules/nixos/hardware/raspberry-pi/kernelboot-builder.nix +++ b/modules/nixos/hardware/raspberry-pi/kernelboot-builder.nix @@ -1,5 +1,6 @@ -{ pkgs -, firmwareBuilder +{ + pkgs, + firmwareBuilder, }: pkgs.replaceVarsWith { @@ -16,4 +17,4 @@ pkgs.replaceVarsWith { inherit firmwareBuilder; copyKernels = true; }; -} \ No newline at end of file +}