2021-10-01 09:20:50 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.pict-rs;
|
2023-07-15 17:15:38 +00:00
|
|
|
inherit (lib) maintainers mkOption types;
|
|
|
|
|
|
|
|
is03 = lib.versionOlder cfg.package.version "0.4.0";
|
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
meta.maintainers = with maintainers; [ happysalada ];
|
2023-02-02 18:25:31 +00:00
|
|
|
meta.doc = ./pict-rs.md;
|
2021-10-01 09:20:50 +00:00
|
|
|
|
|
|
|
options.services.pict-rs = {
|
2023-07-15 17:15:38 +00:00
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "pict-rs server");
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
example = lib.literalExpression "pkgs.pict-rs";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
pict-rs package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/pict-rs";
|
2023-07-15 17:15:38 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
The directory where to store the uploaded images & database.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
repoPath = mkOption {
|
|
|
|
type = types.nullOr (types.path);
|
|
|
|
default = null;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The directory where to store the database.
|
|
|
|
This option takes precedence over dataDir.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
storePath = mkOption {
|
|
|
|
type = types.nullOr (types.path);
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-10-01 09:20:50 +00:00
|
|
|
The directory where to store the uploaded images.
|
2023-07-15 17:15:38 +00:00
|
|
|
This option takes precedence over dataDir.
|
2021-10-01 09:20:50 +00:00
|
|
|
'';
|
|
|
|
};
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-10-01 09:20:50 +00:00
|
|
|
The IPv4 address to deploy the service to.
|
|
|
|
'';
|
|
|
|
};
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-10-01 09:20:50 +00:00
|
|
|
The port which to bind the service to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2023-07-15 17:15:38 +00:00
|
|
|
services.pict-rs.package = lib.mkDefault (
|
|
|
|
# An incompatible db change happened in the transition from 0.3 to 0.4.
|
|
|
|
if lib.versionAtLeast config.system.stateVersion "23.11"
|
|
|
|
then pkgs.pict-rs
|
|
|
|
else pkgs.pict-rs_0_3
|
|
|
|
);
|
|
|
|
|
|
|
|
# Account for config differences between 0.3 and 0.4
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = !is03 || (cfg.repoPath == null && cfg.storePath == null);
|
|
|
|
message = ''
|
|
|
|
Using `services.pict-rs.repoPath` or `services.pict-rs.storePath` with pict-rs 0.3 or older has no effect.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
systemd.services.pict-rs = {
|
2023-07-15 17:15:38 +00:00
|
|
|
# Pict-rs split it's database and image storage paths in 0.4.0.
|
|
|
|
environment =
|
|
|
|
if is03 then {
|
|
|
|
PICTRS__PATH = cfg.dataDir;
|
|
|
|
PICTRS__ADDR = "${cfg.address}:${toString cfg.port}";
|
|
|
|
} else {
|
|
|
|
PICTRS__REPO__PATH = if cfg.repoPath != null then cfg.repoPath else "${cfg.dataDir}/sled-repo";
|
|
|
|
PICTRS__STORE__PATH = if cfg.storePath != null then cfg.storePath else "${cfg.dataDir}/files";
|
|
|
|
PICTRS__SERVER__ADDR = "${cfg.address}:${toString cfg.port}";
|
|
|
|
};
|
2021-10-01 09:20:50 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = "pict-rs";
|
2023-07-15 17:15:38 +00:00
|
|
|
ExecStart = if is03 then "${lib.getBin cfg.package}/bin/pict-rs" else "${lib.getBin cfg.package}/bin/pict-rs run";
|
2021-10-01 09:20:50 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2021-10-01 09:20:50 +00:00
|
|
|
}
|