1 { config, lib, pkgs, ... }:
4 cfg = config.services.hydron;
6 options.services.hydron = {
7 enable = mkEnableOption (lib.mdDoc "hydron");
11 default = "/var/lib/hydron";
12 example = "/home/okina/hydron";
13 description = lib.mdDoc "Location where hydron runs and stores data.";
20 description = lib.mdDoc ''
21 How often we run hydron import and possibly fetch tags. Runs by default every week.
23 The format is described in
24 {manpage}`systemd.time(7)`.
32 description = lib.mdDoc "Password for the hydron database.";
35 passwordFile = mkOption {
37 default = "/run/keys/hydron-password-file";
38 example = "/home/okina/hydron/keys/pass";
39 description = lib.mdDoc "Password file for the hydron database.";
42 postgresArgs = mkOption {
44 description = lib.mdDoc "Postgresql connection arguments.";
48 "connection": "user=hydron password=dumbpass dbname=hydron sslmode=disable"
53 postgresArgsFile = mkOption {
55 default = "/run/keys/hydron-postgres-args";
56 example = "/home/okina/hydron/keys/postgres";
57 description = lib.mdDoc "Postgresql connection arguments file.";
60 listenAddress = mkOption {
61 type = types.nullOr types.str;
63 example = "127.0.0.1:8010";
64 description = lib.mdDoc "Listen on a specific IP address and port.";
67 importPaths = mkOption {
68 type = types.listOf types.path;
70 example = [ "/home/okina/Pictures" ];
71 description = lib.mdDoc "Paths that hydron will recursively import.";
74 fetchTags = mkOption {
77 description = lib.mdDoc "Fetch tags for imported images and webm from gelbooru.";
81 config = mkIf cfg.enable {
82 services.hydron.passwordFile = mkDefault (pkgs.writeText "hydron-password-file" cfg.password);
83 services.hydron.postgresArgsFile = mkDefault (pkgs.writeText "hydron-postgres-args" cfg.postgresArgs);
84 services.hydron.postgresArgs = mkDefault ''
87 "connection": "user=hydron password=${cfg.password} host=/run/postgresql dbname=hydron sslmode=disable"
91 services.postgresql = {
93 ensureDatabases = [ "hydron" ];
96 ensurePermissions = { "DATABASE hydron" = "ALL PRIVILEGES"; };
101 systemd.tmpfiles.rules = [
102 "d '${cfg.dataDir}' 0750 hydron hydron - -"
103 "d '${cfg.dataDir}/.hydron' - hydron hydron - -"
104 "d '${cfg.dataDir}/images' - hydron hydron - -"
105 "Z '${cfg.dataDir}' - hydron hydron - -"
107 "L+ '${cfg.dataDir}/.hydron/db_conf.json' - - - - ${cfg.postgresArgsFile}"
110 systemd.services.hydron = {
111 description = "hydron";
112 after = [ "network.target" "postgresql.service" ];
113 wantedBy = [ "multi-user.target" ];
118 ExecStart = "${pkgs.hydron}/bin/hydron serve"
119 + optionalString (cfg.listenAddress != null) " -a ${cfg.listenAddress}";
123 systemd.services.hydron-fetch = {
124 description = "Import paths into hydron and possibly fetch tags";
130 ExecStart = "${pkgs.hydron}/bin/hydron import "
131 + optionalString cfg.fetchTags "-f "
132 + (escapeShellArg cfg.dataDir) + "/images " + (escapeShellArgs cfg.importPaths);
136 systemd.timers.hydron-fetch = {
137 description = "Automatically import paths into hydron and possibly fetch tags";
138 after = [ "network.target" "hydron.service" ];
139 wantedBy = [ "timers.target" ];
143 OnCalendar = cfg.interval;
148 groups.hydron.gid = config.ids.gids.hydron;
151 description = "hydron server service user";
154 uid = config.ids.uids.hydron;
160 (mkRenamedOptionModule [ "services" "hydron" "baseDir" ] [ "services" "hydron" "dataDir" ])
163 meta.maintainers = with maintainers; [ Madouura ];