1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 blCfg = config.boot.loader;
7 dtCfg = config.hardware.deviceTree;
8 cfg = blCfg.generic-extlinux-compatible;
9
10 timeoutStr = if blCfg.timeout == null then "-1" else toString blCfg.timeout;
11
12 # The builder used to write during system activation
13 builder = import ./extlinux-conf-builder.nix { inherit pkgs; };
14 # The builder exposed in populateCmd, which runs on the build architecture
15 populateBuilder = import ./extlinux-conf-builder.nix { pkgs = pkgs.buildPackages; };
16in
17{
18 options = {
19 boot.loader.generic-extlinux-compatible = {
20 enable = mkOption {
21 default = false;
22 type = types.bool;
23 description = ''
24 Whether to generate an extlinux-compatible configuration file
25 under <literal>/boot/extlinux.conf</literal>. For instance,
26 U-Boot's generic distro boot support uses this file format.
27
28 See <link xlink:href="http://git.denx.de/?p=u-boot.git;a=blob;f=doc/README.distro;hb=refs/heads/master">U-boot's documentation</link>
29 for more information.
30 '';
31 };
32
33 configurationLimit = mkOption {
34 default = 20;
35 example = 10;
36 type = types.int;
37 description = ''
38 Maximum number of configurations in the boot menu.
39 '';
40 };
41
42 populateCmd = mkOption {
43 type = types.str;
44 readOnly = true;
45 description = ''
46 Contains the builder command used to populate an image,
47 honoring all options except the <literal>-c <path-to-default-configuration></literal>
48 argument.
49 Useful to have for sdImage.populateRootCommands
50 '';
51 };
52
53 };
54 };
55
56 config = let
57 builderArgs = "-g ${toString cfg.configurationLimit} -t ${timeoutStr}" + lib.optionalString (dtCfg.name != null) " -n ${dtCfg.name}";
58 in
59 mkIf cfg.enable {
60 system.build.installBootLoader = "${builder} ${builderArgs} -c";
61 system.boot.loader.id = "generic-extlinux-compatible";
62
63 boot.loader.generic-extlinux-compatible.populateCmd = "${populateBuilder} ${builderArgs}";
64 };
65}