8 cfg = config.services.step-ca;
9 settingsFormat = (pkgs.formats.json { });
12 meta.maintainers = [ ];
16 enable = lib.mkEnableOption "the smallstep certificate authority server";
17 openFirewall = lib.mkEnableOption "opening the certificate authority server port";
18 package = lib.mkOption {
19 type = lib.types.package;
20 default = pkgs.step-ca;
21 defaultText = lib.literalExpression "pkgs.step-ca";
22 description = "Which step-ca package to use.";
24 address = lib.mkOption {
26 example = "127.0.0.1";
28 The address (without port) the certificate authority should listen at.
29 This combined with {option}`services.step-ca.port` overrides {option}`services.step-ca.settings.address`.
33 type = lib.types.port;
36 The port the certificate authority should listen on.
37 This combined with {option}`services.step-ca.address` overrides {option}`services.step-ca.settings.address`.
40 settings = lib.mkOption {
41 type = with lib.types; attrsOf anything;
43 Settings that go into {file}`ca.json`. See
44 [the step-ca manual](https://smallstep.com/docs/step-ca/configuration)
45 for more information. The easiest way to
46 configure this module would be to run `step ca init`
47 to generate {file}`ca.json` and then import it using
49 [This article](https://smallstep.com/docs/step-cli/basic-crypto-operations#run-an-offline-x509-certificate-authority)
50 may also be useful if you want to customize certain aspects of
51 certificate generation for your CA.
52 You need to change the database storage path to {file}`/var/lib/step-ca/db`.
55 The {option}`services.step-ca.settings.address` option
56 will be ignored and overwritten by
57 {option}`services.step-ca.address` and
58 {option}`services.step-ca.port`.
62 intermediatePasswordFile = lib.mkOption {
63 type = lib.types.path;
64 example = "/run/keys/smallstep-password";
66 Path to the file containing the password for the intermediate
67 certificate private key.
70 Make sure to use a quoted absolute path instead of a path literal
71 to prevent it from being copied to the globally readable Nix
79 config = lib.mkIf config.services.step-ca.enable (
81 configFile = settingsFormat.generate "ca.json" (
84 address = cfg.address + ":" + toString cfg.port;
91 assertion = !lib.isStorePath cfg.intermediatePasswordFile;
93 <option>services.step-ca.intermediatePasswordFile</option> points to
94 a file in the Nix store. You should use a quoted absolute path to
100 systemd.packages = [ cfg.package ];
102 # configuration file indirection is needed to support reloading
103 environment.etc."smallstep/ca.json".source = configFile;
105 systemd.services."step-ca" = {
106 wantedBy = [ "multi-user.target" ];
107 restartTriggers = [ configFile ];
109 ConditionFileNotEmpty = ""; # override upstream
115 Environment = "HOME=%S/step-ca";
116 WorkingDirectory = ""; # override upstream
117 ReadWritePaths = ""; # override upstream
119 # LocalCredential handles file permission problems arising from the use of DynamicUser.
120 LoadCredential = "intermediate_password:${cfg.intermediatePasswordFile}";
123 "" # override upstream
124 "${cfg.package}/bin/step-ca /etc/smallstep/ca.json --password-file \${CREDENTIALS_DIRECTORY}/intermediate_password"
127 # ProtectProc = "invisible"; # not supported by upstream yet
128 # ProcSubset = "pid"; # not supported by upstream yet
129 # PrivateUsers = true; # doesn't work with privileged ports therefore not supported by upstream
132 StateDirectory = "step-ca";
136 users.users.step-ca = {
137 home = "/var/lib/step-ca";
142 users.groups.step-ca = { };
144 networking.firewall = lib.mkIf cfg.openFirewall {
145 allowedTCPPorts = [ cfg.port ];