3 cfg = config.hardware.cpu.intel.sgx;
4 defaultPrvGroup = "sgx_prv";
7 options.hardware.cpu.intel.sgx.enableDcapCompat = lib.mkOption {
9 Whether to enable backward compatibility for SGX software build for the
10 out-of-tree Intel SGX DCAP driver.
12 Creates symbolic links for the SGX devices `/dev/sgx_enclave`
13 and `/dev/sgx_provision` to make them available as
14 `/dev/sgx/enclave` and `/dev/sgx/provision`,
17 type = lib.types.bool;
21 options.hardware.cpu.intel.sgx.provision = {
22 enable = lib.mkEnableOption "access to the Intel SGX provisioning device";
24 description = "Owner to assign to the SGX provisioning device.";
28 group = lib.mkOption {
29 description = "Group to assign to the SGX provisioning device.";
31 default = defaultPrvGroup;
34 description = "Mode to set for the SGX provisioning device.";
40 config = lib.mkMerge [
41 (lib.mkIf cfg.provision.enable {
44 assertion = lib.hasAttr cfg.provision.user config.users.users;
45 message = "Given user does not exist";
48 assertion = (cfg.provision.group == defaultPrvGroup) || (lib.hasAttr cfg.provision.group config.users.groups);
49 message = "Given group does not exist";
53 users.groups = lib.optionalAttrs (cfg.provision.group == defaultPrvGroup) {
54 "${cfg.provision.group}" = { };
57 services.udev.extraRules = with cfg.provision; ''
58 SUBSYSTEM=="misc", KERNEL=="sgx_provision", OWNER="${user}", GROUP="${group}", MODE="${mode}"
61 (lib.mkIf cfg.enableDcapCompat {
62 services.udev.extraRules = ''
63 SUBSYSTEM=="misc", KERNEL=="sgx_enclave", SYMLINK+="sgx/enclave"
64 SUBSYSTEM=="misc", KERNEL=="sgx_provision", SYMLINK+="sgx/provision"