From 787b5855b1669466f3d20d7f201e972bef60009e Mon Sep 17 00:00:00 2001 From: NullBite Date: Fri, 9 Feb 2024 07:56:12 +0100 Subject: [PATCH 1/4] Convert home-manager modules to options --- home/comma.nix | 16 +- home/common.nix | 24 ++- home/default.nix | 5 + home/hyprland.nix | 402 +++++++++++++++++++++++---------------------- home/wm-common.nix | 18 +- 5 files changed, 255 insertions(+), 210 deletions(-) diff --git a/home/comma.nix b/home/comma.nix index 203f26a..ca53b0e 100644 --- a/home/comma.nix +++ b/home/comma.nix @@ -1,10 +1,20 @@ { lib, pkgs, config, inputs, ... } @args: +let + cfg = config.nixfiles.programs.comma; +in { imports = [ inputs.nix-index-database.hmModules.nix-index ]; - home.packages = with pkgs; [ - comma - ]; + options.nixfiles.programs.comma = { + enable = lib.mkEnableOption "comma"; + }; + + config = { + programs.nix-index.symlinkToCacheHome = lib.mkDefault cfg.enable; + home.packages = with pkgs; lib.optionals cfg.enable [ + comma + ]; + }; } diff --git a/home/common.nix b/home/common.nix index 1e4d75f..8ebec24 100644 --- a/home/common.nix +++ b/home/common.nix @@ -1,12 +1,22 @@ -{ lib, pkgs, osConfig, ... }: +{ lib, pkgs, config, osConfig, ... }: +let + cfg = config.nixfiles.profile.base; +in { - imports = [ - ./comma.nix - ]; + # imports = [ + # ./comma.nix + # ]; # home.username = "nullbite"; # home.homeDirectory = "/home/nullbite"; - home.packages = with pkgs; [ - btop - ]; + options.nixfiles.profile.base = { + enable = lib.mkEnableOption "base profile"; + }; + + config = lib.mkIf cfg.enable { + nixfiles.programs.comma.enable = true; + home.packages = with pkgs; [ + btop + ]; + }; } diff --git a/home/default.nix b/home/default.nix index 3a51d80..2924e26 100644 --- a/home/default.nix +++ b/home/default.nix @@ -5,6 +5,11 @@ let in { imports = [ + ./common + ./package-sets + ./profile + ./programs + ./sessions ]; config = {}; options.nixfiles = { diff --git a/home/hyprland.nix b/home/hyprland.nix index ebc1489..ae2526e 100644 --- a/home/hyprland.nix +++ b/home/hyprland.nix @@ -1,5 +1,6 @@ -{ lib, pkgs, osConfig, outputs, ... }@args: +{ lib, pkgs, config, osConfig ? {}, outputs, ... }@args: let + cfg = config.nixfiles.sessions.hyprland; mkd = lib.mkDefault; terminal = "${pkgs.kitty}/bin/kitty"; files = "${pkgs.dolphin}/bin/dolphin"; @@ -24,220 +25,233 @@ in { # FIXME this is temporary just to get it working, need to make wm-common an # option first - imports = [ - ./wm-common.nix - ]; - home.packages = with pkgs; [ - kitty - dolphin - rofi-wayland - wev - dunst - pkgs.brightnessctl - ]; + # imports = [ + # ./wm-common.nix + # ]; - wayland.windowManager.hyprland = { - enable = true; - settings = { + options.nixfiles.sessions.hyprland = { + enable = lib.mkOption { + type = lib.types.bool; + default = if (builtins.hasAttr "home-manager" osConfig) then osConfig.nixfiles.sessions.hyprland.enable else false; + example = true; + description = "Whether to enable hyprland."; + }; + }; - # Xwayland fix - xwayland.force_zero_scaling = mkd true; + config = lib.mkIf cfg.enable { + nixfiles.common.wm.enable = true; + home.packages = with pkgs; [ + kitty + dolphin + rofi-wayland + wev + dunst + pkgs.brightnessctl + ]; - # See https://wiki.hyprland.org/Configuring/Monitors/ - monitor = mkd ",preferred,auto,auto"; + wayland.windowManager.hyprland = { + enable = true; + settings = { - # See https://wiki.hyprland.org/Configuring/Keywords/ for more + # Xwayland fix + xwayland.force_zero_scaling = mkd true; - # Execute your favorite apps at launch - # exec-once = waybar & hyprpaper & firefox + # See https://wiki.hyprland.org/Configuring/Monitors/ + monitor = mkd ",preferred,auto,auto"; - exec-once = [ - notifydaemon - polkit-agent - ]; + # See https://wiki.hyprland.org/Configuring/Keywords/ for more - # Source a file (multi-file configs) - # source = ~/.config/hypr/myColors.conf + # Execute your favorite apps at launch + # exec-once = waybar & hyprpaper & firefox - # Some default env vars. - env = mkd "XCURSOR_SIZE,24"; + exec-once = [ + notifydaemon + polkit-agent + ]; + + # Source a file (multi-file configs) + # source = ~/.config/hypr/myColors.conf + + # Some default env vars. + env = mkd "XCURSOR_SIZE,24"; - # For all categories, see https://wiki.hyprland.org/Configuring/Variables/ - input = { - kb_layout = mkd "us"; - # kb_variant = - # kb_model = - # kb_options = - # kb_rules = + # For all categories, see https://wiki.hyprland.org/Configuring/Variables/ + input = { + kb_layout = mkd "us"; + # kb_variant = + # kb_model = + # kb_options = + # kb_rules = - follow_mouse = mkd true; + follow_mouse = mkd true; - touchpad.natural_scroll = mkd true; + touchpad.natural_scroll = mkd true; - sensitivity = mkd 0; # -1.0 - 1.0, 0 means no modification. - }; - - general = { - # See https://wiki.hyprland.org/Configuring/Variables/ for more - - gaps_in = mkd 5; - gaps_out = mkd 20; - border_size = mkd 2; - "col.active_border" = mkd "rgba(33ccffee) rgba(00ff99ee) 45deg"; - "col.inactive_border" = mkd "rgba(595959aa)"; - - layout = mkd "dwindle"; - - # Please see https://wiki.hyprland.org/Configuring/Tearing/ before you turn this on - allow_tearing = mkd false; - }; - - decoration = { - # See https://wiki.hyprland.org/Configuring/Variables/ for more - rounding = mkd 10; - - blur = { - enabled = mkd true; - size = mkd 3; - passes = mkd 1; + sensitivity = mkd 0; # -1.0 - 1.0, 0 means no modification. }; - drop_shadow = mkd true; - shadow_range = mkd 4; - shadow_render_power = mkd 3; - "col.shadow" = mkd "rgba(1a1a1aee)"; - }; + general = { + # See https://wiki.hyprland.org/Configuring/Variables/ for more - animations = { - enabled = mkd true; + gaps_in = mkd 5; + gaps_out = mkd 20; + border_size = mkd 2; + "col.active_border" = mkd "rgba(33ccffee) rgba(00ff99ee) 45deg"; + "col.inactive_border" = mkd "rgba(595959aa)"; - # Some default animations, see https://wiki.hyprland.org/Configuring/Animations/ for more + layout = mkd "dwindle"; - bezier = mkd "myBezier, 0.05, 0.9, 0.1, 1.05"; + # Please see https://wiki.hyprland.org/Configuring/Tearing/ before you turn this on + allow_tearing = mkd false; + }; - 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" + decoration = { + # See https://wiki.hyprland.org/Configuring/Variables/ for more + rounding = mkd 10; + + blur = { + enabled = mkd true; + size = mkd 3; + passes = mkd 1; + }; + + drop_shadow = mkd true; + shadow_range = mkd 4; + shadow_render_power = mkd 3; + "col.shadow" = mkd "rgba(1a1a1aee)"; + }; + + animations = { + enabled = mkd true; + + # Some default animations, see https://wiki.hyprland.org/Configuring/Animations/ for more + + bezier = mkd "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 = { + # See https://wiki.hyprland.org/Configuring/Dwindle-Layout/ for more + pseudotile = mkd true; # master switch for pseudotiling. Enabling is bound to mainMod + P in the keybinds section below + preserve_split = mkd true; # you probably want this + }; + + master = { + # See https://wiki.hyprland.org/Configuring/Master-Layout/ for more + new_is_master = mkd "true"; + }; + + gestures = { + # See https://wiki.hyprland.org/Configuring/Variables/ for more + workspace_swipe = mkd "false"; + }; + + misc = { + # See https://wiki.hyprland.org/Configuring/Variables/ for more + force_default_wallpaper = mkd 0; # Set to 0 to disable the anime mascot wallpapers + }; + + "$mod" = mkd "SUPER"; + + # Example windowrule v1 + # windowrule = float, ^(kitty)$ + # Example windowrule v2 + # windowrulev2 = float,class:^(kitty)$,title:^(kitty)$ + # See https://wiki.hyprland.org/Configuring/Window-Rules/ for more + + # Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more + bind = [ + "$mod, Q, exec, ${terminal}" + "$mod, Return, exec, ${terminal}" + "$mod, C, killactive, " + "$mod, M, exit, " + "$mod, E, exec, ${files}" + "$mod, V, togglefloating, " + "$mod, R, exec, ${rofi} -show drun" + "$mod, P, pseudo," # dwindle" + "$mod, O, togglesplit," # dwindle" + + # Move focus with mod + arrow keys + "$mod, left, movefocus, l" + "$mod, right, movefocus, r" + "$mod, up, movefocus, u" + "$mod, down, movefocus, d" + + "$mod, h, movefocus, l" + "$mod, j, movefocus, d" + "$mod, k, movefocus, u" + "$mod, l, movefocus, r" + + # Switch workspaces with mod + [0-9] + "$mod, 1, workspace, 1" + "$mod, 2, workspace, 2" + "$mod, 3, workspace, 3" + "$mod, 4, workspace, 4" + "$mod, 5, workspace, 5" + "$mod, 6, workspace, 6" + "$mod, 7, workspace, 7" + "$mod, 8, workspace, 8" + "$mod, 9, workspace, 9" + "$mod, 0, workspace, 10" + #] ++ map () [] ++ TODO reconfigure these with workspace helper function + #[ + # Move active window to a workspace with mod + SHIFT + [0-9] + "$mod SHIFT, 1, movetoworkspace, 1" + "$mod SHIFT, 2, movetoworkspace, 2" + "$mod SHIFT, 3, movetoworkspace, 3" + "$mod SHIFT, 4, movetoworkspace, 4" + "$mod SHIFT, 5, movetoworkspace, 5" + "$mod SHIFT, 6, movetoworkspace, 6" + "$mod SHIFT, 7, movetoworkspace, 7" + "$mod SHIFT, 8, movetoworkspace, 8" + "$mod SHIFT, 9, movetoworkspace, 9" + "$mod SHIFT, 0, movetoworkspace, 10" + + # Example special workspace (scratchpad) + "$mod, S, togglespecialworkspace, magic" + "$mod SHIFT, S, movetoworkspace, special:magic" + + # Scroll through existing workspaces with mod + scroll + "$mod, mouse_down, workspace, e+1" + "$mod, mouse_up, workspace, e-1" + + # show this file (help) + ("$mod, slash, exec, ${terminal} -e ${pkgs.neovim}/bin/nvim '+set nomodifiable' '+noremap q :q' " + args.vars.self.outPath + "/home/hyprland.nix") + ]; + + # repeat, ignore mods + bindei = [ + # Volume controls + ",XF86AudioRaiseVolume, exec, ${keysetting} volumeup" + ",XF86AudioLowerVolume, exec, ${keysetting} volumedown" + ",XF86AudioMute, exec, ${keysetting} mute" + ",XF86AudioMicMute, exec, ${keysetting} micmute" + + # brightness + ",XF86KbdBrightnessDown, exec, ${keysetting} keydown" + ",XF86KbdBrightnessUp, exec, ${keysetting} keyup" + ",XF86MonBrightnessDown, exec, ${keysetting} mondown" + ",XF86MonBrightnessUp, exec, ${keysetting} monup" + + ]; + + bindm = [ + # Move/resize windows with mod + LMB/RMB and dragging + "$mod, mouse:272, movewindow" + "$mod, mouse:273, resizewindow" + # RMB sucks on laptop + "$mod SHIFT, mouse:272, resizewindow" ]; }; - - dwindle = { - # See https://wiki.hyprland.org/Configuring/Dwindle-Layout/ for more - pseudotile = mkd true; # master switch for pseudotiling. Enabling is bound to mainMod + P in the keybinds section below - preserve_split = mkd true; # you probably want this - }; - - master = { - # See https://wiki.hyprland.org/Configuring/Master-Layout/ for more - new_is_master = mkd "true"; - }; - - gestures = { - # See https://wiki.hyprland.org/Configuring/Variables/ for more - workspace_swipe = mkd "false"; - }; - - misc = { - # See https://wiki.hyprland.org/Configuring/Variables/ for more - force_default_wallpaper = mkd 0; # Set to 0 to disable the anime mascot wallpapers - }; - - "$mod" = mkd "SUPER"; - - # Example windowrule v1 - # windowrule = float, ^(kitty)$ - # Example windowrule v2 - # windowrulev2 = float,class:^(kitty)$,title:^(kitty)$ - # See https://wiki.hyprland.org/Configuring/Window-Rules/ for more - - # Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more - bind = [ - "$mod, Q, exec, ${terminal}" - "$mod, Return, exec, ${terminal}" - "$mod, C, killactive, " - "$mod, M, exit, " - "$mod, E, exec, ${files}" - "$mod, V, togglefloating, " - "$mod, R, exec, ${rofi} -show drun" - "$mod, P, pseudo," # dwindle" - "$mod, O, togglesplit," # dwindle" - - # Move focus with mod + arrow keys - "$mod, left, movefocus, l" - "$mod, right, movefocus, r" - "$mod, up, movefocus, u" - "$mod, down, movefocus, d" - - "$mod, h, movefocus, l" - "$mod, j, movefocus, d" - "$mod, k, movefocus, u" - "$mod, l, movefocus, r" - - # Switch workspaces with mod + [0-9] - "$mod, 1, workspace, 1" - "$mod, 2, workspace, 2" - "$mod, 3, workspace, 3" - "$mod, 4, workspace, 4" - "$mod, 5, workspace, 5" - "$mod, 6, workspace, 6" - "$mod, 7, workspace, 7" - "$mod, 8, workspace, 8" - "$mod, 9, workspace, 9" - "$mod, 0, workspace, 10" - #] ++ map () [] ++ TODO reconfigure these with workspace helper function - #[ - # Move active window to a workspace with mod + SHIFT + [0-9] - "$mod SHIFT, 1, movetoworkspace, 1" - "$mod SHIFT, 2, movetoworkspace, 2" - "$mod SHIFT, 3, movetoworkspace, 3" - "$mod SHIFT, 4, movetoworkspace, 4" - "$mod SHIFT, 5, movetoworkspace, 5" - "$mod SHIFT, 6, movetoworkspace, 6" - "$mod SHIFT, 7, movetoworkspace, 7" - "$mod SHIFT, 8, movetoworkspace, 8" - "$mod SHIFT, 9, movetoworkspace, 9" - "$mod SHIFT, 0, movetoworkspace, 10" - - # Example special workspace (scratchpad) - "$mod, S, togglespecialworkspace, magic" - "$mod SHIFT, S, movetoworkspace, special:magic" - - # Scroll through existing workspaces with mod + scroll - "$mod, mouse_down, workspace, e+1" - "$mod, mouse_up, workspace, e-1" - - # show this file (help) - ("$mod, slash, exec, ${terminal} -e ${pkgs.neovim}/bin/nvim '+set nomodifiable' '+noremap q :q' " + args.vars.self.outPath + "/home/hyprland.nix") - ]; - - # repeat, ignore mods - bindei = [ - # Volume controls - ",XF86AudioRaiseVolume, exec, ${keysetting} volumeup" - ",XF86AudioLowerVolume, exec, ${keysetting} volumedown" - ",XF86AudioMute, exec, ${keysetting} mute" - ",XF86AudioMicMute, exec, ${keysetting} micmute" - - # brightness - ",XF86KbdBrightnessDown, exec, ${keysetting} keydown" - ",XF86KbdBrightnessUp, exec, ${keysetting} keyup" - ",XF86MonBrightnessDown, exec, ${keysetting} mondown" - ",XF86MonBrightnessUp, exec, ${keysetting} monup" - - ]; - - bindm = [ - # Move/resize windows with mod + LMB/RMB and dragging - "$mod, mouse:272, movewindow" - "$mod, mouse:273, resizewindow" - # RMB sucks on laptop - "$mod SHIFT, mouse:272, resizewindow" - ]; }; }; } diff --git a/home/wm-common.nix b/home/wm-common.nix index 3e173bf..dfc3d75 100644 --- a/home/wm-common.nix +++ b/home/wm-common.nix @@ -1,14 +1,20 @@ { pkgs, lib, config, osConfig, options, ...}: let + cfg = config.nixfiles.common.wm; inherit (lib) mkDefault; in { - # Common options for standalone window managers; many of these (or - # alternatives thereof) are pulled in by desktop environments. - services = { - udiskie = { - enable = mkDefault true; - automount = mkDefault false; + options.nixfiles.common.wm = { + enable = lib.mkEnableOption "common window manager config"; + }; + config = lib.mkIf cfg.enable { + # Common options for standalone window managers; many of these (or + # alternatives thereof) are pulled in by desktop environments. + services = { + udiskie = { + enable = mkDefault true; + automount = mkDefault false; + }; }; }; } From ae20b39529ef1ff06e0c1a54dcbcaf2633701546 Mon Sep 17 00:00:00 2001 From: NullBite Date: Fri, 9 Feb 2024 08:07:16 +0100 Subject: [PATCH 2/4] home: move modules, add default.nix --- home/common/default.nix | 6 ++++++ home/{wm-common.nix => common/wm.nix} | 0 home/package-sets/default.nix | 5 +++++ home/{common.nix => profile/base.nix} | 0 home/profile/default.nix | 6 ++++++ home/{ => programs}/comma.nix | 0 home/programs/default.nix | 6 ++++++ home/sessions/default.nix | 6 ++++++ home/{ => sessions}/hyprland.nix | 0 9 files changed, 29 insertions(+) create mode 100644 home/common/default.nix rename home/{wm-common.nix => common/wm.nix} (100%) create mode 100644 home/package-sets/default.nix rename home/{common.nix => profile/base.nix} (100%) create mode 100644 home/profile/default.nix rename home/{ => programs}/comma.nix (100%) create mode 100644 home/programs/default.nix create mode 100644 home/sessions/default.nix rename home/{ => sessions}/hyprland.nix (100%) diff --git a/home/common/default.nix b/home/common/default.nix new file mode 100644 index 0000000..bcc2249 --- /dev/null +++ b/home/common/default.nix @@ -0,0 +1,6 @@ +{...}: +{ + imports = [ + ./wm.nix + ]; +} diff --git a/home/wm-common.nix b/home/common/wm.nix similarity index 100% rename from home/wm-common.nix rename to home/common/wm.nix diff --git a/home/package-sets/default.nix b/home/package-sets/default.nix new file mode 100644 index 0000000..cbe4b9e --- /dev/null +++ b/home/package-sets/default.nix @@ -0,0 +1,5 @@ +{...}: +{ + imports = [ + ]; +} diff --git a/home/common.nix b/home/profile/base.nix similarity index 100% rename from home/common.nix rename to home/profile/base.nix diff --git a/home/profile/default.nix b/home/profile/default.nix new file mode 100644 index 0000000..8d83827 --- /dev/null +++ b/home/profile/default.nix @@ -0,0 +1,6 @@ +{...}: +{ + imports = [ + ./base.nix + ]; +} diff --git a/home/comma.nix b/home/programs/comma.nix similarity index 100% rename from home/comma.nix rename to home/programs/comma.nix diff --git a/home/programs/default.nix b/home/programs/default.nix new file mode 100644 index 0000000..73afff3 --- /dev/null +++ b/home/programs/default.nix @@ -0,0 +1,6 @@ +{...}: +{ + imports = [ + ./comma.nix + ]; +} diff --git a/home/sessions/default.nix b/home/sessions/default.nix new file mode 100644 index 0000000..65c089d --- /dev/null +++ b/home/sessions/default.nix @@ -0,0 +1,6 @@ +{...}: +{ + imports = [ + ./hyprland.nix + ]; +} diff --git a/home/hyprland.nix b/home/sessions/hyprland.nix similarity index 100% rename from home/hyprland.nix rename to home/sessions/hyprland.nix From 4d35cc115432e9814600cf1870ff3bdc3a3ead96 Mon Sep 17 00:00:00 2001 From: NullBite Date: Fri, 9 Feb 2024 08:16:15 +0100 Subject: [PATCH 3/4] home: fix root.nix (this file should be elsewhere) --- home/root.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/home/root.nix b/home/root.nix index 266a894..aee753e 100644 --- a/home/root.nix +++ b/home/root.nix @@ -1,6 +1,12 @@ +# Configuration for root user. +# TODO this file is sorta an exception to my repo organization, it should +# probably be somewhere else. { config, lib, pkgs, ... }@args: { imports = [ - ./comma.nix + ./. ]; + config = { + nixfiles.programs.comma.enable = true; + }; } From b693ff3a005a4bc44f23e2eeac8b64e8a10504f5 Mon Sep 17 00:00:00 2001 From: NullBite Date: Fri, 9 Feb 2024 08:22:55 +0100 Subject: [PATCH 4/4] slab: switch home.nix to nixfiles options --- hosts/slab/home.nix | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hosts/slab/home.nix b/hosts/slab/home.nix index 3a5f535..0005a89 100644 --- a/hosts/slab/home.nix +++ b/hosts/slab/home.nix @@ -1,13 +1,17 @@ { lib, pkgs, osConfig, ... }: { imports = [ - ../../home/common.nix - ../../home/hyprland.nix + ../../home ]; - - home.stateVersion = "23.11"; - wayland.windowManager.hyprland.settings = { - monitor = ",preferred,auto,1.25"; + config = { + nixfiles = { + profile.base.enable = true; + }; + home.stateVersion = "23.11"; + + wayland.windowManager.hyprland.settings = { + monitor = ",preferred,auto,1.25"; + }; }; }