nixos: add peerflix module

This commit is contained in:
Jaka Hudoklin 2014-12-01 16:40:42 +01:00
parent b90b899b0c
commit 3424ded286
4 changed files with 86 additions and 0 deletions

View File

@ -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!

View File

@ -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

View File

@ -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;
};
}

21
nixos/tests/peerflix.nix Normal file
View File

@ -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");
'';
}