From 1264d0c7f6643ac88f12f69bdef29d57715520a2 Mon Sep 17 00:00:00 2001 From: James Patrick Date: Mon, 13 Dec 2021 22:44:38 -0500 Subject: [PATCH] Refactored sway --- modules/applications/default.nix | 10 +++- modules/applications/sway.nix | 88 ++++++++++++++++++++++++++++++++ modules/profiles/graphical.nix | 1 - modules/sway.nix | 73 -------------------------- 4 files changed, 96 insertions(+), 76 deletions(-) create mode 100644 modules/applications/sway.nix delete mode 100644 modules/sway.nix diff --git a/modules/applications/default.nix b/modules/applications/default.nix index a620a9f..718b453 100644 --- a/modules/applications/default.nix +++ b/modules/applications/default.nix @@ -1,4 +1,10 @@ { config, pkgs, ... }: { - imports = - [ ./firefox.nix ./mako.nix ./nextcloud.nix ./waybar.nix ./emacs.nix ]; + imports = [ + ./firefox.nix + ./mako.nix + ./nextcloud.nix + ./waybar.nix + ./emacs.nix + ./sway.nix + ]; } diff --git a/modules/applications/sway.nix b/modules/applications/sway.nix new file mode 100644 index 0000000..704b772 --- /dev/null +++ b/modules/applications/sway.nix @@ -0,0 +1,88 @@ +{ config, lib, pkgs, ... }: +let cfg = config.application.sway; +in with lib; { + options = { + application.sway = { + enable = mkOption { + # TODO base on graphical + default = true; + type = with types; bool; + description = "testing one two three"; + }; + }; + }; + + config = mkIf cfg.enable { + home-manager.users.james = { + home.sessionVariables = { + MOZ_ENABLE_WAYLAND = 1; + XDG_CURRENT_DESKTOP = "sway"; + }; + + home.packages = with pkgs; [ + autotiling + dmenu + kitty + mako + swayidle + swaylock + wl-clipboard + wofi + (writeTextFile { + name = "sway-entry"; + destination = "/bin/sway-entry"; + executable = true; + text = '' + #! ${pkgs.bash}/bin/bash + + # first import environment variables from the login manager + # function is currently deprecated. It should be rolled back in the future + systemctl --user import-environment + + # then start the service + exec systemctl --user start sway.service + ''; + }) + ]; + + }; + + programs.sway = { + enable = true; + wrapperFeatures.gtk = true; # so that gtk works properly + }; + + systemd.user.targets.sway-session = { + description = "Sway compositor session"; + documentation = [ "man:systemd.special(7)" ]; + bindsTo = [ "graphical-session.target" ]; + wants = [ "graphical-session-pre.target" ]; + after = [ "graphical-session-pre.target" ]; + }; + + systemd.user.services.sway = { + description = "Sway - Wayland window manager"; + documentation = [ "man:sway(5)" ]; + bindsTo = [ "graphical-session.target" ]; + wants = [ "graphical-session-pre.target" ]; + after = [ "graphical-session-pre.target" ]; + # We explicitly unset PATH here, as we want it to be set by + # systemctl --user import-environment in startsway + environment.PATH = lib.mkForce null; + serviceConfig = { + ExecStart = + "${pkgs.dbus}/bin/dbus-run-session ${pkgs.sway}/bin/sway --debug"; + ExecStopPost = + "/usr/bin/systemctl --user unset-environment SWAYSOCK DISPLAY I3SOCK WAYLAND_DISPLAY"; + NotifyAccess = "all"; + Restart = "on-failure"; + RestartSec = 1; + TimeoutStopSec = 10; + Type = "simple"; + }; + }; + + users.users.james.extraGroups = [ "video" "audio" ]; + }; +} + diff --git a/modules/profiles/graphical.nix b/modules/profiles/graphical.nix index b3fb097..db6bd68 100644 --- a/modules/profiles/graphical.nix +++ b/modules/profiles/graphical.nix @@ -5,7 +5,6 @@ ../boot.nix ../cli.nix ../fonts.nix - ../sway.nix ../system/gtk.nix ./minimal.nix ]; diff --git a/modules/sway.nix b/modules/sway.nix deleted file mode 100644 index 9e47050..0000000 --- a/modules/sway.nix +++ /dev/null @@ -1,73 +0,0 @@ -{ config, lib, pkgs, ... }: { - programs.sway = { - enable = true; - wrapperFeatures.gtk = true; # so that gtk works properly - }; - - home-manager.users.james = { - home.sessionVariables = { - MOZ_ENABLE_WAYLAND = 1; - XDG_CURRENT_DESKTOP = "sway"; - }; - - home.packages = with pkgs; [ - autotiling - dmenu - kitty - mako - swayidle - swaylock - wl-clipboard - wofi - (writeTextFile { - name = "sway-entry"; - destination = "/bin/sway-entry"; - executable = true; - text = '' - #! ${pkgs.bash}/bin/bash - - # first import environment variables from the login manager - # function is currently deprecated. It should be rolled back in the future - systemctl --user import-environment - - # then start the service - exec systemctl --user start sway.service - ''; - }) - ]; - }; - - systemd.user.targets.sway-session = { - description = "Sway compositor session"; - documentation = [ "man:systemd.special(7)" ]; - bindsTo = [ "graphical-session.target" ]; - wants = [ "graphical-session-pre.target" ]; - after = [ "graphical-session-pre.target" ]; - }; - - systemd.user.services.sway = { - description = "Sway - Wayland window manager"; - documentation = [ "man:sway(5)" ]; - bindsTo = [ "graphical-session.target" ]; - wants = [ "graphical-session-pre.target" ]; - after = [ "graphical-session-pre.target" ]; - # We explicitly unset PATH here, as we want it to be set by - # systemctl --user import-environment in startsway - environment.PATH = lib.mkForce null; - serviceConfig = { - ExecStart = - "${pkgs.dbus}/bin/dbus-run-session ${pkgs.sway}/bin/sway --debug"; - ExecStopPost = - "/usr/bin/systemctl --user unset-environment SWAYSOCK DISPLAY I3SOCK WAYLAND_DISPLAY"; - NotifyAccess = "all"; - Restart = "on-failure"; - RestartSec = 1; - TimeoutStopSec = 10; - Type = "simple"; - }; - }; - - users.users.james.extraGroups = [ "video" "audio" ]; - - imports = [ ./applications/mako.nix ./applications/waybar.nix ]; -}