1 { config, lib, options, pkgs, ... }:
6 cfg = config.services.peerflix;
7 opt = options.services.peerflix;
9 configFile = pkgs.writeText "peerflix-config.json" ''
12 "tmp": "${cfg.downloadDir}"
20 options.services.peerflix = {
22 description = "Whether to enable peerflix service.";
28 description = "Peerflix state directory.";
29 default = "/var/lib/peerflix";
33 downloadDir = mkOption {
34 description = "Peerflix temporary download directory.";
35 default = "${cfg.stateDir}/torrents";
36 defaultText = literalExpression ''"''${config.${opt.stateDir}}/torrents"'';
43 config = mkIf cfg.enable {
44 systemd.tmpfiles.rules = [
45 "d '${cfg.stateDir}' - peerflix - - -"
48 systemd.services.peerflix = {
49 description = "Peerflix Daemon";
50 wantedBy = [ "multi-user.target" ];
51 after = [ "network.target" ];
52 environment.HOME = cfg.stateDir;
55 mkdir -p "${cfg.stateDir}"/{torrents,.config/peerflix-server}
56 ln -fs "${configFile}" "${cfg.stateDir}/.config/peerflix-server/config.json"
60 ExecStart = "${pkgs.nodePackages.peerflix-server}/bin/peerflix-server";
65 users.users.peerflix = {
69 users.groups.peerflix = {};