feat: myvnc as nix module

This commit is contained in:
Jonas Juselius
2022-09-27 14:20:49 +02:00
parent 6736c6d7de
commit 6f48eea200
2 changed files with 44 additions and 24 deletions

44
cluster/myvnc.nix Normal file
View File

@@ -0,0 +1,44 @@
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.features.myvnc;
myvnc = pkgs.writeScriptBin "myvnc" ''
#!${pkgs.runtimeShell}
uid=`id -u`
port=$((9000+$uid))
shell=`getent passwd $(id -un) | awk -F : '{print $NF}'`
vnc=${pkgs.turbovnc}/bin/vncserver
# vnc=/nix/store/czp2b60dwk75widi8y287hr0xx1wgv2a-tigervnc-1.10.1/bin/vncserver
case $1 in
-p|--port) shift; port=$1 ;;
kill|stop)
display=$($vnc -list | sed -n 's/^\(:[0-9]\+\).*/\1/p'| head -1)
$vnc -kill $display
exit 0
;;
esac
ps ax | sed '/grep/d' | grep "Xvnc.*-rfbport $port" >/dev/null 2>&1
[ $? = 1 ] && $vnc -rfbport $port
echo "Xvnc server is running on port $port."
# exec $shell -i
'';
configuration = {
services.xserver.windowManager.fluxbox.enable = true;
environment.systemPackages = with pkgs; [
alacritty
myvnc
];
};
in {
options.features.myvnc = {
enable = mkEnableOption "Enable mynvc script";
};
config = mkMerge [
(mkIf config.features.myvnc.enable configuration)
];
}