Skip to content

Instantly share code, notes, and snippets.

@balsoft
Last active October 3, 2021 15:23
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save balsoft/997fae0c1b454353ca46d4a16a68ef41 to your computer and use it in GitHub Desktop.
chrome-remote-desktop on nixos/nix
{ config, lib, pkgs, ...}:
with lib;
let
cfg = config.services.crd;
in {
options = {
services.crd = {
enable = mkEnableOption ''
chrome remote desktop, a service which allows for remote control of your desktop from anywhere.
'';
user = mkOption {
type = types.submodule;
description = ''
A user which the service will run as.
'';
example = "users.users.alice";
};
screenSize = mkOption {
type = types.string;
description = ''
Size of the screen (for all clients)
'';
default = "1366x768";
example = "1920x1080";
};
session = mkOption {
type = types.string;
description = ''
The X session that chrome remote desktop will control
'';
example = "gnome-session";
};
};
};
config = mkIf cfg.enable {
systemd.services.chrome-remote-desktop = {
description = "Chrome remote desktop service";
path = with pkgs; [ sudo chrome-remote-desktop ];
script = ''
sudo -u ${cfg.user.name} ${pkgs.chrome-remote-desktop}/opt/google/chrome-remote-desktop --start --size=${cfg.screenSize}
'';
};
security.wrappers.crd-user-session.source = "${pkgs.chrome-remote-desktop}/opt/google/chrome-remote-desktop/user-session";
system.activationScripts.crd-setup = {
text = ''
if [[ -z $(cat ${cfg.user.home}/.chrome-remote-desktop-session) ]]; then
# Create the file
echo "export $(dbus-launch)" > ${cfg.user.home}/.chrome-remote-desktop-session
echo "exec ${cfg.session}" >> ${cfg.user.home}/.chrome-remote-desktop-session
fi
'';
};
};
}
{ stdenv, lib, fetchurl, fetchgit, dpkg, python2, glibc, glib, pam, nss, nspr, expat, gnome3, xorg, fontconfig, dbus_daemon, alsaLib }:
stdenv.mkDerivation rec {
name = "chrome-remote-desktop";
src = fetchurl {
sha256 = "d18baa7033d80cf458ffec808dacce11d737bf31e81f25884221867c8c6a3001";
url = "https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb";
};
unpackPhase = ''
${dpkg}/bin/dpkg -x $src $out
'';
installPhase = ''
'';
patchPhase = ''
sed \
-e '/^.*sudo_command =/ s/"gksudo .*"/"pkexec"/' \
-e '/^.*command =/ s/s -- sh -c/s sh -c/' \
-i $out/opt/google/chrome-remote-desktop/chrome-remote-desktop
substituteInPlace $out/opt/google/chrome-remote-desktop/chrome-remote-desktop --replace /usr/bin/python2 ${python2.withPackages (ps: with ps;[ psutil ])}/bin/python2
'';
preFixup = let
libPath = lib.makeLibraryPath [glib pam nss nspr expat gnome3.gtk gnome3.gconf xorg.libXext xorg.libX11 xorg.libXcomposite xorg.libXrender xorg.libXrandr xorg.libXcursor xorg.libXdamage xorg.libXfixes xorg.libXi xorg.libXtst fontconfig xorg.libXScrnSaver dbus_daemon.lib alsaLib];
in ''
for i in $out/opt/google/$name/{chrome-remote-desktop-host,start-host,native-messaging-host,remote-assistance-host,user-session}; do
patchelf --set-rpath "${libPath}" $i
patchelf --set-interpreter ${glibc}/lib/ld-linux-x86-64.so.2 $i
done
'';
}
@steve-chavez
Copy link

@balsoft How can I test it? Running nix-shell gives me:

error: cannot auto-call a function that has an argument without a default value ('stdenv')

@balsoft
Copy link
Author

balsoft commented Jan 18, 2020

You'll have to add those files to nixpkgs, then fix them (in this form, it doesn't quite work), then build your system with patched nixpkgs. If you're feeling particularly altruistic, you might even share your results with the world and submit a PR to nixpkgs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment