9 cfg = config.services.artalk;
10 settingsFormat = pkgs.formats.json { };
15 maintainers = with lib.maintainers; [ moraxyc ];
20 enable = lib.mkEnableOption "artalk, a comment system";
21 configFile = lib.mkOption {
23 default = "/etc/artalk/config.yml";
24 description = "Artalk config file path. If it is not exist, Artalk will generate one.";
26 allowModify = lib.mkOption {
27 type = lib.types.bool;
29 description = "allow Artalk store the settings to config file persistently";
31 workdir = lib.mkOption {
33 default = "/var/lib/artalk";
34 description = "Artalk working directory";
39 description = "Artalk user name.";
42 group = lib.mkOption {
45 description = "Artalk group name.";
48 package = lib.mkPackageOption pkgs "artalk" { };
49 settings = lib.mkOption {
50 type = lib.types.submodule {
51 freeformType = settingsFormat.type;
57 Artalk server listen host
61 type = lib.types.port;
64 Artalk server listen port
71 The artalk configuration.
73 If you set allowModify to true, Artalk will be able to store the settings in the config file persistently. This section's content will update in the config file after the service restarts.
75 Options containing secret data should be set to an attribute set
76 containing the attribute `_secret` - a string pointing to a file
77 containing the value the option should be set to.
83 config = lib.mkIf cfg.enable {
84 users.users.artalk = lib.optionalAttrs (cfg.user == "artalk") {
85 description = "artalk user";
89 users.groups.artalk = lib.optionalAttrs (cfg.group == "artalk") { };
91 environment.systemPackages = [ cfg.package ];
93 systemd.services.artalk = {
94 after = [ "network.target" ];
95 wantedBy = [ "multi-user.target" ];
99 ${utils.genJqSecretsReplacementSnippet cfg.settings "/run/artalk/new"}
102 if cfg.allowModify then
104 [ -e "${cfg.configFile}" ] || ${lib.getExe cfg.package} gen config "${cfg.configFile}"
105 cat "${cfg.configFile}" | ${lib.getExe pkgs.yj} > "/run/artalk/old"
106 ${lib.getExe pkgs.jq} -s '.[0] * .[1]' "/run/artalk/old" "/run/artalk/new" > "/run/artalk/result"
107 cat "/run/artalk/result" | ${lib.getExe pkgs.yj} -r > "${cfg.configFile}"
108 rm /run/artalk/{old,new,result}
112 cat /run/artalk/new | ${lib.getExe pkgs.yj} -r > "${cfg.configFile}"
120 ExecStart = "${lib.getExe cfg.package} server --config ${cfg.configFile} --workdir ${cfg.workdir} --host ${cfg.settings.host} --port ${builtins.toString cfg.settings.port}";
121 Restart = "on-failure";
123 ConfigurationDirectory = [ "artalk" ];
124 StateDirectory = [ "artalk" ];
125 RuntimeDirectory = [ "artalk" ];
126 AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];