From 6d1d683b231a13e94bed8fd215cd311fb99b0be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Thu, 25 Aug 2022 00:13:23 +0200 Subject: [PATCH] Fix swayidle command, add hibernation on lid close, fix env The swayidle command in the service was straight up broken, this commit fixes that. Environment Variables set in the `session-variables` file are now correctly imported across the system. This fixes `EDITOR` defaulting to `nano`. --- modules/paranoia/default.nix | 1 + modules/sway/config/config.d/systemd.conf | 2 +- modules/sway/mako.service.nix | 1 - modules/sway/swayidle.service.nix | 20 +++++++++----------- modules/sway/waybar.service.nix | 3 ++- pkgs/sway-service.nix | 2 +- profiles/base-user/session-variables.nix | 18 +++++++++++++++--- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/modules/paranoia/default.nix b/modules/paranoia/default.nix index bb319767..699ab13e 100644 --- a/modules/paranoia/default.nix +++ b/modules/paranoia/default.nix @@ -20,5 +20,6 @@ in config = mkIf cfg.enable { pub-solar.core.hibernation.enable = true; + services.logind.lidSwitch = "hibernate"; }; } diff --git a/modules/sway/config/config.d/systemd.conf b/modules/sway/config/config.d/systemd.conf index d6380d41..66759c4f 100644 --- a/modules/sway/config/config.d/systemd.conf +++ b/modules/sway/config/config.d/systemd.conf @@ -5,4 +5,4 @@ # https://github.com/swaywm/sway/wiki/Systemd-integration # Also, import the most important environment variables into the D-Bus and systemd # user environments (e.g. required for screen sharing and Pinentry prompts): -exec "systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target; exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemd-cat --identifier=sway sway" +exec "systemctl --user import-environment; systemctl --user start sway-session.target; exec dbus-update-activation-environment --systemd $IMPORT_ENVIRONMENT_ENV_LIST DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemd-cat --identifier=sway sway" diff --git a/modules/sway/mako.service.nix b/modules/sway/mako.service.nix index b155e148..1f210c74 100644 --- a/modules/sway/mako.service.nix +++ b/modules/sway/mako.service.nix @@ -5,7 +5,6 @@ Documentation = [ "man:mako(1)" ]; BindsTo = [ "sway-session.target" ]; After = [ "sway-session.target" ]; - # ConditionEnvironment requires systemd v247 to work correctly ConditionEnvironment = [ "WAYLAND_DISPLAY" ]; }; Service = { diff --git a/modules/sway/swayidle.service.nix b/modules/sway/swayidle.service.nix index 3b87c610..f10675fb 100644 --- a/modules/sway/swayidle.service.nix +++ b/modules/sway/swayidle.service.nix @@ -10,17 +10,15 @@ Service = { Type = "simple"; Environment = "PATH=/run/current-system/sw/bin:${pkgs.sway}/bin"; - ExecStart = if psCfg.paranoia.enable then '' - ${pkgs.swayidle}/bin/swayidle -w \ - timeout 120 'swaymsg "output * dpms off"' \ - timeout 150 'systemctl hibernate' \ - '' else '' - ${pkgs.swayidle}/bin/swayidle -w \ - timeout 600 'swaylock-bg' \ - timeout 900 'swaymsg "output * dpms off"' \ - resume 'swaymsg "output * dpms on"' \ - before-sleep 'swaylock-bg' - ''; + ExecStart = ''${pkgs.swayidle}/bin/swayidle -w \ + after-resume 'swaymsg "output * dpms on"' \ + before-sleep 'swaylock-bg' '' + (if psCfg.paranoia.enable then '' \ + timeout 120 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \ + timeout 150 'systemctl hibernate' + '' else '' \ + timeout 600 'swaylock-bg' + timeout 900 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' + ''); }; Install = { WantedBy = [ "sway-session.target" ]; diff --git a/modules/sway/waybar.service.nix b/modules/sway/waybar.service.nix index 98b8ed35..0237612f 100644 --- a/modules/sway/waybar.service.nix +++ b/modules/sway/waybar.service.nix @@ -4,8 +4,9 @@ Description = "Highly customizable Wayland bar for Sway and Wlroots based compositors."; Documentation = "https://github.com/Alexays/Waybar/wiki/"; BindsTo = [ "sway-session.target" ]; - After = [ "graphical-session-pre.target" "network-online.target" ]; + After = [ "sway-session.target" "network-online.target" ]; Wants = [ "graphical-session-pre.target" "network-online.target" "blueman-applet.service" ]; + ConditionEnvironment = [ "WAYLAND_DISPLAY" ]; }; Service = { diff --git a/pkgs/sway-service.nix b/pkgs/sway-service.nix index f0b97ee7..15781a1a 100644 --- a/pkgs/sway-service.nix +++ b/pkgs/sway-service.nix @@ -1,6 +1,6 @@ self: with self; '' # first import environment variables from the login manager - systemctl --user import-environment + systemctl --user import-environment $IMPORT_ENVIRONMENT_ENV_LIST DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP PATH; # then start the service exec systemctl --wait --user start sway.service '' diff --git a/profiles/base-user/session-variables.nix b/profiles/base-user/session-variables.nix index 5bbfa8ee..e922781b 100644 --- a/profiles/base-user/session-variables.nix +++ b/profiles/base-user/session-variables.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: let psCfg = config.pub-solar; wlroots = psCfg.graphical.wayland; @@ -77,10 +77,22 @@ let # TELEMETRY BS VUEDX_TELEMETRY = "off"; }; + + envListNames = lib.attrsets.mapAttrsToList (name: value: name) variables; + + # Here we merge an extra variable into the attrset called FULL_ENV_LIST. + # It's a list of the variable names defined above. + # We can use this to tell `systemctl import-environment` to import the full list above. + variablesWithMeta = lib.attrsets.zipAttrsWith (name: values: builtins.head values) [ + variables + { IMPORT_ENVIRONMENT_ENV_LIST = lib.lists.foldl (a: b: a + " " + b) "IMPORT_ENVIRONMENT_ENV_LIST" envListNames; } + ]; in { home-manager = pkgs.lib.setAttrByPath [ "users" psCfg.user.name ] { - home.sessionVariables = variables; - systemd.user.sessionVariables = variables; + home.sessionVariables = variablesWithMeta; + systemd.user.sessionVariables = variablesWithMeta; }; + + environment.variables = variablesWithMeta; }