1 { config, lib, pkgs, ... }:
7 cfg = config.security.pki;
9 cacertPackage = pkgs.cacert.override {
10 blacklist = cfg.caCertificateBlacklist;
11 extraCertificateFiles = cfg.certificateFiles;
12 extraCertificateStrings = cfg.certificates;
14 caBundleName = if cfg.useCompatibleBundle then "ca-no-trust-rules-bundle.crt" else "ca-bundle.crt";
15 caBundle = "${cacertPackage}/etc/ssl/certs/${caBundleName}";
22 security.pki.installCACerts = mkEnableOption "installing CA certificates to the system" // {
27 security.pki.useCompatibleBundle = mkEnableOption ''usage of a compatibility bundle.
29 Such a bundle consists exclusively of `BEGIN CERTIFICATE` and no `BEGIN TRUSTED CERTIFICATE`,
30 which is an OpenSSL specific PEM format.
32 It is known to be incompatible with certain software stacks.
34 Nevertheless, enabling this will strip all additional trust rules provided by the
35 certificates themselves. This can have security consequences depending on your usecases
38 security.pki.certificateFiles = mkOption {
39 type = types.listOf types.path;
41 example = literalExpression ''[ "''${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ]'';
43 A list of files containing trusted root certificates in PEM
44 format. These are concatenated to form
45 {file}`/etc/ssl/certs/ca-certificates.crt`, which is
46 used by many programs that use OpenSSL, such as
47 {command}`curl` and {command}`git`.
51 security.pki.certificates = mkOption {
52 type = types.listOf types.str;
54 example = literalExpression ''
58 -----BEGIN CERTIFICATE-----
59 MIIGUDCCBTigAwIBAgIDD8KWMA0GCSqGSIb3DQEBBQUAMIGMMQswCQYDVQQGEwJJ
60 TDEWMBQGA1UEChMNU3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0
62 -----END CERTIFICATE-----
67 A list of trusted root certificates in PEM format.
71 security.pki.caCertificateBlacklist = mkOption {
72 type = types.listOf types.str;
75 "WoSign" "WoSign China"
77 "Certification Authority of WoSign G2"
80 A list of blacklisted CA certificate names that won't be imported from
81 the Mozilla Trust Store into
82 {file}`/etc/ssl/certs/ca-certificates.crt`. Use the
89 config = mkIf cfg.installCACerts {
91 # NixOS canonical location + Debian/Ubuntu/Arch/Gentoo compatibility.
92 environment.etc."ssl/certs/ca-certificates.crt".source = caBundle;
94 # Old NixOS compatibility.
95 environment.etc."ssl/certs/ca-bundle.crt".source = caBundle;
97 # CentOS/Fedora compatibility.
98 environment.etc."pki/tls/certs/ca-bundle.crt".source = caBundle;
100 # P11-Kit trust source.
101 environment.etc."ssl/trust-source".source = "${cacertPackage.p11kit}/etc/ssl/trust-source";