From 4aeb3360d3271d7f8fd130dbf49f66623e0696d4 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 30 May 2024 06:00:32 +0000 Subject: [PATCH] cleanup: programs: dont assume `sway` is always the wayland/x11 provider --- hosts/common/programs/pipewire.nix | 3 +++ hosts/common/programs/sway/default.nix | 19 ++++++++++++++----- modules/programs/default.nix | 8 +++++--- modules/users/default.nix | 16 +++++++++++++--- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/hosts/common/programs/pipewire.nix b/hosts/common/programs/pipewire.nix index 5dcbbfa7..6b3d25ae 100644 --- a/hosts/common/programs/pipewire.nix +++ b/hosts/common/programs/pipewire.nix @@ -177,6 +177,9 @@ in ]; cleanupCommand = ''rm -f "$XDG_RUNTIME_DIR/pulse/{native,pid}"''; }; + + # bring up sound by default + services."sound".partOf = [ "default" ]; }; # taken from nixos/modules/services/desktops/pipewire/pipewire.nix diff --git a/hosts/common/programs/sway/default.nix b/hosts/common/programs/sway/default.nix index c9c1924e..dd25cd55 100644 --- a/hosts/common/programs/sway/default.nix +++ b/hosts/common/programs/sway/default.nix @@ -4,6 +4,7 @@ # sway-config docs: `man 5 sway` let cfg = config.sane.programs.sway; + enableXWayland = config.sane.programs.xwayland.enabled; wrapSway = configuredSway: let swayLauncher = pkgs.writeShellScriptBin "sway" '' test -e "$(dirname "$SWAYSOCK")" || \ @@ -66,7 +67,7 @@ let # - when xwayland is enabled, KOreader incorrectly chooses the X11 backend # -> slower; blurrier # - xwayland uses a small amount of memory (like 30MiB, IIRC?) - enableXWayland = config.sane.programs.xwayland.enabled; + inherit enableXWayland; }).overrideAttrs (upstream: { # fix to create SWAYSOCK and WAYLAND_DISPLAY directly in a sandboxable subdirectory: # i can't simply move it after creation i think because that would @@ -221,7 +222,7 @@ in mod workspace_layout ; - xwayland = if config.sane.programs.xwayland.enabled then "enable" else "disable"; + xwayland = if enableXWayland then "enable" else "disable"; }; env.XDG_CURRENT_DESKTOP = "sway"; @@ -238,7 +239,15 @@ in services.sway = { description = "sway: tiling wayland desktop environment"; - dependencyOf = [ "graphical-session" ]; #< TODO: should be safe to remove this now + partOf = [ + "wayland" + ] ++ lib.optionals enableXWayland [ + "x11" + ]; + # partOf = lib.mkMerge [ + # "wayland" + # (lib.mkIf enableXWayland "x11") + # ]; command = pkgs.writeShellScript "sway-start" '' # have to create these directories before launching sway so that they're available in the sandbox mkdir -p "$(dirname "$SWAYSOCK")" @@ -248,8 +257,8 @@ in ''; readiness.waitExists = [ "$SWAYSOCK" "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ]; }; - # link the graphical-session into the default target, so sway gets auto-started - services.graphical-session.partOf = [ "default" ]; + # launch all graphical apps by default + services."graphical-session".partOf = [ "default" ]; }; # TODO: this can go elsewhere diff --git a/modules/programs/default.nix b/modules/programs/default.nix index 96b20c9c..d0cd4e26 100644 --- a/modules/programs/default.nix +++ b/modules/programs/default.nix @@ -223,6 +223,7 @@ let acts as noop for root-enabled packages. see `sane.users..services` for options; ''; + # TODO: this `apply` should by moved to where we pass the `services` down to `sane.users` apply = lib.mapAttrs (svcName: svcCfg: svcCfg // lib.optionalAttrs (builtins.tryEval svcCfg.description).success { # ensure service dependencies based on what a service's program whitelists. @@ -231,9 +232,10 @@ let depends = svcCfg.depends ++ lib.optionals (svcName != "dbus" && builtins.elem "user" config.sandbox.whitelistDbus) [ "dbus" - ] ++ lib.optionals (svcName != "sway" && (config.sandbox.whitelistWayland || config.sandbox.whitelistX)) [ - # TODO: i shouldn't assume sway here: factor out a "partOf" like i do for "sound" - "sway" + ] ++ lib.optionals ((!builtins.elem "wayland" svcCfg.partOf) && config.sandbox.whitelistWayland) [ + "wayland" + ] ++ lib.optionals ((!builtins.elem "x11" svcCfg.partOf) && config.sandbox.whitelistX) [ + "x11" ] ++ lib.optionals ((!builtins.elem "sound" svcCfg.partOf) && config.sandbox.whitelistAudio) [ "sound" ]; diff --git a/modules/users/default.nix b/modules/users/default.nix index 22c8454b..32673cba 100644 --- a/modules/users/default.nix +++ b/modules/users/default.nix @@ -157,7 +157,7 @@ let userModule = let nixConfig = config; in with lib; types.submodule ({ name, config, ... }: { - options = userOptions// { + options = userOptions // { default = mkOption { type = types.bool; default = false; @@ -273,16 +273,26 @@ let '') ]; + # a few common targets one can depend on or declare a `partOf` to. + # for example, a wayland session provider should: + # - declare `myService.partOf = [ "wayland" ];` + # - and `graphical-session.partOf = [ "default" ];` services."default" = { description = "service (bundle) which is started by default upon login"; }; services."graphical-session" = { description = "service (bundle) which is started upon successful graphical login"; - # partOf = [ "default" ]; #< leave it to the DEs to set this + # partOf = [ "default" ]; }; services."sound" = { description = "service (bundle) which represents functional sound input/output when active"; - partOf = [ "default" ]; + # partOf = [ "default" ]; + }; + services."wayland" = { + description = "service (bundle) which provides a wayland session"; + }; + services."x11" = { + description = "service (bundle) which provides a x11 session (possibly via xwayland)"; }; } ];