mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-11 04:05:40 +03:00

After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
113 lines
3.2 KiB
Nix
113 lines
3.2 KiB
Nix
{
|
|
lib,
|
|
config,
|
|
options,
|
|
...
|
|
}:
|
|
let
|
|
inherit (builtins) hasAttr;
|
|
inherit (lib) mkIf;
|
|
cfg = config.hardware.cpu.x86.msr;
|
|
opt = options.hardware.cpu.x86.msr;
|
|
defaultGroup = "msr";
|
|
isDefaultGroup = cfg.group == defaultGroup;
|
|
set = "to set for devices of the `msr` kernel subsystem.";
|
|
|
|
# Generates `foo=bar` parameters to pass to the kernel.
|
|
# If `module = baz` is passed, generates `baz.foo=bar`.
|
|
# Adds double quotes on demand to handle `foo="bar baz"`.
|
|
kernelParam =
|
|
{
|
|
module ? null,
|
|
}:
|
|
name: value:
|
|
assert lib.asserts.assertMsg (
|
|
!lib.strings.hasInfix "=" name
|
|
) "kernel parameter cannot have '=' in name";
|
|
let
|
|
key = (if module == null then "" else module + ".") + name;
|
|
valueString = lib.generators.mkValueStringDefault { } value;
|
|
quotedValueString =
|
|
if lib.strings.hasInfix " " valueString then
|
|
lib.strings.escape [ "\"" ] valueString
|
|
else
|
|
valueString;
|
|
in
|
|
"${key}=${quotedValueString}";
|
|
msrKernelParam = kernelParam { module = "msr"; };
|
|
in
|
|
{
|
|
options.hardware.cpu.x86.msr =
|
|
with lib.options;
|
|
with lib.types;
|
|
{
|
|
enable = mkEnableOption "the `msr` (Model-Specific Registers) kernel module and configure `udev` rules for its devices (usually `/dev/cpu/*/msr`)";
|
|
owner = mkOption {
|
|
type = str;
|
|
default = "root";
|
|
example = "nobody";
|
|
description = "Owner ${set}";
|
|
};
|
|
group = mkOption {
|
|
type = str;
|
|
default = defaultGroup;
|
|
example = "nobody";
|
|
description = "Group ${set}";
|
|
};
|
|
mode = mkOption {
|
|
type = str;
|
|
default = "0640";
|
|
example = "0660";
|
|
description = "Mode ${set}";
|
|
};
|
|
settings = mkOption {
|
|
type = submodule {
|
|
freeformType = attrsOf (oneOf [
|
|
bool
|
|
int
|
|
str
|
|
]);
|
|
options.allow-writes = mkOption {
|
|
type = nullOr (enum [
|
|
"on"
|
|
"off"
|
|
]);
|
|
default = null;
|
|
description = "Whether to allow writes to MSRs (`\"on\"`) or not (`\"off\"`).";
|
|
};
|
|
};
|
|
default = { };
|
|
description = "Parameters for the `msr` kernel module.";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
assertions = [
|
|
{
|
|
assertion = hasAttr cfg.owner config.users.users;
|
|
message = "Owner '${cfg.owner}' set in `${opt.owner}` is not configured via `${options.users.users}.\"${cfg.owner}\"`.";
|
|
}
|
|
{
|
|
assertion = isDefaultGroup || (hasAttr cfg.group config.users.groups);
|
|
message = "Group '${cfg.group}' set in `${opt.group}` is not configured via `${options.users.groups}.\"${cfg.group}\"`.";
|
|
}
|
|
];
|
|
|
|
boot = {
|
|
kernelModules = [ "msr" ];
|
|
kernelParams = lib.attrsets.mapAttrsToList msrKernelParam (
|
|
lib.attrsets.filterAttrs (_: value: value != null) cfg.settings
|
|
);
|
|
};
|
|
|
|
users.groups.${cfg.group} = mkIf isDefaultGroup { };
|
|
|
|
services.udev.extraRules = ''
|
|
SUBSYSTEM=="msr", OWNER="${cfg.owner}", GROUP="${cfg.group}", MODE="${cfg.mode}"
|
|
'';
|
|
};
|
|
|
|
meta = with lib; {
|
|
maintainers = with maintainers; [ lorenzleutgeb ];
|
|
};
|
|
}
|