diff --git a/devices/turris-omnia/default.nix b/devices/turris-omnia/default.nix index 2a15a13..9c3d333 100644 --- a/devices/turris-omnia/default.nix +++ b/devices/turris-omnia/default.nix @@ -132,9 +132,6 @@ PHY_MVEBU_A38X_COMPHY = "y"; # for eth2 MARVELL_PHY = "y"; - USB_XHCI_MVEBU = "y"; - USB_XHCI_HCD = "y"; - MVPP2 = "y"; MV_XOR = "y"; @@ -150,6 +147,12 @@ NET_DSA = "y"; NET_DSA_MV88E6XXX = "y"; # depends on PTP_1588_CLOCK_OPTIONAL }; + conditionalConfig = { + USB = { + USB_XHCI_MVEBU = "y"; + USB_XHCI_HCD = "y"; + }; + }; }; boot = { diff --git a/modules/kernel.nix b/modules/kernel.nix index 81e7201..f10e3d7 100644 --- a/modules/kernel.nix +++ b/modules/kernel.nix @@ -13,6 +13,16 @@ let type_service = pkgs.liminix.lib.types.service; + mergeConditionals = conf : conditions : + # for each key in conditions, if it is present in conf + # then merge the associated value into conf + lib.foldlAttrs + (acc: name: value: + if (conf ? ${name}) && (conf.${name} != "n") + then acc // value + else acc) + conf + conditions; in { options = { kernel = { @@ -42,6 +52,20 @@ in { }; ''; }; + conditionalConfig = mkOption { + description = '' + Kernel config options that should only be applied when + some other option is present. + ''; + type = types.attrsOf (types.attrsOf types.nonEmptyStr); + default = {}; + example = { + USB = { + USB_XHCI_MVEBU = "y"; + USB_XHCI_HCD = "y"; + }; + }; + }; makeTargets = mkOption { type = types.listOf types.str; }; @@ -49,10 +73,15 @@ in { }; config = { system.outputs = - let k = liminix.builders.kernel.override { - inherit (config.kernel) config src extraPatchPhase; - targets = config.kernel.makeTargets; - }; + let + mergedConfig = mergeConditionals + config.kernel.config + config.kernel.conditionalConfig; + k = liminix.builders.kernel.override { + config = mergedConfig; + inherit (config.kernel) src extraPatchPhase; + targets = config.kernel.makeTargets; + }; in { kernel = k.vmlinux; zimage = k.zImage;