2018-10-03 18:49:50 +09:00
|
|
|
{ lib, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2024-12-10 20:26:33 +01:00
|
|
|
mergeFalseByDefault =
|
|
|
|
locs: defs:
|
|
|
|
if defs == [ ] then
|
|
|
|
abort "This case should never happen."
|
|
|
|
else if any (x: x == false) (getValues defs) then
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true;
|
2018-10-03 18:49:50 +09:00
|
|
|
|
|
|
|
kernelItem = types.submodule {
|
|
|
|
options = {
|
|
|
|
tristate = mkOption {
|
2024-12-10 20:26:33 +01:00
|
|
|
type = types.enum [
|
|
|
|
"y"
|
|
|
|
"m"
|
|
|
|
"n"
|
|
|
|
null
|
|
|
|
];
|
2018-10-03 18:49:50 +09:00
|
|
|
default = null;
|
|
|
|
internal = true;
|
|
|
|
visible = true;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2018-10-03 18:49:50 +09:00
|
|
|
Use this field for tristate kernel options expecting a "y" or "m" or "n".
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
freeform = mkOption {
|
|
|
|
type = types.nullOr types.str // {
|
|
|
|
merge = mergeEqualOption;
|
|
|
|
};
|
|
|
|
default = null;
|
|
|
|
example = ''MMC_BLOCK_MINORS.freeform = "32";'';
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2018-10-03 18:49:50 +09:00
|
|
|
Freeform description of a kernel configuration item value.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
optional = mkOption {
|
2024-12-10 20:26:33 +01:00
|
|
|
type = types.bool // {
|
|
|
|
merge = mergeFalseByDefault;
|
|
|
|
};
|
2018-10-03 18:49:50 +09:00
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2020-07-04 15:15:26 +02:00
|
|
|
Whether option should generate a failure when unused.
|
2020-04-01 03:20:33 +02:00
|
|
|
Upon merging values, mandatory wins over optional.
|
2018-10-03 18:49:50 +09:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-10 20:26:33 +01:00
|
|
|
mkValue =
|
|
|
|
with lib;
|
|
|
|
val:
|
|
|
|
let
|
|
|
|
isNumber =
|
|
|
|
c:
|
|
|
|
elem c [
|
|
|
|
"0"
|
|
|
|
"1"
|
|
|
|
"2"
|
|
|
|
"3"
|
|
|
|
"4"
|
|
|
|
"5"
|
|
|
|
"6"
|
|
|
|
"7"
|
|
|
|
"8"
|
|
|
|
"9"
|
|
|
|
];
|
2018-10-03 18:49:50 +09:00
|
|
|
|
2024-12-10 20:26:33 +01:00
|
|
|
in
|
|
|
|
if (val == "") then
|
|
|
|
"\"\""
|
|
|
|
else if val == "y" || val == "m" || val == "n" then
|
|
|
|
val
|
|
|
|
else if all isNumber (stringToCharacters val) then
|
|
|
|
val
|
|
|
|
else if substring 0 2 val == "0x" then
|
|
|
|
val
|
|
|
|
else
|
|
|
|
val; # FIXME: fix quoting one day
|
2018-10-03 18:49:50 +09:00
|
|
|
|
|
|
|
# generate nix intermediate kernel config file of the form
|
|
|
|
#
|
|
|
|
# VIRTIO_MMIO m
|
|
|
|
# VIRTIO_BLK y
|
|
|
|
# VIRTIO_CONSOLE n
|
|
|
|
# NET_9P_VIRTIO? y
|
|
|
|
#
|
|
|
|
# Borrowed from copumpkin https://github.com/NixOS/nixpkgs/pull/12158
|
|
|
|
# returns a string, expr should be an attribute set
|
|
|
|
# Use mkValuePreprocess to preprocess option values, aka mark 'modules' as 'yes' or vice-versa
|
|
|
|
# use the identity if you don't want to override the configured values
|
2024-12-10 20:26:33 +01:00
|
|
|
generateNixKConf =
|
|
|
|
exprs:
|
|
|
|
let
|
|
|
|
mkConfigLine =
|
|
|
|
key: item:
|
|
|
|
let
|
|
|
|
val = if item.freeform != null then item.freeform else item.tristate;
|
|
|
|
in
|
|
|
|
optionalString (val != null) (
|
|
|
|
if (item.optional) then "${key}? ${mkValue val}\n" else "${key} ${mkValue val}\n"
|
|
|
|
);
|
2018-10-03 18:49:50 +09:00
|
|
|
|
2024-12-10 20:26:33 +01:00
|
|
|
mkConf = cfg: concatStrings (mapAttrsToList mkConfigLine cfg);
|
|
|
|
in
|
|
|
|
mkConf exprs;
|
2018-10-03 18:49:50 +09:00
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
intermediateNixConfig = mkOption {
|
|
|
|
readOnly = true;
|
|
|
|
type = types.lines;
|
|
|
|
example = ''
|
|
|
|
USB? y
|
|
|
|
DEBUG n
|
|
|
|
'';
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2018-10-03 18:49:50 +09:00
|
|
|
The result of converting the structured kernel configuration in settings
|
|
|
|
to an intermediate string that can be parsed by generate-config.pl to
|
|
|
|
answer the kernel `make defconfig`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrsOf kernelItem;
|
2024-12-10 20:26:33 +01:00
|
|
|
example = literalExpression ''
|
|
|
|
with lib.kernel; {
|
|
|
|
"9P_NET" = yes;
|
|
|
|
USB = option yes;
|
|
|
|
MMC_BLOCK_MINORS = freeform "32";
|
|
|
|
}'';
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2018-10-03 18:49:50 +09:00
|
|
|
Structured kernel configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
intermediateNixConfig = generateNixKConf config.settings;
|
|
|
|
};
|
|
|
|
}
|