grimm-nixos-laptop/common/graphics/sway.nix

181 lines
5.1 KiB
Nix
Raw Normal View History

2024-04-10 16:51:28 +02:00
{ pkgs, config, lib, ... }:
let
2024-03-24 16:59:47 +01:00
cfg = config.grimmShared;
sway_conf = with lib; types.submodule ({ config, ... }: rec {
options = {
keybinds = mkOption {
type = types.attrsOf types.str;
default = { };
description = "set of keybinds assigning key combo to action";
};
autolaunch = mkOption {
type = types.listOf (types.either types.nonEmptyStr types.package);
default = [ ];
description = "set of commands to be run at sway startup";
};
extraConfig = mkOption {
type = types.str;
default = "";
description = "additional sway config to be included";
};
definitions = mkOption {
type = types.attrsOf types.str;
default = { };
description = "set of definitions assigning variable to value";
};
modes = mkOption {
type = types.attrsOf sway_conf;
default = { };
description = "possible modes to switch to, e.g. resize";
};
};
});
2024-04-10 16:51:28 +02:00
in
{
config =
let
waybar_full = pkgs.writeShellScriptBin "waybar-full" (
(lib.getExe config.programs.waybar.package)
2024-04-16 12:25:00 +02:00
+ (lib.optionalString (!isNull cfg.sway.bar.config) " -c ${cfg.sway.bar.config}")
+ (lib.optionalString (!isNull cfg.sway.bar.style) " -s ${cfg.sway.bar.style}")
2024-03-26 14:18:33 +01:00
);
2024-03-24 16:59:47 +01:00
2024-04-10 16:51:28 +02:00
bar_config = ''
bar {
swaybar_command ${lib.getExe waybar_full}
2024-04-10 16:51:28 +02:00
}
'';
2024-04-10 16:42:11 +02:00
build_conf = with lib; sway_conf:
2024-04-10 16:51:28 +02:00
let
build_definition_lines = mapAttrsToList (name: value: "set \$${name} ${value}");
build_keybind_lines = mapAttrsToList (key: value: "bindsym ${key} ${value}");
build_exec_lines = map (item: "exec " + (if isString item then item else (getExe item)));
build_mode_lines = mapAttrsToList (name: value: ''
2024-04-10 16:51:28 +02:00
mode "${name}" {
${strings.concatLines (map (item: " " + item ) (build_conf value))}}'');
2024-04-10 16:51:28 +02:00
in
([ ]
++ (build_definition_lines sway_conf.definitions)
++ (build_keybind_lines sway_conf.keybinds)
++ (build_exec_lines sway_conf.autolaunch)
++ (build_mode_lines sway_conf.modes)
++ optional (sway_conf.extraConfig != "") sway_conf.extraConfig
2024-04-10 16:51:28 +02:00
);
2024-04-10 16:42:11 +02:00
2024-04-20 19:50:23 +02:00
sway_conf = lib.concatLines (
2024-04-10 16:51:28 +02:00
(build_conf cfg.sway.config)
++ lib.optional cfg.sway.bar.enable bar_config
2024-04-11 10:56:21 +02:00
++ (lib.mapAttrsToList
(name: value:
"output ${value.id} mode ${value.mode}@${toString value.fps}Hz"
+ (lib.optionalString (value.pos != null) " position ${value.pos}")
)
cfg.screens)
2024-04-10 16:51:28 +02:00
);
2024-03-24 16:59:47 +01:00
2024-04-20 19:50:23 +02:00
conf_path = "sway.conf";
# sway_conf = pkgs.writeText "sway.conf" text;
2024-04-10 16:51:28 +02:00
in
with cfg; lib.mkIf (enable && sway.enable) {
2024-04-20 19:50:23 +02:00
environment.etc."${conf_path}".text = sway_conf;
2024-03-24 16:59:47 +01:00
2024-04-10 16:51:28 +02:00
environment.systemPackages = [
waybar_full
] ++ (with pkgs; [
procps
slurp
libnotify
]);
2024-03-24 16:59:47 +01:00
2024-04-10 16:51:28 +02:00
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
2024-04-21 16:02:55 +02:00
rm -rf /home/*/.cache/rmenu
2024-04-10 16:51:28 +02:00
'';
2024-04-20 19:50:23 +02:00
reloadTriggers = [ config.environment.etc."${conf_path}".source ];
2024-04-10 16:51:28 +02:00
};
2024-03-24 16:59:47 +01:00
2024-04-10 16:51:28 +02:00
programs.waybar.enable = true;
2024-03-24 16:59:47 +01:00
2024-04-10 16:51:28 +02:00
programs.sway = {
enable = true;
2024-04-20 19:50:23 +02:00
2024-04-10 16:51:28 +02:00
wrapperFeatures = {
gtk = true;
base = true;
};
extraPackages = with pkgs; [
swaylock
swayidle
wl-clipboard
wf-recorder
dmenu
2024-04-20 19:50:23 +02:00
# wlroots_0_16
2024-04-10 16:51:28 +02:00
wmenu
waybar-mpris
];
extraOptions = [
"--unsupported-gpu"
"--config"
2024-04-20 19:50:23 +02:00
"/etc/${conf_path}"
2024-04-10 16:51:28 +02:00
];
extraSessionCommands = ''
2024-04-21 16:02:55 +02:00
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 WLR_RENDERER=vulkan
export DRI_PRIME=1
export NIXOS_OZONE_WL=1
2024-04-10 16:51:28 +02:00
'';
2024-03-24 16:59:47 +01:00
};
};
options.grimmShared.sway = with lib; {
enable = mkEnableOption "grimm-sway";
bar = {
enable = mkEnableOption "grimm-sway-bar";
style = mkOption {
type = types.nullOr types.path;
default = null;
description = "waybar style sheet to use";
};
config = mkOption {
type = types.nullOr types.path;
default = null;
description = "waybar config to use";
};
};
config = mkOption {
type = sway_conf;
description = "sway config to use";
};
};
2024-03-24 16:59:47 +01:00
}