add sway to shared modules

This commit is contained in:
LordGrimmauld 2024-03-18 00:34:52 +01:00
parent 33069a8db6
commit 154b9aa8ec
7 changed files with 334 additions and 7 deletions

View File

@ -85,6 +85,40 @@ in {
description = "disables user controlled plugins";
};
};
sway = {
enable = mkEnableOption "grimm-sway";
definitions = mkOption {
type = types.attrsOf types.str;
default = {};
description = "set of definitions assigning variable to value";
};
keybinds = mkOption {
type = types.attrsOf types.str;
default = {};
description = "set of keybinds assigning key combo to action";
};
autolaunch = mkOption {
type = types.listOf types.str;
default = [];
description = "set of commands to be run at sway startup";
};
extraConfig = mkOption {
type = types.str;
default = "";
description = "additional sway config to be included";
};
populateDefaultConfig = mkOption {
type = types.bool;
default = false;
description = "puts my personal config in place using above methods";
};
};
};
imports = [
@ -98,5 +132,7 @@ in {
./modules/gaming.nix
./modules/firefox.nix
./modules/pass.nix
./modules/sway.nix
./modules/sway-defaults.nix
];
}

View File

@ -42,11 +42,11 @@
]
},
"locked": {
"lastModified": 1710551318,
"narHash": "sha256-s1fOcZdpMbPOTuyVpzvN8QXdxS/viYjQ6J+hTR8NGys=",
"lastModified": 1710637843,
"narHash": "sha256-NVszlVTM0sEe8yZuOShitwOhNdl2juD7032SQg2dV+U=",
"owner": "fufexan",
"repo": "nix-gaming",
"rev": "8b46b34b574cd1e6a9a8ded392f5b2f97b1f46a2",
"rev": "da2c09734818d85ef4d112997b5188b62cfdd0fd",
"type": "github"
},
"original": {
@ -57,11 +57,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1710451336,
"narHash": "sha256-pP86Pcfu3BrAvRO7R64x7hs+GaQrjFes+mEPowCfkxY=",
"lastModified": 1710631334,
"narHash": "sha256-rL5LSYd85kplL5othxK5lmAtjyMOBg390sGBTb3LRMM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d691274a972b3165335d261cc4671335f5c67de9",
"rev": "c75037bbf9093a2acb617804ee46320d6d1fea5a",
"type": "github"
},
"original": {
@ -93,9 +93,30 @@
"flake-compat": "flake-compat",
"nix-gaming": "nix-gaming",
"nixpkgs": "nixpkgs",
"swaymux": "swaymux",
"utils": "utils"
}
},
"swaymux": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1710362637,
"narHash": "sha256-i5fTiwb4SvEIoEcJyPMLy0QYtlIuoJagpSMb+KDwLdQ=",
"ref": "refs/heads/main",
"rev": "4e6afa08fd8c9a302e3ad634c691fcd3fcf516d1",
"revCount": 27,
"type": "git",
"url": "https://git.grimmauld.de/Grimmauld/swaymux"
},
"original": {
"type": "git",
"url": "https://git.grimmauld.de/Grimmauld/swaymux"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,

View File

@ -12,9 +12,13 @@
url = "github:fufexan/nix-gaming";
inputs.nixpkgs.follows = "nixpkgs";
};
swaymux = {
url = "git+https://git.grimmauld.de/Grimmauld/swaymux";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs @ { self, utils, nixpkgs, nix-gaming, ... }: let
outputs = inputs @ { self, swaymux, utils, nixpkgs, nix-gaming, ... }: let
lib = nixpkgs.lib;
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};

189
modules/sway-defaults.nix Normal file
View File

