diff --git a/flake.lock b/flake.lock index 7dbc1cd..b1b5976 100644 --- a/flake.lock +++ b/flake.lock @@ -688,11 +688,11 @@ "treefmt-nix": "treefmt-nix_2" }, "locked": { - "lastModified": 1735551011, - "narHash": "sha256-rp26PcdLjfgxsCeaSeZ0K1rGPN1Ap7YCy1UVuo9gRJA=", + "lastModified": 1735985475, + "narHash": "sha256-7blkWqfcvYKfaL2hpy/nWTooHRfJSqaO0a2+XWccqkE=", "owner": "pizzapim", "repo": "NixNG", - "rev": "aa35f7a3d426e906b15e3083c90bf2972bcfb4b4", + "rev": "dea65c6a83945c755b9d0097aa2535991daeb907", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c875d9f..d1a3a35 100644 --- a/flake.nix +++ b/flake.nix @@ -60,5 +60,6 @@ ./formatter.nix ./shell.nix ./nixng-configurations + ./nixng-modules ]; } diff --git a/nixng-configurations/default.nix b/nixng-configurations/default.nix index cd02779..e70cce2 100644 --- a/nixng-configurations/default.nix +++ b/nixng-configurations/default.nix @@ -37,6 +37,12 @@ in { }; extraModules = [ + self.nixngModules.bazarr + self.nixngModules.radicale + self.nixngModules.jellyseerr + self.nixngModules.radarr + self.nixngModules.sonarr + self.nixngModules.prowlarr { nixpkgs.overlays = [ (final: _prev: { diff --git a/nixng-modules/bazarr.nix b/nixng-modules/bazarr.nix new file mode 100644 index 0000000..4620479 --- /dev/null +++ b/nixng-modules/bazarr.nix @@ -0,0 +1,29 @@ +{ + lib, + config, + pkgs, + ... +}: let + cfg = config.services.bazarr; +in { + options.services.bazarr = { + enable = lib.mkEnableOption "bazarr"; + package = lib.mkPackageOption pkgs "bazarr" {}; + configDir = lib.mkOption { + description = "Where Bazarr's configuration files are stored."; + type = lib.types.str; + default = "/config"; + }; + }; + config = lib.mkIf cfg.enable { + init.services.bazarr = { + enabled = true; + script = pkgs.writeShellScript "bazarr-run" '' + ${lib.getExe cfg.package} \ + --no-update \ + --config '${cfg.configDir}' + ''; + }; + environment.systemPackages = [cfg.package]; + }; +} diff --git a/nixng-modules/default.nix b/nixng-modules/default.nix new file mode 100644 index 0000000..e39eca0 --- /dev/null +++ b/nixng-modules/default.nix @@ -0,0 +1,10 @@ +{...}: { + nixngModules = { + bazarr = import ./bazarr.nix; + radicale = import ./radicale.nix; + jellyseerr = import ./jellyseerr.nix; + radarr = import ./radarr.nix; + sonarr = import ./sonarr.nix; + prowlarr = import ./prowlarr.nix; + }; +} diff --git a/nixng-modules/jellyseerr.nix b/nixng-modules/jellyseerr.nix new file mode 100644 index 0000000..c9179c6 --- /dev/null +++ b/nixng-modules/jellyseerr.nix @@ -0,0 +1,46 @@ +{ + lib, + pkgs, + config, + ... +}: let + cfg = config.services.jellyseerr; +in { + options.services.jellyseerr = { + enable = lib.mkEnableOption "jellyseerr"; + package = lib.mkPackageOption pkgs "jellyseerr" {}; + + port = lib.mkOption { + description = '' + The port Jellyseerr should listen on. + ''; + type = lib.types.port; + example = 8080; + default = 5055; + }; + + configDir = lib.mkOption { + description = '' + The directory to save run-time configuration. + ''; + type = lib.types.str; + example = "/jellyseerr"; + default = "/var/lib/jellyseerr"; + }; + }; + + config = lib.mkIf cfg.enable { + init.services.jellyseerr = { + enabled = true; + script = lib.getExe cfg.package; + }; + + environment = { + systemPackages = [cfg.package]; + variables = { + PORT = builtins.toString cfg.port; + CONFIG_DIRECTORY = cfg.configDir; + }; + }; + }; +} diff --git a/nixng-modules/prowlarr.nix b/nixng-modules/prowlarr.nix new file mode 100644 index 0000000..e8f9677 --- /dev/null +++ b/nixng-modules/prowlarr.nix @@ -0,0 +1,33 @@ +{ + pkgs, + lib, + config, + ... +}: let + cfg = config.services.prowlarr; +in { + options.services.prowlarr = { + enable = lib.mkEnableOption "prowlarr"; + package = lib.mkPackageOption pkgs "prowlarr" {}; + + dataDir = lib.mkOption { + description = "Directory to store Prowlarr's data"; + type = lib.types.str; + default = "/config"; + }; + }; + + config = lib.mkIf cfg.enable { + init.services.prowlarr = { + enabled = true; + + script = pkgs.writeShellScript "prowlarr-run" '' + ${lib.getExe cfg.package} \ + -nobrowser \ + -data=${cfg.dataDir} + ''; + }; + + environment.systemPackages = [cfg.package]; + }; +} diff --git a/nixng-modules/radarr.nix b/nixng-modules/radarr.nix new file mode 100644 index 0000000..aa6af40 --- /dev/null +++ b/nixng-modules/radarr.nix @@ -0,0 +1,31 @@ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.services.radarr; +in { + options.services.radarr = { + enable = lib.mkEnableOption "radarr"; + package = lib.mkPackageOption pkgs "radarr" {}; + + dataDir = lib.mkOption { + type = lib.types.str; + default = "/var/lib/radarr/.config/Radarr"; + description = "The directory where Radarr stores its data files."; + }; + }; + + config = lib.mkIf cfg.enable { + init.services.radarr = { + enabled = true; + + script = pkgs.writeShellScript "radarr-run.sh" '' + ${lib.getExe cfg.package} -nobrowser -data='${cfg.dataDir}' + ''; + }; + + environment.systemPackages = [cfg.package]; + }; +} diff --git a/nixng-modules/radicale.nix b/nixng-modules/radicale.nix new file mode 100644 index 0000000..f12b0bd --- /dev/null +++ b/nixng-modules/radicale.nix @@ -0,0 +1,75 @@ +{ + lib, + pkgs, + config, + nglib, + ... +}: let + cfg = config.services.radicale; + + settingsFormat = pkgs.formats.ini { + listToValue = lib.concatMapStringsSep ", " (lib.generators.mkValueStringDefault {}); + }; +in { + options.services.radicale = { + enable = lib.mkEnableOption "radicale"; + package = lib.mkPackageOption pkgs "radicale" {}; + user = lib.mkOption { + description = "radicale user"; + type = lib.types.str; + default = "radicale"; + }; + group = lib.mkOption { + description = "radicale group"; + type = lib.types.str; + default = "radicale"; + }; + settings = lib.mkOption { + type = settingsFormat.type; + default = {}; + description = '' + Configuration for Radicale. See + . + ''; + example = lib.literalExpression '' + server = { + hosts = [ "0.0.0.0:5232" "[::]:5232" ]; + }; + auth = { + type = "htpasswd"; + htpasswd_filename = "/etc/radicale/users"; + htpasswd_encryption = "bcrypt"; + }; + storage = { + filesystem_folder = "/var/lib/radicale/collections"; + }; + ''; + }; + }; + config = lib.mkIf cfg.enable (let + configFile = settingsFormat.generate "radicale.ini" cfg.settings; + in { + init.services.radicale = { + enabled = true; + script = pkgs.writeShellScript "radicale-run" '' + chpst -u ${cfg.user}:${cfg.group} ${cfg.package}/bin/radicale \ + --config ${configFile} + ''; + }; + environment.systemPackages = [cfg.package]; + users.users.${cfg.user} = nglib.mkDefaultRec { + description = "radicale"; + group = cfg.group; + createHome = false; + home = "/var/empty"; + useDefaultShell = true; + uid = config.ids.uids.radicale; + }; + users.groups.${cfg.group} = nglib.mkDefaultRec {gid = config.ids.gids.radicale;}; + + ids = { + uids.radicale = 408; + gids.radicale = 408; + }; + }); +} diff --git a/nixng-modules/sonarr.nix b/nixng-modules/sonarr.nix new file mode 100644 index 0000000..5ebff69 --- /dev/null +++ b/nixng-modules/sonarr.nix @@ -0,0 +1,31 @@ +{ + lib, + config, + pkgs, + ... +}: let + cfg = config.services.sonarr; +in { + options.services.sonarr = { + enable = lib.mkEnableOption "sonarr"; + package = lib.mkPackageOption pkgs "sonarr" {}; + + dataDir = lib.mkOption { + type = lib.types.str; + default = "/var/lib/sonarr/.config/NzbDrone"; + description = "The directory where Sonarr stores its data files."; + }; + }; + + config = lib.mkIf cfg.enable { + init.services.sonarr = { + enabled = true; + + script = pkgs.writeShellScript "sonarr-run" '' + ${lib.getExe cfg.package} -nobrowser -data=${cfg.dataDir} + ''; + }; + + environment.systemPackages = [cfg.package]; + }; +}