From 2a2526f196e1561e64a2e6bd52f73d44334791dd Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 1 Aug 2024 12:29:56 +0800 Subject: [PATCH] home-manager/services/gonic: init Even though it's pointless in practice since it needs firewall for security-oriented systems but still... could be useful for desktop systems where security is permissive. --- modules/home-manager/default.nix | 1 + modules/home-manager/services/gonic.nix | 54 +++++++++++++++++++ tests/modules/home-manager/default.nix | 1 + .../home-manager/services/gonic/basic.nix | 19 +++++++ .../home-manager/services/gonic/default.nix | 3 ++ 5 files changed, 78 insertions(+) create mode 100644 modules/home-manager/services/gonic.nix create mode 100644 tests/modules/home-manager/services/gonic/basic.nix create mode 100644 tests/modules/home-manager/services/gonic/default.nix diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix index 5e56d6f8..97dffc50 100644 --- a/modules/home-manager/default.nix +++ b/modules/home-manager/default.nix @@ -9,6 +9,7 @@ ./services/bleachbit.nix ./services/distant.nix ./services/gallery-dl.nix + ./services/gonic.nix ./services/matcha.nix ./services/plover.nix ./services/yt-dlp.nix diff --git a/modules/home-manager/services/gonic.nix b/modules/home-manager/services/gonic.nix new file mode 100644 index 00000000..980c126c --- /dev/null +++ b/modules/home-manager/services/gonic.nix @@ -0,0 +1,54 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.services.gonic; + + settingsFormat = pkgs.formats.keyValue { + mkKeyValue = lib.generators.mkKeyValueDefault { } " "; + listsAsDuplicateKeys = true; + }; + settingsFile = settingsFormat.generate "gonic-settings-config" cfg.settings; +in +{ + options.services.gonic = { + enable = lib.mkEnableOption "Gonic, a Subsonic-compatible music server"; + + package = lib.mkPackageOption pkgs "gonic" { }; + + settings = lib.mkOption { + type = settingsFormat.type; + default = { }; + description = '' + Configuration to be included to the service. + ''; + example = lib.literalExpression '' + { + music-path = [ config.xdg.userDirs.music ]; + podcast-path = [ "''${config.xdg.userDirs.music}/Podcasts" ]; + } + ''; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.gonic" pkgs + lib.platforms.linux) + ]; + + systemd.user.services.gonic = { + Unit = { + Description = "Gonic media server"; + Documentation = [ "https://github.com/sentriz/gonic/wiki" ]; + After = [ "network.target" ]; + }; + + Service = { + ExecStart = "${lib.getExe' cfg.package "gonic"} -config-path ${settingsFile}"; + Restart = "on-failure"; + }; + + Install.WantedBy = [ "default.target" ]; + }; + }; +} diff --git a/tests/modules/home-manager/default.nix b/tests/modules/home-manager/default.nix index 45567800..3609fa5f 100644 --- a/tests/modules/home-manager/default.nix +++ b/tests/modules/home-manager/default.nix @@ -60,6 +60,7 @@ import nmt { ./services/archivebox ./services/bleachbit ./services/gallery-dl + ./services/gonic ./services/matcha ./services/plover ./services/yt-dlp diff --git a/tests/modules/home-manager/services/gonic/basic.nix b/tests/modules/home-manager/services/gonic/basic.nix new file mode 100644 index 00000000..ab0daa7a --- /dev/null +++ b/tests/modules/home-manager/services/gonic/basic.nix @@ -0,0 +1,19 @@ +{ config, lib, pkgs, ... }: + +{ + services.gonic = { + enable = true; + package = pkgs.gonic; + + settings = { + music-path = [ config.xdg.userDirs.music ]; + podcast-path = [ "${config.xdg.userDirs.music}/Podcasts" ]; + }; + }; + + test.stubs.gonic = { }; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/gonic.service + ''; +} diff --git a/tests/modules/home-manager/services/gonic/default.nix b/tests/modules/home-manager/services/gonic/default.nix new file mode 100644 index 00000000..10ef0b68 --- /dev/null +++ b/tests/modules/home-manager/services/gonic/default.nix @@ -0,0 +1,3 @@ +{ + gonic-basic = ./basic.nix; +}