Hi,
I am trying to convert the current kernel config process from a string to a structured attrset (https://github.com/NixOS/nixpkgs/pull/41393), i.e., from the legacy:
linux_latest_9p = prev.pkgs.linux_latest.override({
extraConfig = ''
NET_9P y
NET_9P_VIRTIO y
NET_9P_DEBUG y
'';
});
to the desired
linux_latest_9p = prev.pkgs.linux_latest.override({
extraStructuredConfig = {
NET_9P = yes;
NET_9P_VIRTIO = yes;
NET_9P_DEBUG = yes;
};
});
Among the motivations is the ability to merge different configs so that programs can specify required dependencies (e.g., if you enable the openvswitch module, hopefully it should enable CONFIG_OPENVSWITCH ).
Instead of rewriting the merging logic (e.g., how to merge the 2 configs { NET_9P_DEBUG = yes; } and { NET_9P_DEBUG = no; }), I thought I could reuse the module logic mkMerge/mkIf etc. but this proves harder than I thought.
It seems the module system expects a list of paths config.foo.bar
for any operation. I don’t want to rely on a single option boot.kernel.config, I want to use the lib/types.nix to “typecheck” the structured config of different kernels each with their own configuration. Each configuration entry should conform to
kernelItem = types.submodule {
options = {
answer = mkOption {
type = types.str;
default = null;
internal = true;
description = ''
For most options "y" or "m" or "n" but freeform.
'';
};
optional = mkOption {
type = types.bool;
default = false;
internal = true;
description = ''
Wether it should fail if not asked.
'';
};
};
};
Then I tried different things to merge the 2 configs { NET_9P_DEBUG = yes; } and { NET_9P_DEBUG = no; } but it is not straightforward.
Playing with the REPL I found out that I could merge two booleans via lib.types.bool.merge [] [{ value = false; file="papa"; } {value = true; file="toto";} ]
.
I proceeded likewise to run kernelItem.merge to merge 2 structured configs:
kernelItem.merge [ { file= “PLACEHOLDER”; value = { NET_9P_DEBUG = no; };} { file=“PLACEHOLDER”; value = { NET_9P_DEBUG = yes; optional = true; }; } ]
but I run into further trouble:
while evaluating the attribute '"9P_FSCACHE"' at /home/teto/nixpkgs3/lib/attrsets.nix:200:46:
while evaluating 'option' at /home/teto/nixpkgs3/lib/kernel.nix:53:12, called from /home/teto/nixpkgs3/pkgs/os-specific/linux/kernel/common-config.nix:473:27:
while evaluating 'traceValSeqFn' at /home/teto/nixpkgs3/lib/debug.nix:80:22, called from /home/teto/nixpkgs3/lib/kernel.nix:60:5:
while evaluating 'traceValFn' at /home/teto/nixpkgs3/lib/debug.nix:42:19, called from /home/teto/nixpkgs3/lib/debug.nix:80:25:
while evaluating 'id' at /home/teto/nixpkgs3/lib/trivial.nix:46:8, called from /home/teto/nixpkgs3/lib/debug.nix:42:29:
while evaluating the attribute '_module' at /home/teto/nixpkgs3/lib/attrsets.nix:200:46:
while evaluating the attribute 'args' at /home/teto/nixpkgs3/lib/attrsets.nix:200:46:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/modules.nix:75:45, called from /home/teto/nixpkgs3/lib/attrsets.nix:200:54:
while evaluating the attribute 'value' at /home/teto/nixpkgs3/lib/modules.nix:312:9:
while evaluating the option `_module.args':
while evaluating the attribute 'mergedValue' at /home/teto/nixpkgs3/lib/modules.nix:345:5:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/modules.nix:345:32, called from /home/teto/nixpkgs3/lib/modules.nix:345:19:
while evaluating 'merge' at /home/teto/nixpkgs3/lib/types.nix:274:20, called from /home/teto/nixpkgs3/lib/modules.nix:348:8:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/attrsets.nix:199:9, called from /home/teto/nixpkgs3/lib/types.nix:275:9:
while evaluating 'filterAttrs' at /home/teto/nixpkgs3/lib/attrsets.nix:115:23, called from /home/teto/nixpkgs3/lib/types.nix:275:35:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/lists.nix:104:41, called from /home/teto/nixpkgs3/lib/attrsets.nix:116:18:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/attrsets.nix:116:29, called from undefined position:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/types.nix:275:51, called from /home/teto/nixpkgs3/lib/attrsets.nix:116:62:
while evaluating the attribute 'name' at /home/teto/nixpkgs3/lib/attrsets.nix:335:7:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/types.nix:275:86, called from /home/teto/nixpkgs3/lib/attrsets.nix:335:15:
while evaluating the attribute 'optionalValue' at /home/teto/nixpkgs3/lib/modules.nix:352:5:
while evaluating the attribute 'values' at /home/teto/nixpkgs3/lib/modules.nix:338:9:
while evaluating the attribute 'values' at /home/teto/nixpkgs3/lib/modules.nix:434:7:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/lists.nix:104:41, called from /home/teto/nixpkgs3/lib/modules.nix:434:16:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/lists.nix:104:41, called from /home/teto/nixpkgs3/lib/modules.nix:324:17:
while evaluating anonymous function at /home/teto/nixpkgs3/lib/modules.nix:324:28, called from undefined position:
while evaluating 'dischargeProperties' at /home/teto/nixpkgs3/lib/modules.nix:392:25, called from /home/teto/nixpkgs3/lib/modules.nix:325:62:
while evaluating the attribute 'value' at /home/teto/nixpkgs3/lib/types.nix:280:55:
while evaluating the attribute 'name' at /home/teto/nixpkgs3/lib/types.nix:368:13:
while evaluating 'last' at /home/teto/nixpkgs3/lib/lists.nix:512:10, called from /home/teto/nixpkgs3/lib/types.nix:368:25:
assertion failed at /home/teto/nixpkgs3/lib/lists.nix:513:5
I wonder if something similar is done anywhere in nixpkgs (i.e., bypass the whole module creation
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.mymodule;
in {
options.mymodule = {
};
config = mkIf cfg.enable ( ... )
};
to directly call mkMerge on submodules and retrieve the merged value as in mkMerge [{ NET_9P_DEBUG = yes; } { NET_9P_DEBUG = no; }]
returns sthg like NET_9P_DEBUG = yes;
NB: I already asked this on IRC without much success but I hope my request is clearer with more context.