1 { config, lib, pkgs, ... }:
6 cfg = config.services.sks;
8 dbConfig = pkgs.writeText "DB_CONFIG" ''
13 meta.maintainers = with maintainers; [ primeos calbrecht jcumming ];
19 enable = mkEnableOption (lib.mdDoc ''
20 SKS (synchronizing key server for OpenPGP) and start the database
21 server. You need to create "''${dataDir}/dump/*.gpg" for the initial
26 defaultText = literalExpression "pkgs.sks";
28 description = lib.mdDoc "Which SKS derivation to use.";
33 default = "/var/db/sks";
34 example = "/var/lib/sks";
35 # TODO: The default might change to "/var/lib/sks" as this is more
36 # common. There's also https://github.com/NixOS/nixpkgs/issues/26256
37 # and "/var/db" is not FHS compliant (seems to come from BSD).
38 description = lib.mdDoc ''
39 Data directory (-basedir) for SKS, where the database and all
40 configuration files are located (e.g. KDB, PTree, membership and
45 extraDbConfig = mkOption {
48 description = lib.mdDoc ''
49 Set contents of the files "KDB/DB_CONFIG" and "PTree/DB_CONFIG" within
50 the ''${dataDir} directory. This is used to configure options for the
51 database for the sks key server.
53 Documentation of available options are available in the file named
54 "sampleConfig/DB_CONFIG" in the following repository:
55 https://bitbucket.org/skskeyserver/sks-keyserver/src
59 hkpAddress = mkOption {
60 default = [ "127.0.0.1" "::1" ];
61 type = types.listOf types.str;
62 description = lib.mdDoc ''
63 Domain names, IPv4 and/or IPv6 addresses to listen on for HKP
70 type = types.ints.u16;
71 description = lib.mdDoc "HKP port to listen on.";
75 type = types.nullOr types.path;
76 default = "${sksPkg.webSamples}/OpenPKG";
77 defaultText = literalExpression ''"''${package.webSamples}/OpenPKG"'';
78 description = lib.mdDoc ''
79 Source directory (will be symlinked, if not null) for the files the
80 built-in webserver should serve. SKS (''${pkgs.sks.webSamples})
81 provides the following examples: "HTML5", "OpenPKG", and "XHTML+ES".
82 The index file can be named index.html, index.htm, index.xhtm, or
83 index.xhtml. Files with the extensions .css, .es, .js, .jpg, .jpeg,
84 .png, or .gif are supported. Subdirectories and filenames with
85 anything other than alphanumeric characters and the '.' character
92 config = mkIf cfg.enable {
97 description = "SKS user";
101 useDefaultShell = true;
102 packages = [ sksPkg pkgs.db ];
107 systemd.services = let
108 hkpAddress = "'" + (builtins.concatStringsSep " " cfg.hkpAddress) + "'" ;
109 hkpPort = builtins.toString cfg.hkpPort;
112 description = "SKS database server";
113 after = [ "network.target" ];
114 wantedBy = [ "multi-user.target" ];
116 ${lib.optionalString (cfg.webroot != null)
117 "ln -sfT \"${cfg.webroot}\" web"}
119 ${sksPkg}/bin/sks build dump/*.gpg -n 10 -cache 100 || true #*/
120 ${sksPkg}/bin/sks cleandb || true
121 ${sksPkg}/bin/sks pbuild -cache 20 -ptree_cache 70 || true
122 # Check that both database configs are symlinks before overwriting them
123 # TODO: The initial build will be without DB_CONFIG, but this will
124 # hopefully not cause any significant problems. It might be better to
125 # create both directories manually but we have to check that this does
126 # not affect the initial build of the DB.
127 for CONFIG_FILE in KDB/DB_CONFIG PTree/DB_CONFIG; do
128 if [ -e $CONFIG_FILE ] && [ ! -L $CONFIG_FILE ]; then
129 echo "$CONFIG_FILE exists but is not a symlink." >&2
130 echo "Please remove $PWD/$CONFIG_FILE manually to continue." >&2
133 ln -sf ${dbConfig} $CONFIG_FILE
137 WorkingDirectory = "~";
141 ExecStart = "${sksPkg}/bin/sks db -hkp_address ${hkpAddress} -hkp_port ${hkpPort}";