diff --git a/nixos/modules/config/sysmodule.nix b/nixos/modules/config/sysmodule.nix new file mode 100644 index 0000000000000..ec8e5277b8639 --- /dev/null +++ b/nixos/modules/config/sysmodule.nix @@ -0,0 +1,37 @@ +{ config, lib, ... }: +let + cfg = config.boot.kernel.sysmodule; + + kernelParamOptionType = lib.mkOptionType { + name = "kernel command-line parameters option value"; + check = + val: + let + checkType = x: lib.isBool x || lib.isString x || lib.isInt x || x == null; + in + checkType val || (val._type or "" == "override" && checkType val.content); + merge = loc: defs: lib.mergeOneOption loc (lib.filterOverrides defs); + }; + +in +{ + options.boot.kernel.sysmodule = lib.mkOption { + type = lib.types.submodule { + freeformType = lib.types.attrsOf (lib.types.attrsOf kernelParamOptionType); + }; + }; + + config.systemd.tmpfiles.settings.sysmodule = lib.listToAttrs ( + lib.concatLists ( + lib.mapAttrsToList ( + moduleName: v: + lib.mapAttrsToList (paramName: paramValue: { + name = "/sys/module/${moduleName}/parameters/${paramName}"; + value = lib.mkIf (paramValue != null) { + "w-".argument = if paramValue == false then "0" else toString paramValue; + }; + }) v + ) cfg + ) + ); +} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 4b487179231b6..134c3866cea41 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -29,6 +29,7 @@ ./config/stub-ld.nix ./config/swap.nix ./config/sysctl.nix + ./config/sysmodule.nix ./config/system-environment.nix ./config/system-path.nix ./config/terminfo.nix