diff --git a/modules/headless-graphical/default.nix b/modules/headless-graphical/default.nix new file mode 100644 index 00000000..149dea3c --- /dev/null +++ b/modules/headless-graphical/default.nix @@ -0,0 +1,73 @@ +{ lib, config, pkgs, ... }: +with lib; +let + psCfg = config.pub-solar; + cfg = config.pub-solar.headless-graphical; +in +{ + options.pub-solar.headless-graphical = { + enable = mkEnableOption "Enable headless sway and VNC"; + }; + + config = mkIf cfg.enable { + programs.sway.enable = true; + + xdg.portal = { + enable = true; + extraPortals = with pkgs; [ xdg-desktop-portal-gtk xdg-desktop-portal-wlr ]; + gtkUsePortal = true; + }; + + services.pipewire.enable = true; + + home-manager = with pkgs; pkgs.lib.setAttrByPath [ "users" psCfg.user.name ] { + home.packages = with pkgs; [ + sway + grim + kanshi + mako + slurp + swayidle + swaylock + swaybg + xwayland + + libappindicator-gtk3 + + wl-clipboard + wf-recorder + brightnessctl + gammastep + geoclue2 + xsettingsd + ydotool + + swaylock-bg + sway-launcher + import-gtk-settings + s + wcwd + ]; + + programs.waybar.enable = true; + + systemd.user.services.mako = import ./mako.service.nix pkgs; + systemd.user.services.swayidle = import ./swayidle.service.nix pkgs; + systemd.user.services.xsettingsd = import ./xsettingsd.service.nix pkgs; + systemd.user.services.waybar = import ./waybar.service.nix pkgs; + systemd.user.targets.sway-session = import ./sway-session.target.nix pkgs; + + systemd.user.services.sway-headless = mkIf cfg.vnc.enable (import ./wayvnc.service.nix pkgs); + systemd.user.services.wayvnc = mkIf cfg.vnc.enable (import ./wayvnc.service.nix pkgs); + + xdg.configFile."sway/config".source = ./config/config; + xdg.configFile."sway/config.d/colorscheme.conf".source = ./config/config.d/colorscheme.conf; + xdg.configFile."sway/config.d/theme.conf".source = ./config/config.d/theme.conf; + xdg.configFile."sway/config.d/gaps.conf".source = ./config/config.d/gaps.conf; + xdg.configFile."sway/config.d/custom-keybindings.conf".source = ./config/config.d/custom-keybindings.conf; + xdg.configFile."sway/config.d/applications.conf".source = ./config/config.d/applications.conf; + xdg.configFile."sway/config.d/systemd.conf".source = ./config/config.d/systemd.conf; + xdg.configFile."wayvnc/config".text = import ./config/wayvnc/config.nix { inherit psCfg; inherit pkgs; }; + }; + }; +} diff --git a/modules/sway/sway.service.nix b/modules/headless-graphical/sway-headless.service.nix similarity index 58% rename from modules/sway/sway.service.nix rename to modules/headless-graphical/sway-headless.service.nix index 95efc3e6..7074a0d8 100644 --- a/modules/sway/sway.service.nix +++ b/modules/headless-graphical/sway-headless.service.nix @@ -1,18 +1,30 @@ pkgs: { Unit = { - Description = "sway - SirCmpwn's Wayland window manager"; + Description = "Headless sway - SirCmpwn's Wayland window manager"; Documentation = [ "man:sway(5)" ]; BindsTo = [ "graphical-session.target" ]; Wants = [ "graphical-session-pre.target" ]; After = [ "graphical-session-pre.target" ]; }; + Service = { Type = "simple"; - ExecStart = "${pkgs.sway}/bin/sway"; + + ExecStart = "${pkgs.sway}/bin/sway --headless"; + Environment = [ + "WLR_BACKENDS=headless" + "WLR_RENDERER=pixman" + "WLR_LIBINPUT_NO_DEVICES=1" + ]; + Restart = "on-failure"; RestartSec = "1"; TimeoutStopSec = "10"; ExecStopPost = "${pkgs.systemd}/bin/systemctl --user unset-environment SWAYSOCK DISPLAY I3SOCK WAYLAND_DISPLAY"; }; + + Install = { + WantedBy = [ "sway-session.target" ]; + }; } diff --git a/modules/sway/wayvnc.service.nix b/modules/headless-graphical/wayvnc.service.nix similarity index 91% rename from modules/sway/wayvnc.service.nix rename to modules/headless-graphical/wayvnc.service.nix index 45938a3f..54c2d520 100644 --- a/modules/sway/wayvnc.service.nix +++ b/modules/headless-graphical/wayvnc.service.nix @@ -11,6 +11,7 @@ pkgs: Service = { Type = "simple"; ExecStart = "${pkgs.wayvnc}/bin/wayvnc --render-cursor"; + Environment = "WAYLAND_DISPLAY=wayland-1"; }; Install = { diff --git a/modules/sway/default.nix b/modules/sway/default.nix index 568bcb41..72023c83 100644 --- a/modules/sway/default.nix +++ b/modules/sway/default.nix @@ -3,11 +3,11 @@ with lib; let psCfg = config.pub-solar; cfg = config.pub-solar.sway; + headlessCfg = config.pub-solar.sway-headless; in { options.pub-solar.sway = { enable = mkEnableOption "Life in boxes"; - vnc.enable = mkEnableOption "Enable vnc service"; v4l2loopback.enable = mkOption { type = types.bool; @@ -16,6 +16,10 @@ in }; }; + options.pub-solar.sway-headless = { + headless.enable = mkEnableOption "Enable headless sway and vnc service"; + }; + config = mkIf cfg.enable (mkMerge [ (mkIf (cfg.v4l2loopback.enable) { boot.extraModulePackages = with config.boot.kernelPackages; [ v4l2loopback ]; @@ -23,13 +27,12 @@ in boot.extraModprobeConfig = '' options v4l2loopback exclusive_caps=1 devices=3 ''; - }) - - ({ environment.systemPackages = with pkgs; [ linuxPackages.v4l2loopback ]; + }) + ({ programs.sway.enable = true; xdg.portal = { @@ -78,6 +81,7 @@ in systemd.user.services.waybar = import ./waybar.service.nix pkgs; systemd.user.targets.sway-session = import ./sway-session.target.nix pkgs; + systemd.user.services.sway-headless = mkIf cfg.vnc.enable (import ./wayvnc.service.nix pkgs); systemd.user.services.wayvnc = mkIf cfg.vnc.enable (import ./wayvnc.service.nix pkgs); xdg.configFile."sway/config".source = ./config/config; diff --git a/modules/user/default.nix b/modules/user/default.nix index 79e32eca..90f4e7f7 100644 --- a/modules/user/default.nix +++ b/modules/user/default.nix @@ -36,6 +36,7 @@ in type = types.nullOr types.str; default = null; }; + autologin = mkEnableOption "Autologin the pub solar user on all TTYs"; }; }; }