refactor: move modules to their own dir

This commit is contained in:
Jalil David Salamé Messina 2025-03-16 16:10:02 +01:00
parent dda72854df
commit addf563bfc
Signed by: jalil
GPG key ID: F016B9E770737A0B
26 changed files with 86 additions and 60 deletions

198
modules/hm/gui/default.nix Normal file
View file

@ -0,0 +1,198 @@
{
config,
lib,
pkgs,
osConfig ? null,
...
}:
let
inherit (config) jhome;
flatpakEnabled = if osConfig != null then osConfig.services.flatpak.enable else false;
osSway = osConfig == null && !osConfig.programs.sway.enable;
swayPkg = if osSway then pkgs.sway else null;
cfg = jhome.gui;
cursor = {
package = pkgs.nordzy-cursor-theme;
name = "Nordzy-cursors";
};
iconTheme = {
name = "Papirus-Dark";
package = pkgs.papirus-icon-theme;
};
in
{
config = lib.mkIf (jhome.enable && cfg.enable) {
home.packages =
(with pkgs; [
webcord
ferdium
xournalpp
signal-desktop
pcmanfm
wl-clipboard
# Extra fonts
noto-fonts-cjk-sans # Chinese, Japanese and Korean characters
noto-fonts-cjk-serif # Chinese, Japanese and Korean characters
(nerdfonts.override { fonts = [ "NerdFontsSymbolsOnly" ]; })
])
++ lib.optional flatpakEnabled pkgs.flatpak;
fonts.fontconfig = {
enable = true;
defaultFonts = lib.mkIf config.jhome.styling.enable {
emoji = [ "Noto Color Emoji" ];
monospace = [
"JetBrains Mono"
"Symbols Nerd Font"
];
serif = [
"Noto Serif"
"Symbols Nerd Font"
];
sansSerif = [
"Noto Sans"
"Symbols Nerd Font"
];
};
};
# Browser
programs = {
firefox.enable = true;
# Dynamic Menu
fuzzel = {
enable = true;
settings.main = lib.mkIf config.jhome.styling.enable {
icon-theme = "Papirus-Dark";
inherit (cfg) terminal;
layer = "overlay";
};
};
# Video player
mpv = {
enable = true;
scripts = builtins.attrValues { inherit (pkgs.mpvScripts) uosc thumbfast; };
};
# Text editor
nixvim.clipboard.providers.wl-copy.enable = lib.mkDefault true;
# Status bar
waybar = {
enable = true;
systemd.enable = true;
settings = lib.mkIf config.jhome.styling.enable (
import ./waybar-settings.nix { inherit config lib; }
);
style =
lib.optionalString config.jhome.styling.enable # css
''
.modules-left #workspaces button {
border-bottom: 3px solid @base01;
}
.modules-left #workspaces button.persistent {
border-bottom: 3px solid transparent;
}
'';
};
# Terminal
wezterm = {
enable = cfg.terminal == "wezterm";
extraConfig =
lib.optionalString config.jhome.styling.enable # lua
''
local wezterm = require("wezterm")
local config = wezterm.config_builder()
config.front_end = "WebGpu"
config.hide_tab_bar_if_only_one_tab = true
config.window_padding = { left = 1, right = 1, top = 1, bottom = 1 }
return config
'';
};
alacritty = {
enable = cfg.terminal == "alacritty";
settings = {
# hide mouse when typing, this ensures I don't have to move the mouse when it hides text
mouse.hide_when_typing = true;
# Start zellij when it is enabled
terminal.shell = lib.mkIf (config.jhome.dev.enable && config.programs.zellij.enable) {
program = "${lib.getExe config.programs.zellij.package}";
};
};
};
zellij.enable = cfg.terminal == "alacritty"; # alacritty has no terminal multiplexer built-in
# PDF reader
zathura.enable = true;
# Auto start sway
zsh.loginExtra =
lib.optionalString cfg.sway.autostart # sh
''
# Start Sway on login to TTY 1
if [ "$TTY" = /dev/tty1 ]; then
exec sway
fi
'';
};
services = {
# Volume/Backlight control and notifications
avizo = {
enable = true;
settings.default = {
time = 0.8;
border-width = 0;
height = 176;
y-offset = 0.1;
block-spacing = 1;
};
};
# Sound tuning
easyeffects.enable = true;
# Auto configure displays
kanshi.enable = lib.mkDefault true;
# Notifications
mako = {
enable = true;
layer = "overlay";
borderRadius = 8;
defaultTimeout = 15000;
};
};
# Window Manager
wayland.windowManager.sway = {
inherit (cfg.sway) enable;
package = swayPkg; # no sway package if it comes from the OS
config = import ./sway-config.nix { inherit config pkgs; };
systemd = {
enable = true;
xdgAutostart = true;
};
};
# Set cursor style
stylix = lib.mkIf config.jhome.styling.enable { inherit cursor; };
home.pointerCursor = lib.mkIf config.jhome.styling.enable (
lib.mkDefault {
gtk.enable = true;
inherit (cursor) name package;
}
);
# Set Gtk theme
gtk = lib.mkIf config.jhome.styling.enable {
enable = true;
inherit iconTheme;
gtk3.extraConfig.gtk-application-prefer-dark-theme = 1;
gtk4.extraConfig.gtk-application-prefer-dark-theme = 1;
};
# Set Qt theme
qt = lib.mkIf config.jhome.styling.enable {
enable = true;
platformTheme.name = "gtk";
};
xdg.systemDirs.data = [
"/usr/share"
"/var/lib/flatpak/exports/share"
"${config.xdg.dataHome}/flatpak/exports/share"
];
};
}

View file

@ -0,0 +1,118 @@
{ pkgs, config }:
let
cfg = config.jhome.gui.sway;
passmenu = "${pkgs.jpassmenu}/bin/jpassmenu";
selectAudio = "${pkgs.audiomenu}/bin/audiomenu";
swayconf = config.wayland.windowManager.sway.config;
mod = swayconf.modifier;
workspaces = map toString [
1
2
3
4
5
6
7
8
9
];
dirs =
map
(dir: {
key = swayconf.${dir};
arrow = dir;
direction = dir;
})
[
"up"
"down"
"left"
"right"
];
joinKeys = builtins.concatStringsSep "+";
# Generate a keybind from a modifier prefix and a key
keycombo = prefix: key: joinKeys (prefix ++ [ key ]);
modKeybind = keycombo [ mod ];
modCtrlKeybind = keycombo [
mod
"Ctrl"
];
modShiftKeybind = keycombo [
mod
"Shift"
];
modCtrlShiftKeybind = keycombo [
mod
"Ctrl"
"Shift"
];
dir2resize.up = "resize grow height";
dir2resize.down = "resize shrink height";
dir2resize.right = "resize grow width";
dir2resize.left = "resize shrink width";
# Bind a key combo to an action
genKeybind = prefix: action: key: { "${prefix key}" = "${action key}"; };
genKey =
prefix: action: genKeybind ({ key, ... }: prefix key) ({ direction, ... }: action direction);
genArrow =
prefix: action: genKeybind ({ arrow, ... }: prefix arrow) ({ direction, ... }: action direction);
genArrowAndKey =
prefix: action: key:
(genKey prefix action key) // (genArrow prefix action key);
# Move window
moveWindowKeybinds = map (genArrowAndKey modShiftKeybind (dir: "move ${dir}")) dirs;
# Focus window
focusWindowKeybinds = map (genArrowAndKey modKeybind (dir: "focus ${dir}")) dirs;
# Resize window
resizeWindowKeybinds = map (genArrowAndKey modCtrlKeybind (dir: dir2resize.${dir})) dirs;
# Move container to workspace
moveWorkspaceKeybindings = map (genKeybind modShiftKeybind (
number: "move container to workspace number ${number}"
)) workspaces;
# Focus workspace
focusWorkspaceKeybindings = map (genKeybind modKeybind (
number: "workspace number ${number}"
)) workspaces;
# Move container to Workspace and focus on it
moveFocusWorkspaceKeybindings = map (genKeybind modCtrlShiftKeybind (
number: "move container to workspace number ${number}; workspace number ${number}"
)) workspaces;
in
builtins.foldl' (l: r: l // r)
{
"${mod}+Return" = "exec ${swayconf.terminal}";
"${mod}+D" = "exec ${swayconf.menu}";
"${mod}+P" = "exec ${passmenu}";
"${mod}+Shift+P" = "exec ${passmenu} --type";
"${mod}+F2" = "exec qutebrowser";
"${mod}+Shift+Q" = "kill";
"${mod}+F" = "fullscreen toggle";
# Media Controls
"${mod}+F10" = "exec ${selectAudio} select-sink";
"${mod}+Shift+F10" = "exec ${selectAudio} select-source";
"XF86AudioRaiseVolume" = "exec ${pkgs.avizo}/bin/volumectl up";
"XF86AudioLowerVolume" = "exec ${pkgs.avizo}/bin/volumectl down";
"XF86AudioMute" = "exec ${pkgs.avizo}/bin/volumectl toggle-mute";
"XF86ScreenSaver" = "exec swaylock --image ${cfg.background}";
"XF86MonBrightnessUp" = "exec ${pkgs.avizo}/bin/lightctl up";
"XF86MonBrightnessDown" = "exec ${pkgs.avizo}/bin/lightctl down";
# Floating
"${mod}+Space" = "floating toggle";
"${mod}+Shift+Space" = "focus mode_toggle";
# Scratchpad
"${mod}+Minus" = "scratchpad show";
"${mod}+Shift+Minus" = "move scratchpad";
# Layout
"${mod}+e" = "layout toggle split";
# Session control
"${mod}+r" = "reload";
"${mod}+Shift+m" = "exit";
}
(
focusWindowKeybinds
++ moveWindowKeybinds
++ resizeWindowKeybinds
++ focusWorkspaceKeybindings
++ moveWorkspaceKeybindings
++ moveFocusWorkspaceKeybindings
)

