2 { config, options, pkgs, lib, ... }:
5 cfg = config.services.tcsd;
6 opt = options.services.tcsd;
8 tcsdConf = pkgs.writeText "tcsd.conf" ''
11 system_ps_file = ${cfg.stateDir}/system.data
12 # This is the log of each individual measurement done by the system.
13 # By re-calculating the PCR registers based on this information, even
14 # finer details about the measured environment can be inferred than
15 # what is available directly from the PCR registers.
16 firmware_log_file = /sys/kernel/security/tpm0/binary_bios_measurements
17 kernel_log_file = /sys/kernel/security/ima/binary_runtime_measurements
18 firmware_pcrs = ${cfg.firmwarePCRs}
19 kernel_pcrs = ${cfg.kernelPCRs}
20 platform_cred = ${cfg.platformCred}
21 conformance_cred = ${cfg.conformanceCred}
22 endorsement_cred = ${cfg.endorsementCred}
23 #remote_ops = create_key,random
24 #host_platform_class = server_12
25 #all_platform_classes = pc_11,pc_12,mobile_12
37 enable = lib.mkOption {
39 type = lib.types.bool;
41 Whether to enable tcsd, a Trusted Computing management service
42 that provides TCG Software Stack (TSS). The tcsd daemon is
43 the only portal to the Trusted Platform Module (TPM), a hardware
44 chip on the motherboard.
51 description = "User account under which tcsd runs.";
54 group = lib.mkOption {
57 description = "Group account under which tcsd runs.";
60 stateDir = lib.mkOption {
61 default = "/var/lib/tpm";
62 type = lib.types.path;
64 The location of the system persistent storage file.
65 The system persistent storage file holds keys and data across
66 restarts of the TCSD and system reboots.
70 firmwarePCRs = lib.mkOption {
71 default = "0,1,2,3,4,5,6,7";
73 description = "PCR indices used in the TPM for firmware measurements.";
76 kernelPCRs = lib.mkOption {
77 default = "8,9,10,11,12";
79 description = "PCR indices used in the TPM for kernel measurements.";
82 platformCred = lib.mkOption {
83 default = "${cfg.stateDir}/platform.cert";
84 defaultText = lib.literalExpression ''"''${config.${opt.stateDir}}/platform.cert"'';
85 type = lib.types.path;
87 Path to the platform credential for your TPM. Your TPM
88 manufacturer may have provided you with a set of credentials
89 (certificates) that should be used when creating identities
90 using your TPM. When a user of your TPM makes an identity,
91 this credential will be encrypted as part of that process.
92 See the 1.1b TPM Main specification section 9.3 for information
96 conformanceCred = lib.mkOption {
97 default = "${cfg.stateDir}/conformance.cert";
98 defaultText = lib.literalExpression ''"''${config.${opt.stateDir}}/conformance.cert"'';
99 type = lib.types.path;
101 Path to the conformance credential for your TPM.
102 See also the platformCred option'';
105 endorsementCred = lib.mkOption {
106 default = "${cfg.stateDir}/endorsement.cert";
107 defaultText = lib.literalExpression ''"''${config.${opt.stateDir}}/endorsement.cert"'';
108 type = lib.types.path;
110 Path to the endorsement credential for your TPM.
111 See also the platformCred option'';
117 ###### implementation
119 config = lib.mkIf cfg.enable {
121 environment.systemPackages = [ pkgs.trousers ];
123 services.udev.extraRules = ''
124 # Give tcsd ownership of all TPM devices
125 KERNEL=="tpm[0-9]*", MODE="0660", OWNER="${cfg.user}", GROUP="${cfg.group}"
126 # Tag TPM devices to create a .device unit for tcsd to depend on
127 ACTION=="add", KERNEL=="tpm[0-9]*", TAG+="systemd"
130 systemd.tmpfiles.rules = [
131 # Initialise the state directory
132 "d ${cfg.stateDir} 0770 ${cfg.user} ${cfg.group} - -"
135 systemd.services.tcsd = {
136 description = "Manager for Trusted Computing resources";
137 documentation = [ "man:tcsd(8)" ];
139 requires = [ "dev-tpm0.device" ];
140 after = [ "dev-tpm0.device" ];
141 wantedBy = [ "multi-user.target" ];
146 ExecStart = "${pkgs.trousers}/sbin/tcsd -f -c ${tcsdConf}";
150 users.users = lib.optionalAttrs (cfg.user == "tss") {
157 users.groups = lib.optionalAttrs (cfg.group == "tss") { tss = {}; };