m 3 rtorrent: mkIf, recursiveUpdate and multiple changes in systemd.services and nginx config do not work well together it seems

This commit is contained in:
makefu 2016-08-24 00:14:43 +02:00
parent 7110552e30
commit 5231d21dfb
No known key found for this signature in database
GPG Key ID: 36F7711F3FC0F225

View File

@ -8,8 +8,11 @@ let
nginx-user = config.services.nginx.user; nginx-user = config.services.nginx.user;
nginx-group = config.services.nginx.group; nginx-group = config.services.nginx.group;
fpm-socket = "/var/run/php5-fpm-rutorrent.sock";
webdir = rucfg.webdir;
rutorrent-deps = with pkgs; [ curl php coreutils procps ffmpeg mediainfo ] ++ rutorrent-deps = with pkgs; [ curl php coreutils procps ffmpeg mediainfo ] ++
(if config.nixpkgs.config.allowUnfree then (if (config.nixpkgs.config.allowUnfree or false) then
trace "enabling unfree packages for rutorrent" [ unrar unzip ] else trace "enabling unfree packages for rutorrent" [ unrar unzip ] else
trace "not enabling unfree packages for rutorrent because allowUnfree is unset" []) trace "not enabling unfree packages for rutorrent because allowUnfree is unset" [])
; ;
@ -34,7 +37,6 @@ let
echo "replacing scgi port and host variable in conf/config.php" echo "replacing scgi port and host variable in conf/config.php"
''; '';
}; };
fpm-socket = "/var/run/php5-fpm.sock";
systemd-logfile = cfg.workDir + "/rtorrent-systemd.log"; systemd-logfile = cfg.workDir + "/rtorrent-systemd.log";
configFile = pkgs.writeText "rtorrent-config" '' configFile = pkgs.writeText "rtorrent-config" ''
# THIS FILE IS AUTOGENERATED # THIS FILE IS AUTOGENERATED
@ -73,9 +75,12 @@ let
out = { out = {
options.makefu.rtorrent = api; options.makefu.rtorrent = api;
config = lib.recursiveUpdate (lib.mkIf cfg.enable imp) # This only works because none of the attrsets returns the same key
( lib.recursiveUpdate (lib.mkIf cfg.web.enable rpcweb-imp) config = with lib; mkIf cfg.enable (lib.mkMerge [
(lib.mkIf cfg.rutorrent.enable rutorrent-imp)); (lib.mkIf webcfg.enable rpcweb-imp)
(lib.mkIf rucfg.enable rutorrent-imp)
imp
]);
}; };
api = { api = {
@ -91,7 +96,7 @@ let
description ='' description =''
nginx listen address for rtorrent web nginx listen address for rtorrent web
''; '';
default = "localhost:8005"; default = "localhost:8006";
}; };
enableAuth = mkEnableOption "rutorrent authentication"; enableAuth = mkEnableOption "rutorrent authentication";
@ -225,7 +230,8 @@ let
}; };
imp = { imp = {
systemd.services.rtorrent-daemon = { systemd.services = {
rtorrent-daemon = {
description = "rtorrent headless"; description = "rtorrent headless";
after = [ "network.target" ]; after = [ "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
@ -234,6 +240,7 @@ let
Type = "forking"; Type = "forking";
ExecStartPre = pkgs.writeDash "prepare-folder" '' ExecStartPre = pkgs.writeDash "prepare-folder" ''
mkdir -p ${cfg.workDir} ${cfg.sessionDir} mkdir -p ${cfg.workDir} ${cfg.sessionDir}
chmod 770 ${cfg.workDir} ${cfg.sessionDir}
touch ${systemd-logfile} touch ${systemd-logfile}
cp -f ${configFile} ${cfg.workDir}/.rtorrent.rc cp -f ${configFile} ${cfg.workDir}/.rtorrent.rc
''; '';
@ -246,9 +253,8 @@ let
Restart = "on-failure"; Restart = "on-failure";
User = "${cfg.user}"; User = "${cfg.user}";
}; };
}; };
systemd.services.rtorrent-log = { rtorrent-log = {
after = [ "rtorrent-daemon.service" ]; after = [ "rtorrent-daemon.service" ];
bindsTo = [ "rtorrent-daemon.service" ]; bindsTo = [ "rtorrent-daemon.service" ];
wantedBy = [ "rtorrent-daemon.service" ]; wantedBy = [ "rtorrent-daemon.service" ];
@ -257,44 +263,8 @@ let
User = "${cfg.user}"; User = "${cfg.user}";
}; };
}; };
} // (optionalAttrs webcfg.enable {
users = lib.mkIf (cfg.user == "rtorrent") { rutorrent-prepare = {
users.rtorrent = {
uid = genid "rtorrent";
home = cfg.workDir;
group = nginx-group;
shell = "/bin/sh"; #required for tmux
createHome = true;
};
groups.rtorrent.gid = genid "rtorrent";
};
};
rpcweb-imp = {
krebs.nginx.enable = mkDefault true;
krebs.nginx.servers.rtorrent = {
listen = [ webcfg.listenAddress ];
server-names = [ "default" ];
extraConfig = ''
${optionalString webcfg.enableAuth ''
auth_basic "rtorrent";
auth_basic_user_file ${webcfg.authfile};
''}
'';
locations = [
(nameValuePair "/RPC2" ''
include ${pkgs.nginx}/conf/scgi_params;
scgi_param SCRIPT_NAME /RPC2;
scgi_pass unix:${cfg.xmlrpc-socket};
'')
];
};
};
rutorrent-imp = let
webdir = rucfg.webdir;
in {
systemd.services.rutorrent-prepare = {
after = [ "rtorrent-daemon.service" ]; after = [ "rtorrent-daemon.service" ];
bindsTo = [ "rtorrent-daemon.service" ]; bindsTo = [ "rtorrent-daemon.service" ];
wantedBy = [ "rtorrent-daemon.service" ]; wantedBy = [ "rtorrent-daemon.service" ];
@ -314,12 +284,43 @@ let
''; '';
}; };
}; };
})
// (optionalAttrs rucfg.enable { });
users = lib.mkIf (cfg.user == "rtorrent") {
users.rtorrent = {
uid = genid "rtorrent";
home = cfg.workDir;
group = nginx-group;
shell = "/bin/sh"; #required for tmux
isSystemUser = true;
createHome = true;
};
groups.rtorrent.gid = genid "rtorrent";
};
};
rpcweb-imp = {
krebs.nginx.enable = mkDefault true;
krebs.nginx.servers.rtorrent = { krebs.nginx.servers.rtorrent = {
listen = [ webcfg.listenAddress ];
server-names = [ "default" ];
extraConfig = '' extraConfig = ''
${optionalString webcfg.enableAuth ''
auth_basic "rtorrent";
auth_basic_user_file ${webcfg.authfile};
''}
${optionalString rucfg.enable ''
root ${webdir}; root ${webdir};
''}
''; '';
locations = [ locations = [
(nameValuePair "/RPC2" ''
include ${pkgs.nginx}/conf/scgi_params;
scgi_param SCRIPT_NAME /RPC2;
scgi_pass unix:${cfg.xmlrpc-socket};
'')
] ++ (optional rucfg.enable
(nameValuePair "~ \.php$" '' (nameValuePair "~ \.php$" ''
client_max_body_size 200M; client_max_body_size 200M;
root ${webdir}; root ${webdir};
@ -330,22 +331,20 @@ let
include ${pkgs.nginx}/conf/fastcgi_params; include ${pkgs.nginx}/conf/fastcgi_params;
include ${pkgs.nginx}/conf/fastcgi.conf; include ${pkgs.nginx}/conf/fastcgi.conf;
'') '')
);
];
}; };
};
rutorrent-imp = {
services.phpfpm = { services.phpfpm = {
# phpfpm does not have an enable option # phpfpm does not have an enable option
poolConfigs = let poolConfigs = {
user = config.services.nginx.user;
group = config.services.nginx.group;
fpm-socket = "/var/run/php5-fpm.sock";
in {
rutorrent = '' rutorrent = ''
user = ${user} user = ${nginx-user}
group = ${group} group = ${nginx-group}
listen = ${fpm-socket} listen = ${fpm-socket}
listen.owner = ${user} listen.owner = ${nginx-user}
listen.group = ${group} listen.group = ${nginx-group}
pm = dynamic pm = dynamic
pm.max_children = 5 pm.max_children = 5
pm.start_servers = 2 pm.start_servers = 2
@ -356,7 +355,6 @@ let
php_admin_value[error_log] = 'stderr' php_admin_value[error_log] = 'stderr'
php_admin_flag[log_errors] = on php_admin_flag[log_errors] = on
catch_workers_output = yes catch_workers_output = yes
env[PATH] = ${makeBinPath rutorrent-deps}
''; '';
}; };
}; };