View file

@ -0,0 +1,101 @@
{ config, pkgs }:
let
cfg = config.jhome.gui.sway;
modifier = "Mod4";
inherit (config.jhome.gui) terminal;
termCmd =
if terminal == "wezterm" then
"wezterm start"
else if terminal == "alacritty" then
"alacritty -e"
else
builtins.abort "no command configured for ${terminal}";
menu = "${pkgs.fuzzel}/bin/fuzzel --terminal '${termCmd}'";
# currently, there is some friction between sway and gtk:
# https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland
# the suggested way to set gtk settings is with gsettings
# for gsettings to work, we need to tell it where the schemas are
# using the XDG_DATA_DIR environment variable
# run at the end of sway config
configure-gtk =
let
schema = pkgs.gsettings-desktop-schemas;
datadir = "${schema}/share/gsettings-schemas/${schema.name}";
in
pkgs.writers.writeDashBin "configure-gtk" ''
export XDG_DATA_DIRS="${datadir}:$XDG_DATA_DIRS"
gnome_schema=org.gnome.desktop.interface
config="${config.xdg.configHome}/gtk-3.0/settings.ini"
if [ ! -f "$config" ]; then exit 1; fi
# Read settings from gtk3
gtk_theme="$(${pkgs.gnugrep}/bin/grep 'gtk-theme-name' "$config" | ${pkgs.gnused}/bin/sed 's/.*\s*=\s*//')"
icon_theme="$(${pkgs.gnugrep}/bin/grep 'gtk-icon-theme-name' "$config" | ${pkgs.gnused}/bin/sed 's/.*\s*=\s*//')"
cursor_theme="$(${pkgs.gnugrep}/bin/grep 'gtk-cursor-theme-name' "$config" | ${pkgs.gnused}/bin/sed 's/.*\s*=\s*//')"
font_name="$(grep 'gtk-font-name' "$config" | sed 's/.*\s*=\s*//')"
${pkgs.glib}/bin/gsettings set "$gnome_schema" gtk-theme "$gtk_theme"
${pkgs.glib}/bin/gsettings set "$gnome_schema" icon-theme "$icon_theme"
${pkgs.glib}/bin/gsettings set "$gnome_schema" cursor-theme "$cursor_theme"
${pkgs.glib}/bin/gsettings set "$gnome_schema" font-name "$font_name"
${pkgs.glib}/bin/gsettings set "$gnome_schema" color-scheme prefer-dark
'';
cmdOnce = command: { inherit command; };
cmdAlways = command: {
inherit command;
always = true;
};
in
{
inherit modifier terminal menu;
keybindings = import ./keybindings.nix { inherit config pkgs; };
# Appearance
bars = [ ]; # Waybar is started as a systemd service
gaps = {
smartGaps = true;
smartBorders = "on";
inner = 4;
};
output."*".bg = "${cfg.background} fill";
# Window Appearance
window = {
border = 2;
titlebar = false;
# Make certain windows floating
commands = [
{
command = "floating enable";
criteria.title = "zoom";
}
{
command = "floating enable";
criteria.class = "floating";
}
{
command = "floating enable";
criteria.app_id = "floating";
}
];
};
# Startup scripts
startup =
[
(cmdAlways "${configure-gtk}/bin/configure-gtk")
]
++ (builtins.map cmdAlways cfg.exec.always)
++ (builtins.map cmdOnce cfg.exec.once);
# Keyboard configuration
input."type:keyboard" = {
repeat_delay = "300";
repeat_rate = "50";
xkb_options = "caps:swapescape,compose:ralt";
xkb_numlock = "enabled";
};
# Touchpad
input."type:touchpad" = {
click_method = "clickfinger";
natural_scroll = "enabled";
scroll_method = "two_finger";
tap = "enabled";
tap_button_map = "lrm";
};
}

View file

@ -0,0 +1,127 @@
{ config, lib }:
let
cfg = config.jhome.gui;
in
{
mainBar = {
layer = "top";
position = "top";
margin = "2 2 2 2";
# Choose the order of the modules
modules-left = [ "sway/workspaces" ];
modules-center = [ "clock" ];
modules-right =
[
"pulseaudio"
"backlight"
"battery"
"sway/language"
"memory"
]
++ lib.optional (cfg.tempInfo != null) "temperature"
++ [ "tray" ];
"sway/workspaces" = {
disable-scroll = true;
persistent-workspaces = {
"1" = [ ];
"2" = [ ];
"3" = [ ];
"4" = [ ];
"5" = [ ];
"6" = [ ];
"7" = [ ];
"8" = [ ];
"9" = [ ];
};
};
"sway/language" = {
format = "{} ";
min-length = 5;
tooltip = false;
};
memory = {
format = "{used:0.1f}/{total:0.1f}GiB ";
interval = 3;
};
clock = {
timezone = "Europe/Berlin";
tooltip-format = "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>";
format = "{:%a, %d %b, %H:%M}";
};
pulseaudio = {
reverse-scrolling = 1;
format = "{volume}% {icon} {format_source}";
format-bluetooth = "{volume}% {icon} {format_source}";
format-bluetooth-muted = "{volume}% 󰖁 {icon} {format_source}";
format-muted = "{volume}% 󰖁 {format_source}";
format-source = "{volume}% ";
format-source-muted = "{volume}% 󰍭";
format-icons = {
headphone = "󰋋";
hands-free = "";
headset = "󰋎";
phone = "󰘂";
portable = "";
car = "";
default = [
"󰕿"
"󰖀"
"󰕾"
];
};
on-click = "pavucontrol";
min-length = 13;
};
temperature = lib.optionalAttrs (cfg.tempInfo != null) {
inherit (cfg.tempInfo) hwmon-path;
critical-threshold = 80;
format = "{temperatureC}°C {icon}";
format-icons = [
""
""
""
""
""
];
tooltip = false;
};
backlight = {
device = "intel_backlight";
format = "{percent}% {icon}";
format-icons = [
"󰃚"
"󰃛"
"󰃜"
"󰃝"
"󰃞"
"󰃟"
"󰃠"
];
min-length = 7;
};
battery = {
states.warning = 30;
states.critical = 15;
format = "{capacity}% {icon}";
format-charging = "{capacity}% 󰂄";
format-plugged = "{capacity}% 󰚥";
format-alt = "{time} {icon}";
format-icons = [
"󰁺"
"󰁻"
"󰁼"
"󰁽"
"󰁾"
"󰁿"
"󰂀"
"󰂁"
"󰂂"
"󰁹"
];
};
tray = {
icon-size = 16;
spacing = 0;
};
};
}