at 21.11-pre 5.0 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.programs.x2goserver; 7 8 defaults = { 9 superenicer = { enable = cfg.superenicer.enable; }; 10 }; 11 confText = generators.toINI {} (recursiveUpdate defaults cfg.settings); 12 x2goServerConf = pkgs.writeText "x2goserver.conf" confText; 13 14 x2goAgentOptions = pkgs.writeText "x2goagent.options" '' 15 X2GO_NXOPTIONS="" 16 X2GO_NXAGENT_DEFAULT_OPTIONS="${concatStringsSep " " cfg.nxagentDefaultOptions}" 17 ''; 18 19in { 20 options.programs.x2goserver = { 21 enable = mkEnableOption "x2goserver" // { 22 description = '' 23 Enables the x2goserver module. 24 NOTE: This will create a good amount of symlinks in `/usr/local/bin` 25 ''; 26 }; 27 28 superenicer = { 29 enable = mkEnableOption "superenicer" // { 30 description = '' 31 Enables the SupeReNicer code in x2gocleansessions, this will renice 32 suspended sessions to nice level 19 and renice them to level 0 if the 33 session becomes marked as running again 34 ''; 35 }; 36 }; 37 38 nxagentDefaultOptions = mkOption { 39 type = types.listOf types.str; 40 default = [ "-extension GLX" "-nolisten tcp" ]; 41 example = [ "-extension GLX" "-nolisten tcp" ]; 42 description = '' 43 List of default nx agent options. 44 ''; 45 }; 46 47 settings = mkOption { 48 type = types.attrsOf types.attrs; 49 default = {}; 50 description = '' 51 x2goserver.conf ini configuration as nix attributes. See 52 `x2goserver.conf(5)` for details 53 ''; 54 example = literalExample '' 55 superenicer = { 56 "enable" = "yes"; 57 "idle-nice-level" = 19; 58 }; 59 telekinesis = { "enable" = "no"; }; 60 ''; 61 }; 62 }; 63 64 config = mkIf cfg.enable { 65 66 environment.systemPackages = [ pkgs.x2goserver ]; 67 68 users.groups.x2go = {}; 69 users.users.x2go = { 70 home = "/var/lib/x2go/db"; 71 group = "x2go"; 72 isSystemUser = true; 73 }; 74 75 security.wrappers.x2gosqliteWrapper = { 76 source = "${pkgs.x2goserver}/lib/x2go/libx2go-server-db-sqlite3-wrapper.pl"; 77 owner = "x2go"; 78 group = "x2go"; 79 setgid = true; 80 }; 81 security.wrappers.x2goprintWrapper = { 82 source = "${pkgs.x2goserver}/bin/x2goprint"; 83 owner = "x2go"; 84 group = "x2go"; 85 setgid = true; 86 }; 87 88 systemd.tmpfiles.rules = with pkgs; [ 89 "d /var/lib/x2go/ - x2go x2go - -" 90 "d /var/lib/x2go/db - x2go x2go - -" 91 "d /var/lib/x2go/conf - x2go x2go - -" 92 "d /run/x2go 0755 x2go x2go - -" 93 ] ++ 94 # x2goclient sends SSH commands with preset PATH set to 95 # "/usr/local/bin;/usr/bin;/bin". Since we cannot filter arbitrary ssh 96 # commands, we have to make the following executables available. 97 map (f: "L+ /usr/local/bin/${f} - - - - ${x2goserver}/bin/${f}") [ 98 "x2goagent" "x2gobasepath" "x2gocleansessions" "x2gocmdexitmessage" 99 "x2godbadmin" "x2gofeature" "x2gofeaturelist" "x2gofm" "x2gogetapps" 100 "x2gogetservers" "x2golistdesktops" "x2golistmounts" "x2golistsessions" 101 "x2golistsessions_root" "x2golistshadowsessions" "x2gomountdirs" 102 "x2gopath" "x2goprint" "x2goresume-desktopsharing" "x2goresume-session" 103 "x2goruncommand" "x2goserver-run-extensions" "x2gosessionlimit" 104 "x2gosetkeyboard" "x2goshowblocks" "x2gostartagent" 105 "x2gosuspend-desktopsharing" "x2gosuspend-session" 106 "x2goterminate-desktopsharing" "x2goterminate-session" 107 "x2goumount-session" "x2goversion" 108 ] ++ [ 109 "L+ /usr/local/bin/awk - - - - ${gawk}/bin/awk" 110 "L+ /usr/local/bin/chmod - - - - ${coreutils}/bin/chmod" 111 "L+ /usr/local/bin/cp - - - - ${coreutils}/bin/cp" 112 "L+ /usr/local/bin/sed - - - - ${gnused}/bin/sed" 113 "L+ /usr/local/bin/setsid - - - - ${util-linux}/bin/setsid" 114 "L+ /usr/local/bin/xrandr - - - - ${xorg.xrandr}/bin/xrandr" 115 "L+ /usr/local/bin/xmodmap - - - - ${xorg.xmodmap}/bin/xmodmap" 116 ]; 117 118 systemd.services.x2goserver = { 119 description = "X2Go Server Daemon"; 120 wantedBy = [ "multi-user.target" ]; 121 unitConfig.Documentation = "man:x2goserver.conf(5)"; 122 serviceConfig = { 123 Type = "forking"; 124 ExecStart = "${pkgs.x2goserver}/bin/x2gocleansessions"; 125 PIDFile = "/run/x2go/x2goserver.pid"; 126 User = "x2go"; 127 Group = "x2go"; 128 RuntimeDirectory = "x2go"; 129 StateDirectory = "x2go"; 130 }; 131 preStart = '' 132 if [ ! -e /var/lib/x2go/setup_ran ] 133 then 134 mkdir -p /var/lib/x2go/conf 135 cp -r ${pkgs.x2goserver}/etc/x2go/* /var/lib/x2go/conf/ 136 ln -sf ${x2goServerConf} /var/lib/x2go/conf/x2goserver.conf 137 ln -sf ${x2goAgentOptions} /var/lib/x2go/conf/x2goagent.options 138 ${pkgs.x2goserver}/bin/x2godbadmin --createdb 139 touch /var/lib/x2go/setup_ran 140 fi 141 ''; 142 }; 143 144 # https://bugs.x2go.org/cgi-bin/bugreport.cgi?bug=276 145 security.sudo.extraConfig = '' 146 Defaults env_keep+=QT_GRAPHICSSYSTEM 147 ''; 148 }; 149}