nixos/amd.sev: init

Signed-off-by: Roman Volosatovs <roman@profian.com>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
This commit is contained in:
Roman Volosatovs 2022-07-11 12:33:06 +02:00
parent e9109d950b
commit 191f777c4a
No known key found for this signature in database
GPG Key ID: 216DD5F8CA6618A1
3 changed files with 59 additions and 0 deletions

View File

@ -357,6 +357,12 @@
application tries to talk to the libsecret D-Bus API.
</para>
</listitem>
<listitem>
<para>
There is a new module for AMD SEV CPU functionality, which
grants access to the hardware.
</para>
</listitem>
<listitem>
<para>
There is a new module for the <literal>thunar</literal>

View File

@ -132,6 +132,8 @@ Use `configure.packages` instead.
- The `pass-secret-service` package now includes systemd units from upstream, so adding it to the NixOS `services.dbus.packages` option will make it start automatically as a systemd user service when an application tries to talk to the libsecret D-Bus API.
- There is a new module for AMD SEV CPU functionality, which grants access to the hardware.
- There is a new module for the `thunar` program (the Xfce file manager), which depends on the `xfconf` dbus service, and also has a dbus service and a systemd unit. The option `services.xserver.desktopManager.xfce.thunarPlugins` has been renamed to `programs.thunar.plugins`, and in a future release it may be removed.
- There is a new module for the `xfconf` program (the Xfce configuration storage system), which has a dbus service.

View 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}"
'';
};
}