2016-10-14 05:07:59 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.dante;
|
|
|
|
confFile = pkgs.writeText "dante-sockd.conf" ''
|
|
|
|
user.privileged: root
|
|
|
|
user.unprivileged: dante
|
2018-04-16 12:15:09 +00:00
|
|
|
logoutput: syslog
|
2016-10-14 05:07:59 +00:00
|
|
|
|
|
|
|
${cfg.config}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
maintainers = with maintainers; [ arobyn ];
|
|
|
|
};
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.dante = {
|
|
|
|
enable = mkEnableOption "Dante SOCKS proxy";
|
|
|
|
|
|
|
|
config = mkOption {
|
2018-04-16 12:15:09 +00:00
|
|
|
type = types.lines;
|
2016-10-14 05:07:59 +00:00
|
|
|
description = ''
|
2018-04-16 12:15:09 +00:00
|
|
|
Contents of Dante's configuration file.
|
|
|
|
NOTE: user.privileged, user.unprivileged and logoutput are set by the service.
|
2016-10-14 05:07:59 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
2018-04-16 12:15:09 +00:00
|
|
|
{ assertion = cfg.config != "";
|
2016-10-14 05:07:59 +00:00
|
|
|
message = "please provide Dante configuration file contents";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
users.users.dante = {
|
|
|
|
description = "Dante SOCKS proxy daemon user";
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "dante";
|
|
|
|
};
|
|
|
|
users.groups.dante = {};
|
|
|
|
|
|
|
|
systemd.services.dante = {
|
|
|
|
description = "Dante SOCKS v4 and v5 compatible proxy server";
|
2018-02-17 10:18:05 +00:00
|
|
|
after = [ "network-online.target" ];
|
2016-10-14 05:07:59 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = "${pkgs.dante}/bin/sockd -f ${confFile}";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
2018-04-16 12:14:13 +00:00
|
|
|
# Can crash sometimes; see https://github.com/NixOS/nixpkgs/pull/39005#issuecomment-381828708
|
|
|
|
Restart = "on-failure";
|
2016-10-14 05:07:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|