Add home-manager config for sway and hyprland, and enable hyprland for host nixos

This commit is contained in:
Cameron Reed 2024-01-21 19:55:41 -07:00
parent aea956202e
commit efc388197b
10 changed files with 349 additions and 4 deletions

View File

@ -3,13 +3,16 @@
{
desktop = [ "hyprland" ];
programs.hyprland.enable = true;
programs.hyprland = {
enable = true;
xwayland.enable = true;
};
environment.systemPackages = (with pkgs; [
waybar
dmenu
wmenu
swaylock
swayidle
]);
xdg.portal.wlr.enable = true;
}

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
lines='-l 4'
options='Log out\nShutdown\nReboot\nCancel'
answer=$(echo -e "$options" | wmenu "$lines" -i -p 'Action:')
case $answer in
'Log out')
hyprctl dispatch exit
;;
'Shutdown')
systemctl poweroff
;;
'Reboot')
systemctl reboot
;;
esac

View File

@ -0,0 +1,165 @@
{ pkgs, lib, osConfig, ... }:
{
config = lib.mkIf (builtins.elem "hyprland" osConfig.desktops) (
let startup = pkgs.writeShellScript "startup.sh" ''
hyprctl setcursor Bibata-Original-Classic 24
waybar &
swayidle -w \
timeout 270 'swaylock -f' \
timeout 300 'hyprctl dispatch dpms off' \
before-sleep 'swaylock -f; sleep 1' \
after-resume 'hyprctl dispatch dpms on' &
'';
in { wayland.windowManager.hyprland = {
enable = true;
settings = {
"$mod" = "SUPER";
"$term" = "kitty";
"$browser" = "firefox";
"$menu" = "dmenu_path | wmenu -p 'Run:' -l 10 | xargs hyprctl dispatch exec";
exec-once = startup;
monitor = [
",preferred,auto,1"
"eDP-1,preferred,0x0,1.5"
];
env = [
"XCURSOR_SIZE,24"
"DEFAULT_TERM,$term"
];
input = {
kb_layout = "us";
numlock_by_default = true;
accel_profile = "flat";
scroll_method = "2fg";
follow_mouse = 2;
touchpad = {
natural_scroll = true;
tap-to-click = true;
};
};
general = {
gaps_in = 2;
gaps_out = 2;
border_size = 2;
"col.active_border" = "rgba(00aaffee) rgba(00ffffee) -45deg";
"col.inactive_border" = "rgba(595959aa)";
layout = "dwindle";
};
decoration = {
rounding = 2;
drop_shadow = true;
shadow_range = 4;
shadow_render_power = 3;
"col.shadow" = "rgba(1a1a1aee)";
blur = {
enabled = true;
size = 3;
passes = 1;
new_optimizations = true;
};
};
animations = {
enabled = true;
bezier = [
"myBezier, 0.05, 0.9, 0.1, 1.05"
];
animation = [
"windows, 1, 7, myBezier"
"windowsOut, 1, 7, default, popin 80%"
"border, 1, 10, default"
"borderangle, 1, 8, default"
"fade, 1, 7, default"
"workspaces, 1, 6, default"
];
};
dwindle = {
pseudotile = true;
preserve_split = true;
};
master = {
new_is_master = true;
};
gestures = {
workspace_swipe = "on";
};
misc = {
force_default_wallpaper = 0;
};
windowrulev2 = [
"nomaximizerequest, class:.*"
];
bindr = [
"$mod, SUPER_L, exec, pkill wmenu || $menu"
"$mod SHIFT, E, exec, ${./hypr-scripts/logout.sh}"
"$mod, Escape, exec, swaylock"
"$mod SHIFT, Escape, exec, swaylock -f && sleep 2 && hyprctl dispatch dpms off"
];
bind = [
"$mod, Return, exec, $term"
"$mod, B, exec, $browser"
"$mod, E, killactive,"
"$mod, left, movefocus, l"
"$mod, right, movefocus, r"
"$mod, up, movefocus, u"
"$mod, down, movefocus, d"
"$mod, H, movefocus, l"
"$mod, L, movefocus, r"
"$mod, K, movefocus, u"
"$mod, J, movefocus, d"
"$mod SHIFT, left, movewindow, l"
"$mod SHIFT, right, movewindow, r"
"$mod SHIFT, up, movewindow, u"
"$mod SHIFT, down, movewindow, d"
"$mod SHIFT, H, movewindow, l"
"$mod SHIFT, L, movewindow, r"
"$mod SHIFT, K, movewindow, u"
"$mod SHIFT, J, movewindow, d"
] ++ (
# workspaces
# binds $mod + [shift +] {1..10} to [move to] workspace {1..10}
builtins.concatLists (builtins.genList (
x: let
ws = let
c = (x + 1) / 10; # (This is integer division)
in
builtins.toString (x + 1 - (c * 10));
in [
"$mod, ${ws}, workspace, ${toString (x + 1)}"
"$mod SHIFT, ${ws}, movetoworkspace, ${toString (x + 1)}"
]
)
10)
);
}; # settings
};});
}

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
lines='-l 4'
options='Log out\nShutdown\nReboot\nCancel'
answer=$(echo -e "$options" | wmenu "$lines" -i -p 'Action:')
case $answer in
'Log out')
swaymsg exit
;;
'Shutdown')
systemctl poweroff
;;
'Reboot')
systemctl reboot
;;
esac

View File

@ -0,0 +1,102 @@
{ pkgs, lib, config, osConfig, ... }:
{
config = lib.mkIf (builtins.elem "sway" osConfig.desktop) (
let
WOBSOCK = "$XDG_RUNTIME_DIR/wob.sock";
in { wayland.windowManager.sway = {
enable = true;
config = {
modifier = "Mod4";
terminal = "${pkgs.kitty}/bin/kitty";
menu = "${pkgs.dmenu}/bin/dmenu_path | ${pkgs.wmenu}/bin/wmenu -p 'Run:' -l 10 | ${pkgs.findutils}/bin/xargs swaymsg exec --";
startup = [
{ command = "rm -f ${WOBSOCK} && mkfifo ${WOBSOCK} && tail -f ${WOBSOCK} | ${pkgs.wob}/bin/wob"; }
{ command = "swayidle -w timeout 270 'swaylock -f' timeout 300 'systemctl suspend' before-sleep 'swaylock -f; sleep 1' after-resume 'swaymsg \"output * dpms on\" &"; }
];
output = {
"*" = {
bg = "~/Pictures/background.jpg fill";
};
eDP-1 = {
scale = 1.5;
};
};
seat = {
"*" = {
xcursor_theme = "Bibata-Original-Classic";
};
};
gaps = {
inner = 2;
outer = 2;
};
input = {
"type:touchpad" = {
dwt = "enabled";
tap = "enabled";
natural_scroll = "enabled";
middle_emulation = "enabled";
};
};
extraConfig = ''
for_window {
[shell="xwayland"] title_format "%title [XWayland]"
[shell="xwayland"] border normal 2
[window_role="pop-up"] floating enable
[window_role="bubble"] floating enable
[window_role="dialog"] floating enable
[window_type="dialog"] floating enable
[title="(?:Open|Save) (?:File|Folder|As)"] floating enable, resize set width 1030 height 710
[class="Minecraft.*"] floating enable
[con_mark="caffeine"] inhibit_idle title_format "%title [Caffeinated]"
}
bindgesture swipe:3:left workspace next
bindgesture swipe:3:right workspace prev
bindsym --locked XF86MonBrightnessDown exec brightnessctl set 5%- | sed -En 's/.*\(([0-9]+)%\).*/\1/p' > ${WOBSOCK}
bindsym --locked XF86MonBrightnessUp exec brightnessctl set 5%+ | sed -En 's/.*\(([0-9]+)%\).*/\1/p' > ${WOBSOCK}
bindsym --locked XF86AudioRaiseVolume exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ -l 1 && wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print substr($2, 3, length($2))}' > ${WOBSOCK}
bindsym --locked XF86AudioLowerVolume exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- -l 1 && wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print substr($2, 3, length($2))}' > ${WOBSOCK}
'';
keybindings = (
let
mod = config.wayland.windowManager.sway.config.modifier;
menu = config.wayland.windowManager.sway.config.menu;
in lib.mkOptionDefault {
"${mod}+c" = "mark --toggle caffeine";
"${mod}+Return" = "exec ${pkgs.kitty}/bin/kitty";
"${mod}+n" = "exec ${pkgs.firefox}/bin/firefox";
"${mod}+d" = "exec pkill wmenu || ${menu}";
"${mod}+Shift+q" = "kill";
"${mod}+Shift+e" = "exec ${./sway-scripts/logout.sh}";
"${mod}+Escape" = "exec ${pkgs.swaylock}/bin/swaylock -f";
"${mod}+Shift+Escape" = "exec ${pkgs.swaylock}/bin/swaylock -f && sleep 2 && systemctl suspend";
});
bars.swaybar = {
position = "top";
statusCommand = "${pkgs.i3status}/bin/i3status";
colors = {
statusline = "#ffffff";
background = "#323232";
inactiveWorkspace = "#32323200 #32323200 #5c5c5c";
};
};
}; # config
};
});
}

View File

@ -0,0 +1,13 @@
{ pkgs, lib, osConfig, ... }:
{
config = lib.mkIf (builtins.elem "hyprland" osConfig.desktop || builtins.elem "sway" osConfig.desktop)
{ programs.swaylock = {
enable = true;
settings = {
ignore-empty-password = true;
color = "333333";
};
};
};
}

View File

@ -0,0 +1,13 @@
{ pkgs, lib, osConfig, ... }:
{
imports = [
./home-manager/sway.nix
./home-manager/hyprland.nix
./home-manager/swaylock.nix
];
home.username = "cameron";
home.homeDirectory = osConfig.users.users.cameron.home;
}

View File

@ -26,7 +26,7 @@
home-manager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
# home-manager.users.cameron = import ./hosts/nixos/home-manager/cameron.nix;
home-manager.users.cameron = import ./hosts/nixos/home-manager/cameron.nix;
}
];
};

View File

@ -11,6 +11,7 @@
(common_dir + /users/users.nix)
(common_dir + /login-manager/tuigreet.nix)
(common_dir + /desktop/sway.nix)
(common_dir + /desktop/hyprland.nix)
];

View File

@ -0,0 +1,10 @@
{ lib, pkgs, osConfig, common_dir, ... }:
{
imports = [
(common_dir + /users/cameron/home.nix)
];
home.stateVersion = "24.05";
}