diff --git a/configs/laptop.nix b/configs/laptop.nix index b72f963..4c38bca 100644 --- a/configs/laptop.nix +++ b/configs/laptop.nix @@ -1,5 +1,8 @@ { + lib, pkgs, + config, + _utils, ... }: { @@ -29,9 +32,11 @@ programs.light.enable = true; # hyprland stuff - # services.blueman = lib.mkIf config.programs.hyprland.enable { enable = true; }; - # hm.wayland.windowManager.hyprland.settings.exec-once = with pkgs; [ - # "${lib.getExe networkmanagerapplet}" - # "${lib.getExe' blueman "blueman-applet"}" - # ]; + services.blueman = lib.mkIf config.programs.hyprland.enable { enable = true; }; + hj.".config/hypr/hyprland.conf".text = _utils.toHyprconf { + exec-once = with pkgs; [ + "${lib.getExe networkmanagerapplet}" + "${lib.getExe' blueman "blueman-applet"}" + ]; + }; } diff --git a/global/utils.nix b/global/utils.nix index a98b0a5..3efb923 100644 --- a/global/utils.nix +++ b/global/utils.nix @@ -111,4 +111,62 @@ alias = builtins.toString (pkgs.writeTextDir filename content) + "/"; tryFiles = "${filename} =${builtins.toString status}"; }; + + # https://github.com/nix-community/home-manager/blob/ec71b5162848e6369bdf2be8d2f1dd41cded88e8/modules/lib/generators.nix#L4-L61 + toHyprconf = + attrs: + let + inherit (lib) + all + concatMapStringsSep + concatStrings + concatStringsSep + filterAttrs + foldl + generators + hasPrefix + isAttrs + isList + mapAttrsToList + replicate + ; + + indentLevel = 0; + importantPrefixes = [ "$" ]; + initialIndent = concatStrings (replicate indentLevel " "); + + toHyprconf' = + indent: attrs: + let + sections = filterAttrs (n: v: isAttrs v || (isList v && all isAttrs v)) attrs; + + mkSection = + n: attrs: + if lib.isList attrs then + (concatMapStringsSep "\n" (a: mkSection n a) attrs) + else + '' + ${indent}${n} { + ${toHyprconf' " ${indent}" attrs}${indent}} + ''; + + mkFields = generators.toKeyValue { + listsAsDuplicateKeys = true; + inherit indent; + }; + + allFields = filterAttrs (n: v: !(isAttrs v || (isList v && all isAttrs v))) attrs; + + isImportantField = + n: _: foldl (acc: prev: if hasPrefix prev n then true else acc) false importantPrefixes; + + importantFields = filterAttrs isImportantField allFields; + + fields = builtins.removeAttrs allFields (mapAttrsToList (n: _: n) importantFields); + in + mkFields importantFields + + concatStringsSep "\n" (mapAttrsToList mkSection sections) + + mkFields fields; + in + toHyprconf' initialIndent attrs; } diff --git a/programs/alacritty.nix b/programs/alacritty.nix index f59a58f..da06c3d 100644 --- a/programs/alacritty.nix +++ b/programs/alacritty.nix @@ -3,24 +3,23 @@ pkgs, ... }: -{ - hm.programs.alacritty = - let - theme = pkgs.fetchurl { - # url = "https://raw.githubusercontent.com/catppuccin/alacritty/ce476fb41f307d90f841c1a4fd7f0727c21248b2/catppuccin-macchiato.toml"; - url = "https://raw.githubusercontent.com/rose-pine/alacritty/3c3e36eb5225b0eb6f1aa989f9d9e783a5b47a83/dist/rose-pine.toml"; - hash = "sha256-MheSmzz02ZLAOS2uaclyazu6E//eikcdFydFfkio0/U="; - }; +let + toml = pkgs.formats.toml { }; - themeAttr = builtins.fromTOML (builtins.readFile theme); - in - { - enable = true; - settings = lib.recursiveUpdate themeAttr { - font = { - normal.family = "Iosevka Nerd Font"; - size = 12; - }; + theme = pkgs.fetchurl { + # url = "https://raw.githubusercontent.com/catppuccin/alacritty/ce476fb41f307d90f841c1a4fd7f0727c21248b2/catppuccin-macchiato.toml"; + url = "https://raw.githubusercontent.com/rose-pine/alacritty/3c3e36eb5225b0eb6f1aa989f9d9e783a5b47a83/dist/rose-pine.toml"; + hash = "sha256-MheSmzz02ZLAOS2uaclyazu6E//eikcdFydFfkio0/U="; + }; + themeAttr = builtins.fromTOML (builtins.readFile theme); +in +{ + hj.".config/alacritty/alacritty.toml".source = toml.generate "alacritty.toml" ( + lib.recursiveUpdate themeAttr { + font = { + normal.family = "Iosevka Nerd Font"; + size = 12; }; - }; + } + ); } diff --git a/programs/fuzzel.nix b/programs/fuzzel.nix index a3c224a..7baf6ac 100644 --- a/programs/fuzzel.nix +++ b/programs/fuzzel.nix @@ -1,24 +1,24 @@ +{ lib, pkgs, ... }: { - hm.programs.fuzzel = { - enable = true; - settings = { - main = { - font = "Iosevka Nerd Font:size=16"; - dpi-aware = false; - horizontal-pad = 20; - }; + environment.systemPackages = [ pkgs.fuzzel ]; - border.radius = 8; + hj.".config/fuzzel/fuzzel.ini".text = lib.generators.toINI { } { + main = { + font = "Iosevka Nerd Font:size=16"; + dpi-aware = false; + horizontal-pad = 20; + }; - colors = { - background = "24273aff"; # base - border = "91d7e3cc"; # sky - text = "cad3f5ff"; # text - match = "a6da95ff"; # green - selection = "f4dbd6ff"; # rosewater - selection-text = "181926ff"; # crust - selection-match = "40a02bff"; # latte green - }; + border.radius = 8; + + colors = { + background = "24273aff"; # base + border = "91d7e3cc"; # sky + text = "cad3f5ff"; # text + match = "a6da95ff"; # green + selection = "f4dbd6ff"; # rosewater + selection-text = "181926ff"; # crust + selection-match = "40a02bff"; # latte green }; }; } diff --git a/programs/hyprland-misc.nix b/programs/hyprland-misc.nix index f37e79e..36e7bd7 100644 --- a/programs/hyprland-misc.nix +++ b/programs/hyprland-misc.nix @@ -1,8 +1,7 @@ { pkgs, ... }: { # utility packages for hyprland, since you know it's not a DE - - hm.home.packages = with pkgs; [ + environment.systemPackages = with pkgs; [ gnome.gnome-calculator mate.eom nwg-look diff --git a/programs/hyprland.nix b/programs/hyprland.nix index ae83972..3bc0936 100644 --- a/programs/hyprland.nix +++ b/programs/hyprland.nix @@ -1,6 +1,7 @@ { lib, pkgs, + _utils, ... }: { @@ -23,168 +24,163 @@ xdg.portal.extraPortals = with pkgs; [ xdg-desktop-portal-gtk ]; - hm = { - home.packages = with pkgs; [ - hyprpaper - hyprpicker - wl-clipboard - cliphist - swayidle - swappy - grimblast - playerctl - polkit_gnome - ]; + environment.systemPackages = with pkgs; [ + hyprpaper + hyprpicker + wl-clipboard + cliphist + swayidle + swappy + grimblast + playerctl + polkit_gnome + ]; - wayland.windowManager.hyprland = { - enable = true; - settings = - let - inherit (lib) getExe getExe'; - keys = [ - "ampersand" - "eacute" - "quotedbl" - "apostrophe" - "parenleft" - "minus" - "egrave" - "underscore" - "ccedilla" - "agrave" - ]; - in - with pkgs; - { - "$mod" = "SUPER"; - "$wl-paste" = getExe' wl-clipboard "wl-paste"; - "$wpctl" = getExe' wireplumber "wpctl"; + hj.".config/hypr/hyprland.conf".text = + let + inherit (lib) getExe getExe'; + keys = [ + "ampersand" + "eacute" + "quotedbl" + "apostrophe" + "parenleft" + "minus" + "egrave" + "underscore" + "ccedilla" + "agrave" + ]; + in + with pkgs; + _utils.toHyprconf { + "$mod" = "SUPER"; + "$wl-paste" = getExe' wl-clipboard "wl-paste"; + "$wpctl" = getExe' wireplumber "wpctl"; - monitor = lib.mkDefault ",highres,auto,1"; + monitor = lib.mkDefault ",highres,auto,1"; - env = [ - "WLR_DRM_NO_ATOMIC,1" - "SDL_VIDEODRIVER,wayland" - "MOZ_ENABLE_WAYLAND,1" - "_JAVA_AWT_WM_NONREPARENTING,1" - "NIXOS_OZONE_WL,1" - ]; + env = [ + "WLR_DRM_NO_ATOMIC,1" + "SDL_VIDEODRIVER,wayland" + "MOZ_ENABLE_WAYLAND,1" + "_JAVA_AWT_WM_NONREPARENTING,1" + "NIXOS_OZONE_WL,1" + ]; - exec-once = [ - "${getExe waybar}" - "${getExe hyprpaper}" - "${getExe swayidle} -w" - "${polkit_gnome}/libexec/polkit-gnome-authentication-agent-1" - "$wl-paste --type text --watch ${getExe cliphist} store" - "$wl-paste --type image --watch ${getExe cliphist} store" - ]; + exec-once = [ + "${getExe waybar}" + "${getExe hyprpaper}" + "${getExe swayidle} -w" + "${polkit_gnome}/libexec/polkit-gnome-authentication-agent-1" + "$wl-paste --type text --watch ${getExe cliphist} store" + "$wl-paste --type image --watch ${getExe cliphist} store" + ]; - input = { - kb_layout = "fr"; - follow_mouse = 1; + input = { + kb_layout = "fr"; + follow_mouse = 1; - touchpad.drag_lock = true; + touchpad.drag_lock = true; - sensitivity = -0.1; - accel_profile = "flat"; - }; + sensitivity = -0.1; + accel_profile = "flat"; + }; - general = { - gaps_in = 0; - gaps_out = 0; - border_size = 0; + general = { + gaps_in = 0; + gaps_out = 0; + border_size = 0; - allow_tearing = true; - }; + allow_tearing = true; + }; - decoration = { - drop_shadow = false; - blur.enabled = true; - }; + decoration = { + drop_shadow = false; + blur.enabled = true; + }; - animations = { - enabled = true; + animations = { + enabled = true; - animation = [ - "windows, 1, 2, default" - "windowsOut, 1, 2, default, popin 90%" - "fade, 1, 2, default" - "workspaces, 1, 3, default" - ]; - }; + animation = [ + "windows, 1, 2, default" + "windowsOut, 1, 2, default, popin 90%" + "fade, 1, 2, default" + "workspaces, 1, 3, default" + ]; + }; - dwindle = { - pseudotile = true; - preserve_split = true; - force_split = 2; - }; + dwindle = { + pseudotile = true; + preserve_split = true; + force_split = 2; + }; - gestures.workspace_swipe = true; + gestures.workspace_swipe = true; - windowrulev2 = [ - "float, class:^(pavucontrol)$" + windowrulev2 = [ + "float, class:^(pavucontrol)$" - "suppressevent maximize, class:^(firefox)$" - "float, title:^(Picture-in-Picture)$" - "float, class:^(firefox)$, title:^()$" # notifications + "suppressevent maximize, class:^(firefox)$" + "float, title:^(Picture-in-Picture)$" + "float, class:^(firefox)$, title:^()$" # notifications - "immediate, class:^(cs2)$" - "immediate, class:^(osu.*)$" - "immediate, class:^(steam_app_1229490)$" # ultrakill - # "immediate, class:^(steam_app_\d+)$" - # "immediate, class:^(steam_app_322170)$" - ]; + "immediate, class:^(cs2)$" + "immediate, class:^(osu.*)$" + "immediate, class:^(steam_app_1229490)$" # ultrakill + # "immediate, class:^(steam_app_\d+)$" + # "immediate, class:^(steam_app_322170)$" + ]; - bind = + bind = + [ + "$mod, Return, exec, ${getExe alacritty}" + "$mod SHIFT, A, killactive," + "$mod SHIFT, E, exit," + "$mod SHIFT, Space, togglefloating," + "$mod, D, exec, ${getExe fuzzel}" + "$mod, F, fullscreen, 0" + "$mod, P, pseudo," # dwindle + "$mod, J, togglesplit," # dwindle + + # audio + ",XF86AudioRaiseVolume, exec, $wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+" + ",XF86AudioLowerVolume, exec, $wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-" + ",XF86AudioMute, exec, $wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle" + ",XF86AudioMicMute, exec, $wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle" + ",XF86AudioPause, exec, ${getExe playerctl} play-pause" + ",XF86AudioPlay, exec, ${getExe playerctl} play-pause" + ",XF86AudioNext, exec, ${getExe playerctl} next" + ",XF86AudioPrev, exec, ${getExe playerctl} previous" + + # backlight + ",XF86MonBrightnessUp, exec, ${getExe' light "light"} -A 5" + ",XF86MonBrightnessDown, exec, ${getExe' light "light"} -U 5" + + # screenshot + ",Print, exec, ${getExe grimblast} --freeze save area - | ${getExe swappy} -f -" + ] + ++ + # Switch workspaces with mod + [0-9] + # Move active window to a workspace with mod + SHIFT + [0-9] + lib.flatten ( + builtins.map ( + i: + let + key = builtins.elemAt keys (i - 1); + in [ - "$mod, Return, exec, ${getExe alacritty}" - "$mod SHIFT, A, killactive," - "$mod SHIFT, E, exit," - "$mod SHIFT, Space, togglefloating," - "$mod, D, exec, ${getExe fuzzel}" - "$mod, F, fullscreen, 0" - "$mod, P, pseudo," # dwindle - "$mod, J, togglesplit," # dwindle - - # audio - ",XF86AudioRaiseVolume, exec, $wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+" - ",XF86AudioLowerVolume, exec, $wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-" - ",XF86AudioMute, exec, $wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle" - ",XF86AudioMicMute, exec, $wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle" - ",XF86AudioPause, exec, ${getExe playerctl} play-pause" - ",XF86AudioPlay, exec, ${getExe playerctl} play-pause" - ",XF86AudioNext, exec, ${getExe playerctl} next" - ",XF86AudioPrev, exec, ${getExe playerctl} previous" - - # backlight - ",XF86MonBrightnessUp, exec, ${getExe' light "light"} -A 5" - ",XF86MonBrightnessDown, exec, ${getExe' light "light"} -U 5" - - # screenshot - ",Print, exec, ${getExe grimblast} --freeze save area - | ${getExe swappy} -f -" + "$mod, ${key}, workspace, ${toString i}" + "$mod SHIFT, ${key}, movetoworkspace, ${toString i}" ] - ++ - # Switch workspaces with mod + [0-9] - # Move active window to a workspace with mod + SHIFT + [0-9] - lib.flatten ( - builtins.map ( - i: - let - key = builtins.elemAt keys (i - 1); - in - [ - "$mod, ${key}, workspace, ${toString i}" - "$mod SHIFT, ${key}, movetoworkspace, ${toString i}" - ] - ) (lib.range 1 10) - ); + ) (lib.range 1 10) + ); - bindm = [ - "$mod, mouse:272, movewindow" - "$mod, mouse:273, resizewindow" - "$mod SHIFT, mouse:272, resizewindow" - ]; - }; + bindm = [ + "$mod, mouse:272, movewindow" + "$mod, mouse:273, resizewindow" + "$mod SHIFT, mouse:272, resizewindow" + ]; }; - }; } diff --git a/programs/starship/default.nix b/programs/starship/default.nix index 135da01..d7cb632 100644 --- a/programs/starship/default.nix +++ b/programs/starship/default.nix @@ -1,13 +1,24 @@ +{ lib, pkgs, ... }: +let + toml = pkgs.formats.toml { }; +in { - hm.programs.starship = { - enable = true; - settings = { - add_newline = false; + environment.systemPackages = [ pkgs.starship ]; - directory = { - truncation_length = 3; - truncation_symbol = "…/"; - }; - } // (import ./nerd-font.nix); + hj = { + ".config/starship.toml" = + toml.generate "starship.toml" { + add_newline = false; + + directory = { + truncation_length = 3; + truncation_symbol = "…/"; + }; + } + // (import ./nerd-font.nix); + + ".config/fish/config.fish".text = lib.mkAfter '' + starship init fish | source + ''; }; } diff --git a/programs/waybar/default.nix b/programs/waybar/default.nix index 0290b19..5a4b4c9 100644 --- a/programs/waybar/default.nix +++ b/programs/waybar/default.nix @@ -5,93 +5,92 @@ ... }: { - hm.programs.waybar = { - enable = true; - style = ./style.css; + environment.systemPackages = [ pkgs.waybar ]; - settings = [ - { - position = "bottom"; - layer = "top"; - height = 24; - spacing = 2; + hj = { + ".config/waybar/style.css".source = ./style.css; - modules-left = [ "hyprland/workspaces" ]; - modules-center = [ ]; - modules-right = - [ "memory" ] - ++ lib.optionals (builtins.elem "amdgpu" config.services.xserver.videoDrivers) [ - "custom/gpu-usage" - ] - ++ [ - "cpu" - "wireplumber" - ] - ++ lib.optionals config.services.power-profiles-daemon.enable [ "battery" ] - ++ lib.optionals config.programs.light.enable [ "backlight" ] - ++ [ - "clock" - "tray" - ]; + ".config/waybar/config".text = builtins.toJSON { + position = "bottom"; + layer = "top"; + height = 24; + spacing = 2; - "hyprland/workspaces" = { - format = "{name}"; - on-click = "activate"; - sort-by-number = true; + modules-left = [ "hyprland/workspaces" ]; + modules-center = [ ]; + modules-right = + [ "memory" ] + ++ lib.optionals (builtins.elem "amdgpu" config.services.xserver.videoDrivers) [ + "custom/gpu-usage" + ] + ++ [ + "cpu" + "wireplumber" + ] + ++ lib.optionals config.services.power-profiles-daemon.enable [ "battery" ] + ++ lib.optionals config.programs.light.enable [ "backlight" ] + ++ [ + "clock" + "tray" + ]; + + "hyprland/workspaces" = { + format = "{name}"; + on-click = "activate"; + sort-by-number = true; + }; + + tray = { + icon-size = 16; + spacing = 10; + }; + + clock = { + format-alt = "{:%Y-%m-%d %H:%M:%S}"; + interval = 1; + }; + + cpu = { + format = "CPU {usage}%"; + tooltip = false; + interval = 2; + }; + + memory = { + format = "RAM {}%"; + interval = 2; + }; + + backlight = { + format = "LGT {percent}%"; + scroll-step = 5; + }; + + battery = { + states = { + low = 15; }; + format = "BAT {capacity}%"; + format-charging = "BAT+ {capacity}%"; + format-plugged = "BAT+ {capacity}%"; + format-low = "BAT! {capacity}%"; + interval = 5; + }; - tray = { - icon-size = 16; - spacing = 10; - }; + wireplumber = { + scroll-step = 5; + format = "VOL {volume}%"; + format-muted = "muted"; + on-click = "${lib.getExe' pkgs.wireplumber "wpctl"} set-mute @DEFAULT_AUDIO_SINK@ toggle"; + on-click-right = "${lib.getExe pkgs.pavucontrol}"; + }; - clock = { - format-alt = "{:%Y-%m-%d %H:%M:%S}"; - interval = 1; - }; - - cpu = { - format = "CPU {usage}%"; - tooltip = false; - interval = 2; - }; - - memory = { - format = "RAM {}%"; - interval = 2; - }; - - backlight = { - format = "LGT {percent}%"; - scroll-step = 5; - }; - - battery = { - states = { - low = 15; - }; - format = "BAT {capacity}%"; - format-charging = "BAT+ {capacity}%"; - format-plugged = "BAT+ {capacity}%"; - format-low = "BAT! {capacity}%"; - interval = 5; - }; - - wireplumber = { - scroll-step = 5; - format = "VOL {volume}%"; - format-muted = "muted"; - on-click = "${lib.getExe' pkgs.wireplumber "wpctl"} set-mute @DEFAULT_AUDIO_SINK@ toggle"; - on-click-right = "${lib.getExe pkgs.pavucontrol}"; - }; - - "custom/gpu-usage" = { - exec = "cat /sys/class/hwmon/hwmon*/device/gpu_busy_percent"; - format = "GPU {}%"; - return-type = ""; - interval = 2; - }; - } - ]; + "custom/gpu-usage" = { + exec = "cat /sys/class/hwmon/hwmon*/device/gpu_busy_percent"; + format = "GPU {}%"; + return-type = ""; + interval = 2; + }; + }; }; } diff --git a/systems/fuji/default.nix b/systems/fuji/default.nix index 83e4a96..46fe50a 100644 --- a/systems/fuji/default.nix +++ b/systems/fuji/default.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs, _utils, ... }: { imports = [ ./nvidia.nix @@ -11,14 +11,12 @@ wineWowPackages.waylandFull ]; - # hm = { - # wayland.windowManager.hyprland.settings = { - # monitor = "DP-1,3840x2160@144,0x0,1.5"; - # xwayland.force_zero_scaling = true; - # env = [ - # "GDK_SCALE,1.5" - # "XCURSOR_SIZE,24" - # ]; - # }; - # }; + hj.".config/hypr/hyprland.conf".text = _utils.toHyprconf { + monitor = "DP-1,3840x2160@144,0x0,1.5"; + xwayland.force_zero_scaling = true; + env = [ + "GDK_SCALE,1.5" + "XCURSOR_SIZE,24" + ]; + }; } diff --git a/systems/fuji/nvidia.nix b/systems/fuji/nvidia.nix index 78d2e26..d22d70c 100644 --- a/systems/fuji/nvidia.nix +++ b/systems/fuji/nvidia.nix @@ -2,6 +2,7 @@ lib, pkgs, config, + _utils, ... }: { @@ -37,10 +38,12 @@ }; }; - # hm.wayland.windowManager.hyprland.settings.env = [ - # "XDG_SESSION_TYPE,wayland" - # "GBM_BACKEND,nvidia-drm" - # "__GLX_VENDOR_LIBRARY_NAME,nvidia" - # "NVD_BACKEND,direct" - # ]; + hj.".config/hypr/hyprland.conf".text = _utils.toHyprconf { + env = [ + "XDG_SESSION_TYPE,wayland" + "GBM_BACKEND,nvidia-drm" + "__GLX_VENDOR_LIBRARY_NAME,nvidia" + "NVD_BACKEND,direct" + ]; + }; }