Merge pull request #65283 from averelld/add-x2goserver-module

Add x2goserver module
This commit is contained in:
Silvan Mosberger 2019-08-31 17:49:41 +02:00 committed by GitHub
commit 4727a40be9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 256 additions and 0 deletions

View File

@ -159,6 +159,7 @@
./programs/way-cooler.nix
./programs/waybar.nix
./programs/wireshark.nix
./programs/x2goserver.nix
./programs/xfs_quota.nix
./programs/xonsh.nix
./programs/xss-lock.nix

View File

@ -0,0 +1,148 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.x2goserver;
defaults = {
superenicer = { "enable" = cfg.superenicer.enable; };
};
confText = generators.toINI {} (recursiveUpdate defaults cfg.settings);
x2goServerConf = pkgs.writeText "x2goserver.conf" confText;
x2goAgentOptions = pkgs.writeText "x2goagent.options" ''
X2GO_NXOPTIONS=""
X2GO_NXAGENT_DEFAULT_OPTIONS="${concatStringsSep " " cfg.nxagentDefaultOptions}"
'';
in {
options.programs.x2goserver = {
enable = mkEnableOption "x2goserver" // {
description = ''
Enables the x2goserver module.
NOTE: This will create a good amount of symlinks in `/usr/local/bin`
'';
};
superenicer = {
enable = mkEnableOption "superenicer" // {
description = ''
Enables the SupeReNicer code in x2gocleansessions, this will renice
suspended sessions to nice level 19 and renice them to level 0 if the
session becomes marked as running again
'';
};
};
nxagentDefaultOptions = mkOption {
type = types.listOf types.str;
default = [ "-extension GLX" "-nolisten tcp" ];
example = [ "-extension GLX" "-nolisten tcp" ];
description = ''
List of default nx agent options.
'';
};
settings = mkOption {
type = types.attrsOf types.attrs;
default = {};
description = ''
x2goserver.conf ini configuration as nix attributes. See
`x2goserver.conf(5)` for details
'';
example = literalExample ''
superenicer = {
"enable" = "yes";
"idle-nice-level" = 19;
};
telekinesis = { "enable" = "no"; };
'';
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.x2goserver ];
users.groups.x2go = {};
users.users.x2go = {
home = "/var/lib/x2go/db";
group = "x2go";
};
security.wrappers.x2gosqliteWrapper = {
source = "${pkgs.x2goserver}/lib/x2go/libx2go-server-db-sqlite3-wrapper.pl";
owner = "x2go";
group = "x2go";
setgid = true;
};
security.wrappers.x2goprintWrapper = {
source = "${pkgs.x2goserver}/bin/x2goprint";
owner = "x2go";
group = "x2go";
setgid = true;
};
systemd.tmpfiles.rules = with pkgs; [
"d /var/lib/x2go/ - x2go x2go - -"
"d /var/lib/x2go/db - x2go x2go - -"
"d /var/lib/x2go/conf - x2go x2go - -"
"d /run/x2go 0755 x2go x2go - -"
] ++
# x2goclient sends SSH commands with preset PATH set to
# "/usr/local/bin;/usr/bin;/bin". Since we cannot filter arbitrary ssh
# commands, we have to make the following executables available.
map (f: "L+ /usr/local/bin/${f} - - - - ${x2goserver}/bin/${f}") [
"x2goagent" "x2gobasepath" "x2gocleansessions" "x2gocmdexitmessage"
"x2godbadmin" "x2gofeature" "x2gofeaturelist" "x2gofm" "x2gogetapps"
"x2gogetservers" "x2golistdesktops" "x2golistmounts" "x2golistsessions"
"x2golistsessions_root" "x2golistshadowsessions" "x2gomountdirs"
"x2gopath" "x2goprint" "x2goresume-desktopsharing" "x2goresume-session"
"x2goruncommand" "x2goserver-run-extensions" "x2gosessionlimit"
"x2gosetkeyboard" "x2goshowblocks" "x2gostartagent"
"x2gosuspend-desktopsharing" "x2gosuspend-session"
"x2goterminate-desktopsharing" "x2goterminate-session"
"x2goumount-session" "x2goversion"
] ++ [
"L+ /usr/local/bin/awk - - - - ${gawk}/bin/awk"
"L+ /usr/local/bin/chmod - - - - ${coreutils}/bin/chmod"
"L+ /usr/local/bin/cp - - - - ${coreutils}/bin/cp"
"L+ /usr/local/bin/sed - - - - ${gnused}/bin/sed"
"L+ /usr/local/bin/setsid - - - - ${utillinux}/bin/setsid"
"L+ /usr/local/bin/xrandr - - - - ${xorg.xrandr}/bin/xrandr"
"L+ /usr/local/bin/xmodmap - - - - ${xorg.xmodmap}/bin/xmodmap"
];
systemd.services.x2goserver = {
description = "X2Go Server Daemon";
wantedBy = [ "multi-user.target" ];
unitConfig.Documentation = "man:x2goserver.conf(5)";
serviceConfig = {
Type = "forking";
ExecStart = "${pkgs.x2goserver}/bin/x2gocleansessions";
PIDFile = "/run/x2go/x2goserver.pid";
User = "x2go";
Group = "x2go";
RuntimeDirectory = "x2go";
StateDirectory = "x2go";
};
preStart = ''
if [ ! -e /var/lib/x2go/setup_ran ]
then
mkdir -p /var/lib/x2go/conf
cp -r ${pkgs.x2goserver}/etc/x2go/* /var/lib/x2go/conf/
ln -sf ${x2goServerConf} /var/lib/x2go/conf/x2goserver.conf
ln -sf ${x2goAgentOptions} /var/lib/x2go/conf/x2goagent.options
${pkgs.x2goserver}/bin/x2godbadmin --createdb
touch /var/lib/x2go/setup_ran
fi
'';
};
# https://bugs.x2go.org/cgi-bin/bugreport.cgi?bug=276
security.sudo.extraConfig = ''
Defaults env_keep+=QT_GRAPHICSSYSTEM
'';
};
}

View File

@ -0,0 +1,93 @@
{ stdenv, lib, fetchurl, perlPackages, makeWrapper, perl, which, nx-libs
, utillinux, coreutils, glibc, gawk, gnused, gnugrep, findutils, xorg
, nettools, iproute, bc, procps, psmisc, lsof, pwgen, openssh, sshfs, bash
}:
let
pname = "x2goserver";
version = "4.1.0.3";
src = fetchurl {
url = "http://code.x2go.org/releases/source/x2goserver/${pname}-${version}.tar.gz";
sha256 = "1l6wd708kbipib4ldprfiihqmj4895nifg0bkws4x97majislxk7";
};
x2go-perl = perlPackages.buildPerlPackage rec {
pname = "X2Go";
inherit version src;
makeFlags = [ "-f" "Makefile.perl" ];
patchPhase = ''
substituteInPlace X2Go/Config.pm --replace '/etc/x2go' '/var/lib/x2go/conf'
substituteInPlace X2Go/Server/DB.pm \
--replace '$x2go_lib_path/libx2go-server-db-sqlite3-wrapper' \
'/run/wrappers/bin/x2gosqliteWrapper'
substituteInPlace X2Go/Server/DB/SQLite3.pm --replace "user='x2gouser'" "user='x2go'"
'';
};
perlEnv = perl.withPackages (p: with p; [
x2go-perl DBI DBDSQLite FileBaseDir TryTiny CaptureTiny ConfigSimple Switch
]);
binaryDeps = [
perlEnv which nx-libs utillinux coreutils glibc.bin gawk gnused gnugrep
findutils nettools iproute bc procps psmisc lsof pwgen openssh sshfs
xorg.xauth xorg.xinit xorg.xrandr xorg.xmodmap xorg.xwininfo xorg.fontutil
xorg.xkbcomp xorg.setxkbmap
];
in
stdenv.mkDerivation rec {
inherit pname version src;
buildInputs = [ perlEnv bash ];
nativeBuildInputs = [ makeWrapper ];
prePatch = ''
patchShebangs .
sed -i '/Makefile.PL\|Makefile.perl/d' Makefile
for i in */Makefile; do
substituteInPlace "$i" --replace "-o root -g root " ""
done
substituteInPlace libx2go-server-db-perl/Makefile --replace "chmod 2755" "chmod 755"
for i in x2goserver/sbin/x2godbadmin x2goserver/bin/x2go*
do
substituteInPlace $i --replace '/etc/x2go' '/var/lib/x2go/conf'
done
substituteInPlace x2goserver/sbin/x2gocleansessions \
--replace '/var/run/x2goserver.pid' '/var/run/x2go/x2goserver.pid'
substituteInPlace x2goserver/sbin/x2godbadmin --replace 'user="x2gouser"' 'user="x2go"'
substituteInPlace x2goserver-xsession/etc/Xsession \
--replace "SSH_AGENT /bin/bash -c" "SSH_AGENT ${bash}/bin/bash -c" \
--replace "[ -f /etc/redhat-release ]" "[ -d /etc/nix ] || [ -f /etc/redhat-release ]"
'';
makeFlags = [ "PREFIX=/" "NXLIBDIR=${nx-libs}/lib/nx" ];
installFlags = [ "DESTDIR=$(out)" ];
postInstall = ''
mv $out/etc/x2go/x2goserver.conf{,.example}
mv $out/etc/x2go/x2goagent.options{,.example}
ln -sf ${nx-libs}/bin/nxagent $out/bin/x2goagent
for i in $out/sbin/x2go* $(find $out/bin -type f) \
$(ls $out/lib/x2go/x2go* | grep -v x2gocheckport)
do
wrapProgram $i --prefix PATH : ${lib.makeBinPath binaryDeps}:$out
done
# We're patching @INC of the setgid wrapper, because we can't mix
# the perl wrapper (for PERL5LIB) with security.wrappers (for setgid)
sed -ie "s,.\+bin/perl,#!${perl}/bin/perl -I ${perlEnv}/lib/perl5/site_perl," \
$out/lib/x2go/libx2go-server-db-sqlite3-wrapper.pl
'';
enableParallelBuilding = true;
meta = with stdenv.lib; {
description = "Remote desktop application, server component";
homepage = "http://x2go.org/";
platforms = stdenv.lib.platforms.linux;
license = licenses.gpl2;
maintainers = [ maintainers.averelld ];
};
}

View File

@ -21333,6 +21333,8 @@ in
x2goclient = libsForQt5.callPackage ../applications/networking/remote/x2goclient { };
x2goserver = callPackage ../applications/networking/remote/x2goserver { };
x2vnc = callPackage ../tools/X11/x2vnc { };
x32edit = callPackage ../applications/audio/midas/x32edit.nix {};

View File

@ -2879,6 +2879,18 @@ let
};
};
ConfigSimple = buildPerlPackage {
pname = "Config-Simple";
version = "4.59";
src = fetchurl {
url = mirror://cpan/authors/id/S/SH/SHERZODR/Config-Simple-4.59.tar.gz;
sha256 = "0m0hg29baarw5ds768q9r4rxb27im8kj4fazyf9gjqw4mmssjy6b";
};
meta = {
description = "Simple configuration file class";
};
};
ConfigStd = buildPerlModule {
pname = "Config-Std";
version = "0.903";