2022-07-11 11:33:06 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.hardware.cpu.amd.sev;
|
|
|
|
defaultGroup = "sev";
|
|
|
|
in
|
|
|
|
with lib; {
|
|
|
|
options.hardware.cpu.amd.sev = {
|
2022-08-28 20:18:44 +01:00
|
|
|
enable = mkEnableOption (lib.mdDoc "access to the AMD SEV device");
|
2022-07-11 11:33:06 +01:00
|
|
|
user = mkOption {
|
2022-08-15 06:16:25 +01:00
|
|
|
description = lib.mdDoc "Owner to assign to the SEV device.";
|
2022-07-11 11:33:06 +01:00
|
|
|
type = types.str;
|
|
|
|
default = "root";
|
|
|
|
};
|
|
|
|
group = mkOption {
|
2022-08-15 06:16:25 +01:00
|
|
|
description = lib.mdDoc "Group to assign to the SEV device.";
|
2022-07-11 11:33:06 +01:00
|
|
|
type = types.str;
|
|
|
|
default = defaultGroup;
|
|
|
|
};
|
|
|
|
mode = mkOption {
|
2022-08-15 06:16:25 +01:00
|
|
|
description = lib.mdDoc "Mode to set for the SEV device.";
|
2022-07-11 11:33:06 +01:00
|
|
|
type = types.str;
|
|
|
|
default = "0660";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = hasAttr cfg.user config.users.users;
|
|
|
|
message = "Given user does not exist";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = (cfg.group == defaultGroup) || (hasAttr cfg.group config.users.groups);
|
|
|
|
message = "Given group does not exist";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
boot.extraModprobeConfig = ''
|
|
|
|
options kvm_amd sev=1
|
|
|
|
'';
|
|
|
|
|
|
|
|
users.groups = optionalAttrs (cfg.group == defaultGroup) {
|
|
|
|
"${cfg.group}" = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.udev.extraRules = with cfg; ''
|
|
|
|
KERNEL=="sev", OWNER="${user}", GROUP="${group}", MODE="${mode}"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|