-
Notifications
You must be signed in to change notification settings - Fork 0
/
stash.nix
114 lines (103 loc) · 2.78 KB
/
stash.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{ flake, config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.stash;
in
{
options.services.stash = {
enable = mkEnableOption (mdDoc "Stash");
user = mkOption {
type = types.str;
default = "stash";
description = mdDoc "User under which the webserver runs.";
};
group = mkOption {
type = types.str;
default = "stash";
description = mdDoc "Group under which the webserver runs.";
};
host = mkOption {
type = types.str;
default = "localhost";
description = mdDoc "Address on which to start webserver.";
};
port = mkOption {
type = types.port;
default = 9999;
description = mdDoc "Port on which to start webserver.";
};
environment = mkOption {
type = types.attrs;
default = { };
description = mdDoc "Extra environment variables.";
example = {
STASH_EXTERNAL_HOST = "my.hostname";
};
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/stash";
description = mdDoc "Path where to store data files.";
};
};
config = mkIf cfg.enable (
let
stashPackages = with pkgs; [
(python3.withPackages (ps: with ps; [
cloudscraper
configparser
progressbar
requests
]))
bashInteractive
openssl
sqlite
ffmpeg
];
in
{
systemd.services.stash = {
description = "Stash daemon";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
path = stashPackages;
environment = {
HOME = "%S/stash";
STASH_GENERATED = "${cfg.dataDir}/generated";
STASH_METADATA = "${cfg.dataDir}/metadata";
STASH_CACHE = "${cfg.dataDir}/cache";
STASH_CONFIG_FILE = "${cfg.dataDir}/config.yml";
STASH_HOST = cfg.host;
STASH_PORT = toString cfg.port;
} // cfg.environment;
preStart = ''
# mkdir -p ~/.stash && chmod 0700 ~/.stash
ln -sf ${pkgs.ffmpeg}/bin/ffmpeg ${cfg.dataDir}/ffmpeg
ln -sf ${pkgs.ffmpeg}/bin/ffprobe ${cfg.dataDir}/ffprobe
'';
serviceConfig = {
Type = "simple";
Restart = "on-failure";
# DynamicUser = true;
User = cfg.user;
Group = cfg.group;
StateDirectory = "stash";
ExecStart = "${flake.packages.stash}/bin/stash --nobrowser";
};
};
users = {
users = mkIf (cfg.user == "stash") {
stash = {
isSystemUser = true;
group = cfg.group;
home = cfg.dataDir;
createHome = true;
};
};
groups = optionalAttrs (cfg.group == "stash") {
stash = { };
};
};
}
);
}