From 3424ded286db756b62de7e579369bbb9d1ddac84 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Mon, 1 Dec 2014 16:40:42 +0100 Subject: [PATCH] nixos: add peerflix module --- nixos/modules/misc/ids.nix | 1 + nixos/modules/module-list.nix | 1 + nixos/modules/services/torrent/peerflix.nix | 63 +++++++++++++++++++++ nixos/tests/peerflix.nix | 21 +++++++ 4 files changed, 86 insertions(+) create mode 100644 nixos/modules/services/torrent/peerflix.nix create mode 100644 nixos/tests/peerflix.nix diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index f7b8737fa4d..687e26279e6 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -170,6 +170,7 @@ scollector = 160; bosun = 161; kubernetes = 162; + peerflix = 163; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index ecf68136f97..9f4f33d137f 100755 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -309,6 +309,7 @@ ./services/system/nscd.nix ./services/system/uptimed.nix ./services/torrent/deluge.nix + ./services/torrent/peerflix.nix ./services/torrent/transmission.nix ./services/ttys/agetty.nix ./services/ttys/gpm.nix diff --git a/nixos/modules/services/torrent/peerflix.nix b/nixos/modules/services/torrent/peerflix.nix new file mode 100644 index 00000000000..e9f5439ffa3 --- /dev/null +++ b/nixos/modules/services/torrent/peerflix.nix @@ -0,0 +1,63 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.peerflix; + + configFile = pkgs.writeText "peerflix-config.json" '' + { + "connections": 50, + "tmp": "${cfg.downloadDir}" + } + ''; + +in { + + ###### interface + + options.services.peerflix = { + enable = mkOption { + description = "Whether to enable graphite web frontend."; + default = false; + type = types.uniq types.bool; + }; + + stateDir = mkOption { + description = "Peerflix state directory."; + default = "/var/lib/peerflix"; + type = types.path; + }; + + downloadDir = mkOption { + description = "Peerflix temporary download directory."; + default = "${cfg.stateDir}/torrents"; + type = types.path; + }; + }; + + ###### implementation + + config = mkIf cfg.enable { + systemd.services.peerflix = { + description = "Peerflix Daemon"; + wantedBy = [ "multi-user.target" ]; + after = [ "network-interfaces.target" ]; + environment.HOME = cfg.stateDir; + + preStart = '' + mkdir -p "${cfg.stateDir}"/{torrents,.config/peerflix-server} + if [ "$(id -u)" = 0 ]; then chown -R peerflix "${cfg.stateDir}"; fi + ln -fs "${configFile}" "${cfg.stateDir}/.config/peerflix-server/config.json" + ''; + + serviceConfig = { + ExecStart = "${pkgs.nodePackages.peerflix-server}/bin/peerflix-server"; + PermissionsStartOnly = true; + User = "peerflix"; + }; + }; + + users.extraUsers.peerflix.uid = config.ids.uids.peerflix; + }; +} diff --git a/nixos/tests/peerflix.nix b/nixos/tests/peerflix.nix new file mode 100644 index 00000000000..739936a10b2 --- /dev/null +++ b/nixos/tests/peerflix.nix @@ -0,0 +1,21 @@ +# This test runs peerflix and checks if peerflix starts + +import ./make-test.nix { + name = "peerflix"; + + nodes = { + peerflix = + { config, pkgs, ... }: + { + services.peerflix.enable = true; + }; + }; + + testScript = '' + startAll; + + $peerflix->waitForUnit("peerflix.service"); + $peerflix->waitUntilSucceeds("curl localhost:9000"); + ''; + +}