mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
Merge pull request #181079 from profianinc/init/nixos/amd-sev
nixos/amd.sev: init
This commit is contained in:
commit
5ad2e70f95
3 changed files with 59 additions and 0 deletions
51
nixos/modules/hardware/cpu/amd-sev.nix
Normal file
51
nixos/modules/hardware/cpu/amd-sev.nix
Normal file
|
@ -0,0 +1,51 @@
|
|||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.hardware.cpu.amd.sev;
|
||||
defaultGroup = "sev";
|
||||
in
|
||||
with lib; {
|
||||
options.hardware.cpu.amd.sev = {
|
||||
enable = mkEnableOption "access to the AMD SEV device";
|
||||
user = mkOption {
|
||||
description = "Owner to assign to the SEV device.";
|
||||
type = types.str;
|
||||
default = "root";
|
||||
};
|
||||
group = mkOption {
|
||||
description = "Group to assign to the SEV device.";
|
||||
type = types.str;
|
||||
default = defaultGroup;
|
||||
};
|
||||
mode = mkOption {
|
||||
description = "Mode to set for the SEV device.";
|
||||
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}"
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue