mirror of
https://github.com/nix-community/raspberry-pi-nix.git
synced 2025-12-03 15:41:00 +01:00
use make-disk-image instead of sd-image
This commit is contained in:
parent
aaec735faf
commit
fb248c0047
17 changed files with 570 additions and 229 deletions
132
generic-extlinux-compatible/generic-extlinux-compatible.nix
Normal file
132
generic-extlinux-compatible/generic-extlinux-compatible.nix
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
blCfg = config.boot.loader;
|
||||
dtCfg = config.hardware.deviceTree;
|
||||
cfg = blCfg.generic-extlinux-compatible-pi-loader;
|
||||
|
||||
timeoutStr = if blCfg.timeout == null then "-1" else toString blCfg.timeout;
|
||||
|
||||
# The builder used to write during system activation
|
||||
builder = import ./extlinux-conf-builder.nix { inherit pkgs; };
|
||||
# The builder exposed in populateCmd, which runs on the build architecture
|
||||
populateBuilder = import ./extlinux-conf-builder.nix { pkgs = pkgs.buildPackages; };
|
||||
in
|
||||
{
|
||||
options = {
|
||||
boot.loader.generic-extlinux-compatible-pi-loader = {
|
||||
enable = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
description = ''
|
||||
Whether to generate an extlinux-compatible configuration file
|
||||
under `/boot/extlinux.conf`. For instance,
|
||||
U-Boot's generic distro boot support uses this file format.
|
||||
|
||||
See [U-boot's documentation](https://u-boot.readthedocs.io/en/latest/develop/distro.html)
|
||||
for more information.
|
||||
'';
|
||||
};
|
||||
|
||||
useGenerationDeviceTree = mkOption {
|
||||
default = true;
|
||||
type = types.bool;
|
||||
description = ''
|
||||
Whether to generate Device Tree-related directives in the
|
||||
extlinux configuration.
|
||||
|
||||
When enabled, the bootloader will attempt to load the device
|
||||
tree binaries from the generation's kernel.
|
||||
|
||||
Note that this affects all generations, regardless of the
|
||||
setting value used in their configurations.
|
||||
'';
|
||||
};
|
||||
|
||||
configurationLimit = mkOption {
|
||||
default = 20;
|
||||
example = 10;
|
||||
type = types.int;
|
||||
description = ''
|
||||
Maximum number of configurations in the boot menu.
|
||||
'';
|
||||
};
|
||||
|
||||
mirroredBoots = mkOption {
|
||||
default = [ { path = "/boot"; } ];
|
||||
example = [
|
||||
{ path = "/boot1"; }
|
||||
{ path = "/boot2"; }
|
||||
];
|
||||
description = ''
|
||||
Mirror the boot configuration to multiple paths.
|
||||
'';
|
||||
|
||||
type = with types; listOf (submodule {
|
||||
options = {
|
||||
path = mkOption {
|
||||
example = "/boot1";
|
||||
type = types.str;
|
||||
description = ''
|
||||
The path to the boot directory where the extlinux-compatible
|
||||
configuration files will be written.
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
populateCmd = mkOption {
|
||||
type = types.str;
|
||||
readOnly = true;
|
||||
description = ''
|
||||
Contains the builder command used to populate an image,
|
||||
honoring all options except the `-c <path-to-default-configuration>`
|
||||
argument.
|
||||
Useful to have for sdImage.populateRootCommands
|
||||
'';
|
||||
};
|
||||
|
||||
extraCommandsAfter = mkOption {
|
||||
type = types.listOf types.str;
|
||||
description = ''
|
||||
Optional commands to run after installing the bootloader.
|
||||
Useful for putting Raspberry Pi firmwares on the boot partition.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
config = let
|
||||
builderArgs = "-g ${toString cfg.configurationLimit} -t ${timeoutStr}"
|
||||
+ lib.optionalString (dtCfg.name != null) " -n ${dtCfg.name}"
|
||||
+ lib.optionalString (!cfg.useGenerationDeviceTree) " -r";
|
||||
installBootLoader = pkgs.writeScript "install-extlinux-conf.sh" (''
|
||||
#!${pkgs.runtimeShell}
|
||||
set -e
|
||||
'' + flip concatMapStrings cfg.mirroredBoots (args: ''
|
||||
${builder} ${builderArgs} -d '${args.path}' -c "$@"
|
||||
'') + ''
|
||||
${lib.concatLines cfg.extraCommandsAfter}
|
||||
'');
|
||||
in
|
||||
mkIf cfg.enable {
|
||||
system.build.installBootLoader = installBootLoader;
|
||||
system.boot.loader.id = "generic-extlinux-compatible-pi-loader";
|
||||
|
||||
boot.loader.generic-extlinux-compatible-pi-loader.populateCmd = "${populateBuilder} ${builderArgs}";
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = cfg.mirroredBoots != [ ];
|
||||
message = ''
|
||||
You must not remove all elements from option 'boot.loader.generic-extlinux-compatible-pi-loader.mirroredBoots',
|
||||
otherwise the system will not be bootable.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue