summary refs log tree commit diff
diff options
context:
space:
mode:
authorOkina Matara <okinan@chiru.no>2018-07-10 18:10:02 -0500
committerOkina Matara <okinan@chiru.no>2018-07-18 13:16:50 -0500
commit38f2a3efbff43975cc2391011ebb912ee89871e1 (patch)
tree4e065d659afe446a310bc8d93650272eab305a3a
parent58eb085b66c6cbf07bd13253c2262816c4e0e7b0 (diff)
downloadnixpkgs-38f2a3efbff43975cc2391011ebb912ee89871e1.tar
nixpkgs-38f2a3efbff43975cc2391011ebb912ee89871e1.tar.gz
nixpkgs-38f2a3efbff43975cc2391011ebb912ee89871e1.tar.bz2
nixpkgs-38f2a3efbff43975cc2391011ebb912ee89871e1.tar.lz
nixpkgs-38f2a3efbff43975cc2391011ebb912ee89871e1.tar.xz
nixpkgs-38f2a3efbff43975cc2391011ebb912ee89871e1.tar.zst
nixpkgs-38f2a3efbff43975cc2391011ebb912ee89871e1.zip
nixos/hydron: init
-rw-r--r--nixos/modules/misc/ids.nix2
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/web-servers/hydron.nix105
3 files changed, 108 insertions, 0 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index aac86087f9e..7d3d1f71b70 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -321,6 +321,7 @@
       hdfs = 295;
       mapred = 296;
       hadoop = 297;
+      hydron = 298;
 
       # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
 
@@ -602,6 +603,7 @@
       hdfs = 295;
       mapred = 296;
       hadoop = 297;
+      hydron = 298;
 
       # When adding a gid, make sure it doesn't match an existing
       # uid. Users and groups with the same name should have equal
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index f6628b8e9c5..4a5ed20c00f 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -672,6 +672,7 @@
   ./services/web-servers/caddy.nix
   ./services/web-servers/fcgiwrap.nix
   ./services/web-servers/hitch/default.nix
+  ./services/web-servers/hydron.nix
   ./services/web-servers/jboss/default.nix
   ./services/web-servers/lighttpd/cgit.nix
   ./services/web-servers/lighttpd/collectd.nix
diff --git a/nixos/modules/services/web-servers/hydron.nix b/nixos/modules/services/web-servers/hydron.nix
new file mode 100644
index 00000000000..49a18f5e7b2
--- /dev/null
+++ b/nixos/modules/services/web-servers/hydron.nix
@@ -0,0 +1,105 @@
+{ config, lib, pkgs, ... }:
+
+let cfg = config.services.hydron;
+in with lib; {
+  options.services.hydron = {
+    enable = mkEnableOption "hydron";
+
+    dataDir = mkOption {
+      type = types.path;
+      default = "/var/lib/hydron";
+      example = "/home/okina/hydron";
+      description = "Location where hydron runs and stores data.";
+    };
+
+    interval = mkOption {
+      type = types.str;
+      default = "hourly";
+      example = "06:00";
+      description = ''
+        How often we run hydron import and possibly fetch tags. Runs by default every hour.
+
+        The format is described in
+        <citerefentry><refentrytitle>systemd.time</refentrytitle>
+        <manvolnum>7</manvolnum></citerefentry>.
+      '';
+    };
+
+    listenAddress = mkOption {
+      type = types.nullOr types.str;
+      default = null;
+      example = "127.0.0.1:8010";
+      description = "Listen on a specific IP address and port.";
+    };
+
+    importPaths = mkOption {
+      type = types.listOf types.path;
+      default = [];
+      example = [ "/home/okina/Pictures" ];
+      description = "Paths that hydron will recursively import.";
+    };
+
+    fetchTags = mkOption {
+      type = types.bool;
+      default = true;
+      description = "Fetch tags for imported images and webm from gelbooru.";
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.hydron = {
+      description = "hydron";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+
+      preStart = ''
+        # Ensure folder exists and permissions are correct
+        mkdir -p ${escapeShellArg cfg.dataDir}/images
+        chmod 750 ${escapeShellArg cfg.dataDir}
+        chown -R hydron:hydron ${escapeShellArg cfg.dataDir}
+      '';
+
+      serviceConfig = {
+        PermissionsStartOnly = true;
+        User = "hydron";
+        Group = "hydron";
+        ExecStart = "${pkgs.hydron}/bin/hydron serve"
+        + optionalString (cfg.listenAddress != null) " -a ${cfg.listenAddress}";
+      };
+    };
+
+    systemd.services.hydron-fetch = {
+      description = "Import paths into hydron and possibly fetch tags";
+
+      serviceConfig = {
+        Type = "oneshot";
+        User = "hydron";
+        Group = "hydron";
+        ExecStart = "${pkgs.hydron}/bin/hydron import "
+        + optionalString cfg.fetchTags "-f "
+        + (escapeShellArg cfg.dataDir) + "/images " + (escapeShellArgs cfg.importPaths);
+      };
+    };
+
+    systemd.timers.hydron-fetch = {
+      description = "Automatically import paths into hydron and possibly fetch tags";
+      after = [ "network.target" ];
+      wantedBy = [ "timers.target" ];
+      timerConfig.OnCalendar = cfg.interval;
+    };
+
+    users = {
+      groups.hydron.gid = config.ids.gids.hydron;
+      
+      users.hydron = {
+        description = "hydron server service user";
+        home = cfg.dataDir;
+        createHome = true;
+        group = "hydron";
+        uid = config.ids.uids.hydron;
+      };
+    };
+  };
+
+  meta.maintainers = with maintainers; [ chiiruno ];
+}