mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
nixos/pict-rs: Use pict-rs-0.3 for NixOS <= 23.05
This commit is contained in:
parent
fceac044f8
commit
4c5afa2af4
1 changed files with 66 additions and 8 deletions
|
@ -1,21 +1,53 @@
|
||||||
{ lib, pkgs, config, ... }:
|
{ lib, pkgs, config, ... }:
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
cfg = config.services.pict-rs;
|
cfg = config.services.pict-rs;
|
||||||
|
inherit (lib) maintainers mkOption types;
|
||||||
|
|
||||||
|
is03 = lib.versionOlder cfg.package.version "0.4.0";
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
meta.maintainers = with maintainers; [ happysalada ];
|
meta.maintainers = with maintainers; [ happysalada ];
|
||||||
meta.doc = ./pict-rs.md;
|
meta.doc = ./pict-rs.md;
|
||||||
|
|
||||||
options.services.pict-rs = {
|
options.services.pict-rs = {
|
||||||
enable = mkEnableOption (lib.mdDoc "pict-rs server");
|
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.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
dataDir = mkOption {
|
dataDir = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
default = "/var/lib/pict-rs";
|
default = "/var/lib/pict-rs";
|
||||||
description = lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
The directory where to store the uploaded images.
|
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;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The directory where to store the uploaded images.
|
||||||
|
This option takes precedence over dataDir.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
address = mkOption {
|
address = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "127.0.0.1";
|
default = "127.0.0.1";
|
||||||
|
@ -23,6 +55,7 @@ in
|
||||||
The IPv4 address to deploy the service to.
|
The IPv4 address to deploy the service to.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
type = types.port;
|
type = types.port;
|
||||||
default = 8080;
|
default = 8080;
|
||||||
|
@ -31,18 +64,43 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
systemd.services.pict-rs = {
|
systemd.services.pict-rs = {
|
||||||
environment = {
|
# Pict-rs split it's database and image storage paths in 0.4.0.
|
||||||
PICTRS__PATH = cfg.dataDir;
|
environment =
|
||||||
PICTRS__ADDR = "${cfg.address}:${toString cfg.port}";
|
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}";
|
||||||
|
};
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
StateDirectory = "pict-rs";
|
StateDirectory = "pict-rs";
|
||||||
ExecStart = "${pkgs.pict-rs}/bin/pict-rs";
|
ExecStart = if is03 then "${lib.getBin cfg.package}/bin/pict-rs" else "${lib.getBin cfg.package}/bin/pict-rs run";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue