From af0e27630f390faf9995c1aa569e4685eb8c7c68 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 15 Oct 2024 03:30:13 -0400 Subject: [PATCH] refactor: use `systemd` services instead of start script This is probably what I should've done from the beginning, but I didn't really know how `systemd` worked when I started writing this config. --- .../wayland/eww/scripts/get-workspaces | 4 +- home-manager/wayland/hyprland.nix | 9 ----- home-manager/wayland/scripts/autostart | 7 ---- home-manager/wayland/wltools.nix | 40 +++++++++++++++++++ 4 files changed, 42 insertions(+), 18 deletions(-) delete mode 100755 home-manager/wayland/scripts/autostart diff --git a/home-manager/wayland/eww/scripts/get-workspaces b/home-manager/wayland/eww/scripts/get-workspaces index 37b9de6..5957cb2 100755 --- a/home-manager/wayland/eww/scripts/get-workspaces +++ b/home-manager/wayland/eww/scripts/get-workspaces @@ -2,8 +2,8 @@ workspaces() { hyprctl workspaces -j | jaq -c 'map({key: .id | tostring, value: .windows}) | from_entries - | . as $windows | [range(1;11) | {id: tostring, windows: $windows[tostring] // 0, - previous: $windows[.-1|tostring] // 0, next: $windows[.+1|tostring] // 0 }]' + | . as $windows | [range(1;11) | {id: tostring, windows: $windows[tostring] // 0, + previous: $windows[.-1|tostring] // 0, next: $windows[.+1|tostring] // 0}]' } workspaces diff --git a/home-manager/wayland/hyprland.nix b/home-manager/wayland/hyprland.nix index 6164050..f979f2d 100644 --- a/home-manager/wayland/hyprland.nix +++ b/home-manager/wayland/hyprland.nix @@ -4,11 +4,6 @@ let modifier = "SUPER"; terminal = "alacritty"; in { - home.packages = with pkgs; [ - swaybg - swayidle - ]; - wayland.windowManager.hyprland = { enable = true; systemd.enable = true; @@ -28,10 +23,6 @@ in { "$terminal" = terminal; "$menu" = "rofi -show drun"; - exec-once = [ - "background=${../../assets/background.png} platform=${config.platform} ${scripts}/autostart" - ]; - general = { layout = "hy3"; diff --git a/home-manager/wayland/scripts/autostart b/home-manager/wayland/scripts/autostart deleted file mode 100755 index 76d8ae7..0000000 --- a/home-manager/wayland/scripts/autostart +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -# Background -swaybg -o '*' -i "$background" -m fill & - -# Status Bar -eww open "$platform"_bar --screen 0 diff --git a/home-manager/wayland/wltools.nix b/home-manager/wayland/wltools.nix index 0c1448e..ecb0456 100644 --- a/home-manager/wayland/wltools.nix +++ b/home-manager/wayland/wltools.nix @@ -60,6 +60,25 @@ ]; }; + # Swaybg + + systemd.user.services.swaybg = { + Install.WantedBy = [ "graphical-session.target" ]; + + Unit = { + Description = "Sway background manager"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + ConditionEnvironment = "WAYLAND_DISPLAY"; + }; + + Service = { + ExecStart = "${lib.getExe pkgs.swaybg} -o '*' -i ${../../assets/background.png} -m fill"; + Restart = "always"; + RestartSec = "5"; + }; + }; + # Rofi programs.rofi.enable = true; @@ -72,6 +91,27 @@ programs.eww.enable = true; programs.eww.configDir = ./eww; + systemd.user.services.eww = + let eww = lib.getExe config.programs.eww.package; + in { + Install.WantedBy = [ "graphical-session.target" ]; + + Unit = { + Description = "GTK-based custom widgets"; + Documentation = "https://github.com/elkowar/eww"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + ConditionEnvironment = "WAYLAND_DISPLAY"; + }; + + Service = { + ExecStart = "${eww} daemon --no-daemonize"; + ExecStartPost = "${eww} open ${config.machine}_bar --screen 0"; + Restart = "always"; + RestartSec = "5"; + }; + }; + # Mako services.mako = {