2021-12-19 01:06:50 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
2022-01-13 20:06:32 +00:00
|
|
|
cfg = config.hardware.cpu.intel.sgx;
|
|
|
|
defaultPrvGroup = "sgx_prv";
|
2021-12-19 01:06:50 +00:00
|
|
|
in
|
|
|
|
{
|
2022-01-13 20:06:32 +00:00
|
|
|
options.hardware.cpu.intel.sgx.enableDcapCompat = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-01-13 20:06:32 +00:00
|
|
|
Whether to enable backward compatibility for SGX software build for the
|
|
|
|
out-of-tree Intel SGX DCAP driver.
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
Creates symbolic links for the SGX devices `/dev/sgx_enclave`
|
|
|
|
and `/dev/sgx_provision` to make them available as
|
|
|
|
`/dev/sgx/enclave` and `/dev/sgx/provision`,
|
2022-01-13 20:06:32 +00:00
|
|
|
respectively.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
options.hardware.cpu.intel.sgx.provision = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "access to the Intel SGX provisioning device");
|
2021-12-19 01:06:50 +00:00
|
|
|
user = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Owner to assign to the SGX provisioning device.";
|
2021-12-19 01:06:50 +00:00
|
|
|
type = types.str;
|
|
|
|
default = "root";
|
|
|
|
};
|
|
|
|
group = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Group to assign to the SGX provisioning device.";
|
2021-12-19 01:06:50 +00:00
|
|
|
type = types.str;
|
2022-01-13 20:06:32 +00:00
|
|
|
default = defaultPrvGroup;
|
2021-12-19 01:06:50 +00:00
|
|
|
};
|
|
|
|
mode = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Mode to set for the SGX provisioning device.";
|
2021-12-19 01:06:50 +00:00
|
|
|
type = types.str;
|
|
|
|
default = "0660";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
config = mkMerge [
|
|
|
|
(mkIf cfg.provision.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = hasAttr cfg.provision.user config.users.users;
|
|
|
|
message = "Given user does not exist";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = (cfg.provision.group == defaultPrvGroup) || (hasAttr cfg.provision.group config.users.groups);
|
|
|
|
message = "Given group does not exist";
|
|
|
|
}
|
|
|
|
];
|
2021-12-19 01:06:50 +00:00
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
users.groups = optionalAttrs (cfg.provision.group == defaultPrvGroup) {
|
|
|
|
"${cfg.provision.group}" = { };
|
|
|
|
};
|
2021-12-19 01:06:50 +00:00
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
services.udev.extraRules = with cfg.provision; ''
|
|
|
|
SUBSYSTEM=="misc", KERNEL=="sgx_provision", OWNER="${user}", GROUP="${group}", MODE="${mode}"
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
(mkIf cfg.enableDcapCompat {
|
|
|
|
services.udev.extraRules = ''
|
|
|
|
SUBSYSTEM=="misc", KERNEL=="sgx_enclave", SYMLINK+="sgx/enclave"
|
|
|
|
SUBSYSTEM=="misc", KERNEL=="sgx_provision", SYMLINK+="sgx/provision"
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
2021-12-19 01:06:50 +00:00
|
|
|
}
|