@ -0,0 +1,189 @@
{ grimm-shared-inputs, system, pkgs, config, lib, ... }: let
cfg = config.grimmShared;
swaymux_pkg = grimm-shared-inputs.swaymux.packages."${system}".default;
in {
config = with cfg; lib.mkIf (enable && sway.enable && sway.populateDefaultConfig ) {
environment.systemPackages = (with pkgs; [
alacritty
wmenu
grim
slurp
wl-clipboard
])
++ [ swaymux_pkg ];
grimmShared.sway = {
definitions = {
mod = "Mod4";
left = "h";
down = "j";
up = "k";
right = "l";
term = "alacritty";
menu = "dmenu_path | wmenu | xargs swaymsg exec --";
primecol = "#8800FF";
accentcol = "#5700a0";
splitcol = "#69507f";
actsplitcol = "#cd97fc";
darkcol = "#202020";
urgentcol = "#9e3c3c";
realwhite = "#C7D3E3";
};
keybinds = {
"$mod+d" = "exec $menu";
"$mod+Shift+s" = ''exec grim -g "$(slurp -d)" - | wl-copy'';
"$mod+Return" = "exec $term";
"$mod+Shift+q" = "kill";
"$mod+Shift+c" = "reload";
"$mod+Shift+e" = "exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit'";
# Move your focus around
"$mod+$left" = "focus left";
"$mod+$down" = "focus down";
"$mod+$up" = "focus up";
"$mod+$right" = "focus right";
# Or use $mod+[up|down|left|right]
"$mod+Left" = "focus left";
"$mod+Down" = "focus down";
"$mod+Up" = "focus up";
"$mod+Right" = "focus right";
# Move the focused window with the same, but add Shift
"$mod+Shift+$left" = "move left";
"$mod+Shift+$down" = "move down";
"$mod+Shift+$up" = "move up";
"$mod+Shift+$right" = "move right";
# Ditto, with arrow keys
"$mod+Shift+Left" = "move left";
"$mod+Shift+Down" = "move down";
"$mod+Shift+Up" = "move up";
"$mod+Shift+Right" = "move right";
#
# Workspaces:
#
# Switch to workspace
"$mod+1" = "workspace number 1";
"$mod+2" = "workspace number 2";
"$mod+3" = "workspace number 3";
"$mod+4" = "workspace number 4";
"$mod+5" = "workspace number 5";
"$mod+6" = "workspace number 6";
"$mod+7" = "workspace number 7";
"$mod+8" = "workspace number 8";
"$mod+9" = "workspace number 9";
"$mod+0" = "workspace number 10";
# Move focused container to workspace
"$mod+Shift+1" = "move container to workspace number 1";
"$mod+Shift+2" = "move container to workspace number 2";
"$mod+Shift+3" = "move container to workspace number 3";
"$mod+Shift+4" = "move container to workspace number 4";
"$mod+Shift+5" = "move container to workspace number 5";
"$mod+Shift+6" = "move container to workspace number 6";
"$mod+Shift+7" = "move container to workspace number 7";
"$mod+Shift+8" = "move container to workspace number 8";
"$mod+Shift+9" = "move container to workspace number 9";
"$mod+Shift+0" = "move container to workspace number 10";
# Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default.
#
# Layout stuff:
#
# You can "split" the current object of your focus with
# $mod+b or $mod+v, for horizontal and vertical splits
# respectively.
"$mod+b" = "splith";
"$mod+v" = "splitv";
# Switch the current container between different layout styles
"$mod+s" = "layout stacking";
"$mod+w" = "layout tabbed";
"$mod+e" = "layout toggle split";
# Make the current focus fullscreen
"$mod+f" = "fullscreen";
# Toggle the current focus between tiling and floating mode
"$mod+Shift+space" = "floating toggle";
# Swap focus between the tiling area and the floating area
"$mod+space" = "focus mode_toggle";
# Move focus to the parent container
"$mod+a" = "focus parent";
"$mod+Shift+minus" = "move scratchpad";
"$mod+minus" = "scratchpad show";
"$mod+r" = ''mode "resize"'';
"XF86AudioRaiseVolume" = "exec pactl set-sink-volume @DEFAULT_SINK@ +5%";
"XF86AudioLowerVolume" = "exec pactl set-sink-volume @DEFAULT_SINK@ -5%";
"XF86AudioMute" = "exec pactl set-sink-mute @DEFAULT_SINK@ toggle";
"XF86AudioPlay" = "exec playerctl play-pause";
"XF86AudioNext" = "exec playerctl next";
"XF86AudioPrev" = "exec playerctl previous";
"$mod+c" = "exec swaymux";
};
autolaunch = [ # fixme: absolute paths
"blueman-applet"
"lxqt-policykit-agent"
"otd-daemon"
"dunst"
"systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP"
];
extraConfig = ''
# fixme: wallpaper
output * bg ${./wallpapers/spain.jpg} fill
output HDMI-A-1 mode 1920x1080@60Hz position 0,0
for_window [app_id="lxqt-policykit-agent"] floating enable;
floating_modifier $mod normal
bar {
swaybar_command waybar
}
input type:keyboard xkb_numlock enabled
include /etc/sway/config.d/*
# Borders, gaps, titlebars, behavior
default_border pixel 3
default_floating_border pixel 3
gaps inner 5
titlebar_padding 5 5
#5Smart things
smart_gaps on
hide_edge_borders --i3 smart
input * {
xkb_layout "de"
}
for_window [app_id="swaymux"] floating enable
mode "resize" {
# left will shrink the containers width
# right will grow the containers width
# up will shrink the containers height
# down will grow the containers height
bindsym $left resize shrrnk width 10px
bindsym $down resize grow height 10px
bindsym $up resize shrink height 10px
bindsym $right resize grow width 10px
# Ditto, with arrow keys
bindsym Left resize shrink width 10px
bindsym Down resize grow height 10px
bindsym Up resize shrink height 10px
bindsym Right resize grow width 10px
# Return to default mode
bindsym Return mode "default"
bindsym Escape mode "default"
}
'';
};
};
}

77
modules/sway.nix Normal file
View File

@ -0,0 +1,77 @@
{ pkgs, config, lib, ... }: let
cfg = config.grimmShared;
in {
config = let
build_definition_lines = lib.mapAttrsToList (name: value: "set \$${name} ${value}");
build_keybind_lines = lib.mapAttrsToList (key: value: "bindsym ${key} ${value}");
build_exec_lines = map (item: "exec " + item);
sway_conf = pkgs.writeText "sway.conf" (lib.strings.concatLines [
(lib.strings.concatLines (build_definition_lines cfg.sway.definitions))
(lib.strings.concatLines (build_keybind_lines cfg.sway.keybinds))
(lib.strings.concatLines (build_exec_lines cfg.sway.autolaunch))
cfg.sway.extraConfig
]);
in with cfg; lib.mkIf (enable && sway.enable) {
environment.etc."sway.conf" = {
source = sway_conf;
};
environment.systemPackages = with pkgs; [
procps
slurp
libnotify
];
systemd.services.reload-sway = {
description = "Reload all running sway instances";
wantedBy = [ "multi-user.target" ];
serviceConfig.Type = "oneshot";
script =''
for pid in $(${pkgs.procps}/bin/pgrep sway -x)
do
uid=$(id -u $(${pkgs.procps}/bin/ps -o user= -p $pid))
export SWAYSOCK="/run/user/$uid/sway-ipc.$uid.$pid.sock"
if [[ -e "$SWAYSOCK" ]] ; then
echo "sock is $SWAYSOCK"
${config.programs.sway.package}/bin/swaymsg reload
fi
done
'';
reloadTriggers = [ sway_conf ];
};
programs.sway = {
enable = true;
wrapperFeatures = {
gtk = true;
base = true;
};
extraPackages = with pkgs; [
swaylock
swayidle
wl-clipboard
wf-recorder
waybar
dmenu
wmenu
];
extraOptions = [
"--unsupported-gpu"
"--config"
"/etc/sway.conf"
];
extraSessionCommands = ''
export XDG_CURRENT_DESKTOP=sway
export SDL_VIDEODRIVER=wayland
export QT_QPA_PLATFORM=wayland
export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"
export _JAVA_AWT_WM_NONREPARENTING=1
export MOZ_ENABLE_WAYLAND=1
# export MESA_LOADER_DRIVER_OVERRIDE="zink"
'';
};
};
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 MiB