1 { config, options, lib, ... }:
3 cfgSev = config.hardware.cpu.amd.sev;
4 cfgSevGuest = config.hardware.cpu.amd.sevGuest;
6 optionsFor = device: group: {
7 enable = lib.mkEnableOption "access to the AMD ${device} device";
9 description = "Owner to assign to the ${device} device.";
13 group = lib.mkOption {
14 description = "Group to assign to the ${device} device.";
19 description = "Mode to set for the ${device} device.";
26 options.hardware.cpu.amd.sev = optionsFor "SEV" "sev";
28 options.hardware.cpu.amd.sevGuest = optionsFor "SEV guest" "sev-guest";
30 config = lib.mkMerge [
32 (lib.mkIf cfgSev.enable {
35 assertion = lib.hasAttr cfgSev.user config.users.users;
36 message = "Given user does not exist";
39 assertion = (cfgSev.group == options.hardware.cpu.amd.sev.group.default) || (lib.hasAttr cfgSev.group config.users.groups);
40 message = "Given group does not exist";
44 boot.extraModprobeConfig = ''
48 users.groups = lib.optionalAttrs (cfgSev.group == options.hardware.cpu.amd.sev.group.default) {
49 "${cfgSev.group}" = { };
52 services.udev.extraRules = with cfgSev; ''
53 KERNEL=="sev", OWNER="${user}", GROUP="${group}", MODE="${mode}"
58 (lib.mkIf cfgSevGuest.enable {
61 assertion = lib.hasAttr cfgSevGuest.user config.users.users;
62 message = "Given user does not exist";
65 assertion = (cfgSevGuest.group == options.hardware.cpu.amd.sevGuest.group.default) || (lib.hasAttr cfgSevGuest.group config.users.groups);
66 message = "Given group does not exist";
70 users.groups = lib.optionalAttrs (cfgSevGuest.group == options.hardware.cpu.amd.sevGuest.group.default) {
71 "${cfgSevGuest.group}" = { };
74 services.udev.extraRules = with cfgSevGuest; ''
75 KERNEL=="sev-guest", OWNER="${user}", GROUP="${group}", MODE="${mode}"