Merge pull request #308423 from Moraxyc/add-artalk

artalk: init at 2.8.6
This commit is contained in:
Sandro 2024-05-19 18:06:08 +02:00 committed by GitHub
commit 52f4cce004
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 211 additions and 0 deletions

@ -1328,6 +1328,7 @@
./services/web-apps/akkoma.nix
./services/web-apps/alps.nix
./services/web-apps/anuko-time-tracker.nix
./services/web-apps/artalk.nix
./services/web-apps/atlassian/confluence.nix
./services/web-apps/atlassian/crowd.nix
./services/web-apps/atlassian/jira.nix

@ -0,0 +1,131 @@
{
config,
lib,
pkgs,
utils,
...
}:
let
cfg = config.services.artalk;
settingsFormat = pkgs.formats.json { };
in
{
meta = {
maintainers = with lib.maintainers; [ moraxyc ];
};
options = {
services.artalk = {
enable = lib.mkEnableOption "artalk, a comment system";
configFile = lib.mkOption {
type = lib.types.str;
default = "/etc/artalk/config.yml";
description = "Artalk config file path. If it is not exist, Artalk will generate one.";
};
allowModify = lib.mkOption {
type = lib.types.bool;
default = true;
description = "allow Artalk store the settings to config file persistently";
};
workdir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/artalk";
description = "Artalk working directory";
};
user = lib.mkOption {
type = lib.types.str;
default = "artalk";
description = "Artalk user name.";
};
group = lib.mkOption {
type = lib.types.str;
default = "artalk";
description = "Artalk group name.";
};
package = lib.mkPackageOption pkgs "artalk" { };
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;
options = {
host = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
description = ''
Artalk server listen host
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 23366;
description = ''
Artalk server listen port
'';
};
};
};
default = { };
description = ''
The artalk configuration.
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.
Options containing secret data should be set to an attribute set
containing the attribute `_secret` - a string pointing to a file
containing the value the option should be set to.
'';
};
};
};
config = lib.mkIf cfg.enable {
users.users.artalk = lib.optionalAttrs (cfg.user == "artalk") {
description = "artalk user";
isSystemUser = true;
group = cfg.group;
};
users.groups.artalk = lib.optionalAttrs (cfg.group == "artalk") { };
environment.systemPackages = [ cfg.package ];
systemd.services.artalk = {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
preStart =
''
umask 0077
${utils.genJqSecretsReplacementSnippet cfg.settings "/run/artalk/new"}
''
+ (
if cfg.allowModify then
''
[ -e "${cfg.configFile}" ] || ${lib.getExe cfg.package} gen config "${cfg.configFile}"
cat "${cfg.configFile}" | ${lib.getExe pkgs.yj} > "/run/artalk/old"
${lib.getExe pkgs.jq} -s '.[0] * .[1]' "/run/artalk/old" "/run/artalk/new" > "/run/artalk/result"
cat "/run/artalk/result" | ${lib.getExe pkgs.yj} -r > "${cfg.configFile}"
rm /run/artalk/{old,new,result}
''
else
''
cat /run/artalk/new | ${lib.getExe pkgs.yj} -r > "${cfg.configFile}"
rm /run/artalk/new
''
);
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Type = "simple";
ExecStart = "${lib.getExe cfg.package} server --config ${cfg.configFile} --workdir ${cfg.workdir} --host ${cfg.settings.host} --port ${builtins.toString cfg.settings.port}";
Restart = "on-failure";
RestartSec = "5s";
ConfigurationDirectory = [ "artalk" ];
StateDirectory = [ "artalk" ];
RuntimeDirectory = [ "artalk" ];
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
ProtectHome = "yes";
};
};
};
}

@ -130,6 +130,7 @@ in {
apparmor = handleTest ./apparmor.nix {};
archi = handleTest ./archi.nix {};
armagetronad = handleTest ./armagetronad.nix {};
artalk = handleTest ./artalk.nix {};
atd = handleTest ./atd.nix {};
atop = handleTest ./atop.nix {};
atuin = handleTest ./atuin.nix {};

28
nixos/tests/artalk.nix Normal file

@ -0,0 +1,28 @@
import ./make-test-python.nix (
{ lib, pkgs, ... }:
{
name = "artalk";
meta = {
maintainers = with lib.maintainers; [ moraxyc ];
};
nodes.machine =
{ pkgs, ... }:
{
environment.systemPackages = [ pkgs.curl ];
services.artalk = {
enable = true;
};
};
testScript = ''
machine.wait_for_unit("artalk.service")
machine.wait_for_open_port(23366)
machine.succeed("curl --fail --max-time 10 http://127.0.0.1:23366/")
'';
}
)

@ -0,0 +1,50 @@
{
lib,
buildGoModule,
fetchFromGitHub,
artalk,
testers,
fetchurl,
}:
buildGoModule rec {
pname = "artalk";
version = "2.8.6";
src = fetchFromGitHub {
owner = "ArtalkJS";
repo = "artalk";
rev = "v${version}";
hash = "sha256-ya/by1PaWdYS/Fsbu6wDKuUcPy55/2F5hJEqko4K57o=";
};
web = fetchurl {
url = "https://github.com/${src.owner}/${src.repo}/releases/download/v${version}/artalk_ui.tar.gz";
hash = "sha256-3Rg5mCFigLkZ+X8Fxe6A16THd9j6hcTYMEAKU1SrLMw=";
};
CGO_ENABLED = 1;
vendorHash = "sha256-R4/keVGCpCZfLrb2OrK9vdK+N+VKFLAvFXEOA1feqKo=";
ldflags = [
"-s"
"-w"
"-X github.com/ArtalkJS/Artalk/internal/config.Version=${version}"
"-X github.com/ArtalkJS/Artalk/internal/config.CommitHash=${version}"
];
preBuild = ''
tar -xzf ${web}
cp -r ./artalk_ui/* ./public
'';
passthru.tests = {
version = testers.testVersion { package = artalk; };
};
meta = with lib; {
description = "A self-hosted comment system";
homepage = "https://github.com/ArtalkJS/Artalk";
license = licenses.mit;
maintainers = with maintainers; [ moraxyc ];
mainProgram = "Artalk";
};
}