From 560988ea6f96ffb0ee534facba168abd8f999da3 Mon Sep 17 00:00:00 2001
From: Ethel Morgan <eth@ethulhu.co.uk>
Date: Tue, 9 Jun 2020 15:32:20 +0100
Subject: add NixOS module eth.services.helix-directory-jackalope

---
 nixos/modules/module-list.nix                      |  1 +
 .../modules/services/helix-directory-jackalope.nix | 72 ++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100644 nixos/modules/services/helix-directory-jackalope.nix

(limited to 'nixos/modules')

diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 68174a4..5eb74ed 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -6,6 +6,7 @@
   ./programs/dwm.nix
   ./services/catbus-bridge-snapcast.nix
   ./services/dlnatoad.nix
+  ./services/helix-directory-jackalope.nix
   ./services/helix-directory.nix
   ./services/helix-player.nix
   ./services/mosquitto.nix
diff --git a/nixos/modules/services/helix-directory-jackalope.nix b/nixos/modules/services/helix-directory-jackalope.nix
new file mode 100644
index 0000000..fc1d95a
--- /dev/null
+++ b/nixos/modules/services/helix-directory-jackalope.nix
@@ -0,0 +1,72 @@
+{ config, lib, pkgs, ... }:
+with lib;
+
+let
+  cfg = config.eth.services.helix-directory-jackalope;
+
+in {
+
+  options.eth.services.helix-directory-jackalope = {
+
+    enable = mkEnableOption "Whether to enable helix-directory-jackalope";
+
+    friendlyName = mkOption {
+      type = types.str;
+      default = "Helix (${config.networking.hostName})";
+      description = "Human-readable name to broadcast";
+      example = "My Media Server";
+    };
+
+    directory = mkOption {
+      type = types.str;
+      default = "";
+      description = "Directory to serve";
+      example = "/mnt/md0/media";
+    };
+
+    jackalopePath = mkOption {
+      type = types.str;
+      default = "";
+      description = "Path to Jackalope DB";
+      example = "/mnt/md0/media/jackalope.db";
+    };
+  };
+
+
+  config = mkIf cfg.enable {
+    assertions = [
+      {
+        assertion = cfg.directory != "";
+        message = "must set config.eth.services.helix-directory-jackalope.directory";
+      }
+      {
+        assertion = cfg.jackalopePath != "";
+        message = "must set config.eth.services.helix-directory-jackalope.jackalopePath";
+      }
+    ];
+
+    systemd.services.helix-directory-jackalope = {
+      enable = true;
+      description = "Helix UPnP ContentDirectory server, with Jackalope";
+      wants = [ "network.target" ];
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+      path = [ pkgs.ffmpeg ];
+      serviceConfig = {
+        DynamicUser = true;
+
+        ExecStart = "${pkgs.eth.helix}/bin/helix-directory-jackalope -friendly-name ${escapeShellArg cfg.friendlyName} -path ${escapeShellArg cfg.directory} -jackalope-path ${escapeShellArg cfg.jackalopePath}";
+
+        Restart = "always";
+        RestartSec = "1min";
+
+        NoNewPrivileges = true;
+        ProtectHome = true;
+        ProtectKernelTunables = true;
+        ProtectControlGroups = true;
+        ProtectKernelModules = true;
+      };
+    };
+  };
+
+}
-- 
cgit v1.2.3