at 24.11-pre 1.6 kB view raw
1{ config, lib, pkgs, ... }: 2with lib; 3 4let 5 cfg = config.services.dante; 6 confFile = pkgs.writeText "dante-sockd.conf" '' 7 user.privileged: root 8 user.unprivileged: dante 9 logoutput: syslog 10 11 ${cfg.config} 12 ''; 13in 14 15{ 16 meta = { 17 maintainers = with maintainers; [ arobyn ]; 18 }; 19 20 options = { 21 services.dante = { 22 enable = mkEnableOption "Dante SOCKS proxy"; 23 24 config = mkOption { 25 type = types.lines; 26 description = '' 27 Contents of Dante's configuration file. 28 NOTE: user.privileged, user.unprivileged and logoutput are set by the service. 29 ''; 30 }; 31 }; 32 }; 33 34 config = mkIf cfg.enable { 35 assertions = [ 36 { assertion = cfg.config != ""; 37 message = "please provide Dante configuration file contents"; 38 } 39 ]; 40 41 users.users.dante = { 42 description = "Dante SOCKS proxy daemon user"; 43 isSystemUser = true; 44 group = "dante"; 45 }; 46 users.groups.dante = {}; 47 48 systemd.services.dante = { 49 description = "Dante SOCKS v4 and v5 compatible proxy server"; 50 wants = [ "network-online.target" ]; 51 after = [ "network-online.target" ]; 52 wantedBy = [ "multi-user.target" ]; 53 54 serviceConfig = { 55 Type = "simple"; 56 ExecStart = "${pkgs.dante}/bin/sockd -f ${confFile}"; 57 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 58 # Can crash sometimes; see https://github.com/NixOS/nixpkgs/pull/39005#issuecomment-381828708 59 Restart = "on-failure"; 60 }; 61 }; 62 }; 63}