Skip to content

Add boot.kernel.sysctl and boot.kernelModules support #382

@yuxqiu

Description

@yuxqiu

Is your feature request related to a problem? Please describe.
I want to import the docker module directly from NixOS. Right now, it does work (by defining some options), but at the cost of some things potentially not being set up correctly.

Describe the solution you'd like
It would be nice to add support for boot.kernel.sysctl by directly importing (nixosModulesPath + "/config/sysctl.nix") and for boot.kernelModules by adapting nixos/modules/system/boot/kernel.nix as shown below.

{lib, ...}:
let
  modulesTypeDesc = ''
    This can either be a list of modules, or an attrset. In an
    attrset, names that are set to `true` represent modules that will
    be included. Note that setting these names to `false` does not
    prevent the module from being loaded. For that, use
    {option}`boot.blacklistedKernelModules`.
  '';
  kernelModulesConf = pkgs.writeText "nixos.conf" ''
    ${lib.concatStringsSep "\n" config.boot.kernelModules}
  '';
  attrNamesToTrue = lib.types.coercedTo (lib.types.listOf lib.types.str) (
    enabledList: lib.genAttrs enabledList (_attrName: true)
  ) (lib.types.attrsOf lib.types.bool);
in
{
  options.boot.kernelModules = lib.mkOption {
    type = attrNamesToTrue;
    default = { };
    description = ''
      The set of kernel modules to be loaded in the second stage of
      the boot process. Note that modules that are needed to
      mount the root file system should be added to
      {option}`boot.initrd.availableKernelModules` or
      {option}`boot.initrd.kernelModules`.
      ${modulesTypeDesc}
    '';
    apply = mods: lib.attrNames (lib.filterAttrs (_: v: v) mods);
  };
  config = lib.mkIf (config.boot.kernelModules != { }) {
    # Create /etc/modules-load.d/nixos.conf, which is read by
    # systemd-modules-load.service to load required kernel modules.
    environment.etc = {
      "modules-load.d/nixos.conf".source = kernelModulesConf;
    };
  };
}

However, the only issue is that we can no longer set

boot = lib.mkOption {
  type = lib.types.raw;
};

anymore, which is also why the aforementioned things cannot be done locally but must be implemented in this repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions