From 66485e77b9c8e8b3fa05ac5880a4f3f6cbd1f462 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Thu, 9 Jan 2025 08:08:30 -0800 Subject: [PATCH] feat(nixos): Fucking Hyprland --- flake.lock | 153 +++++++++++++++++++- flake.nix | 5 + homes/x86_64-linux/marley@nyx/default.nix | 16 +- modules/home/options/theme/default.nix | 37 +++-- modules/home/programs/git/default.nix | 24 +-- modules/home/programs/wezterm/default.nix | 31 ++-- modules/home/programs/wofi/default.nix | 17 +++ modules/home/wayland/hyprland/default.nix | 87 +++++++++++ modules/nixos/base/drivers/default.nix | 17 ++- modules/nixos/base/users/default.nix | 2 + modules/nixos/nvidia/default.nix | 32 ++++ modules/nixos/options/hasNvidia/default.nix | 9 ++ modules/nixos/services/ly/default.nix | 17 +++ modules/nixos/services/sddm/default.nix | 17 +++ modules/nixos/wayland/hyprland/default.nix | 18 +++ systems/x86_64-linux/nyx/autorandr.nix | 4 +- systems/x86_64-linux/nyx/default.nix | 9 +- 17 files changed, 439 insertions(+), 56 deletions(-) create mode 100644 modules/home/programs/wofi/default.nix create mode 100644 modules/home/wayland/hyprland/default.nix create mode 100644 modules/nixos/nvidia/default.nix create mode 100644 modules/nixos/options/hasNvidia/default.nix create mode 100644 modules/nixos/services/ly/default.nix create mode 100644 modules/nixos/services/sddm/default.nix create mode 100644 modules/nixos/wayland/hyprland/default.nix diff --git a/flake.lock b/flake.lock index abe98eb..517e02c 100644 --- a/flake.lock +++ b/flake.lock @@ -267,6 +267,24 @@ "type": "github" } }, + "flake-utils_5": { + "inputs": { + "systems": "systems_4" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "flakey-profile": { "locked": { "lastModified": 1712898590, @@ -282,6 +300,23 @@ "type": "github" } }, + "freetype2": { + "flake": false, + "locked": { + "lastModified": 1723459814, + "narHash": "sha256-4l90lDtpgm5xlh2m7ifrqNy373DTRTULRkAzicrM93c=", + "owner": "freetype", + "repo": "freetype", + "rev": "42608f77f20749dd6ddc9e0536788eaad70ea4b5", + "type": "github" + }, + "original": { + "owner": "freetype", + "ref": "VER-2-13-3", + "repo": "freetype", + "type": "github" + } + }, "gen-luarc": { "inputs": { "flake-parts": "flake-parts", @@ -398,6 +433,23 @@ "type": "github" } }, + "harfbuzz": { + "flake": false, + "locked": { + "lastModified": 1719502711, + "narHash": "sha256-2ieCf3ftNk851FZBDPVl+7QHWBqD729KiUxUyxi26Yg=", + "owner": "harfbuzz", + "repo": "harfbuzz", + "rev": "9c03576c49db6e7207d9bcdfe3abd170a809157f", + "type": "github" + }, + "original": { + "owner": "harfbuzz", + "ref": "9.0.0", + "repo": "harfbuzz", + "type": "github" + } + }, "hercules-ci-effects": { "inputs": { "flake-parts": "flake-parts_3", @@ -441,6 +493,23 @@ "type": "github" } }, + "libpng": { + "flake": false, + "locked": { + "lastModified": 1726173884, + "narHash": "sha256-gBfHgGaqVYdmhWXoNKZzPyGzyw2rr3zp+DjWmfC41jk=", + "owner": "pnggroup", + "repo": "libpng", + "rev": "f5e92d76973a7a53f517579bc95d61483bf108c0", + "type": "github" + }, + "original": { + "owner": "pnggroup", + "ref": "v1.6.44", + "repo": "libpng", + "type": "github" + } + }, "lix": { "inputs": { "flake-utils": "flake-utils", @@ -769,7 +838,8 @@ "rose-pine-amfora": "rose-pine-amfora", "rose-pine-qt5ct": "rose-pine-qt5ct", "snowfall-lib": "snowfall-lib", - "unstable": "unstable" + "unstable": "unstable", + "wezterm": "wezterm" } }, "rose-pine": { @@ -819,6 +889,27 @@ "type": "github" } }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "wezterm", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1735871325, + "narHash": "sha256-6Ta5E4mhSfCP6LdkzkG2+BciLOCPeLKuYTJ6lOHW+mI=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a599f011db521766cbaf7c2f5874182485554f00", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, "snowfall-lib": { "inputs": { "flake-compat": "flake-compat_4", @@ -886,6 +977,21 @@ "type": "github" } }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { "inputs": { "nixpkgs": [ @@ -945,6 +1051,51 @@ "repo": "nixpkgs", "type": "github" } + }, + "wezterm": { + "inputs": { + "flake-utils": "flake-utils_5", + "freetype2": "freetype2", + "harfbuzz": "harfbuzz", + "libpng": "libpng", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay", + "zlib": "zlib" + }, + "locked": { + "dir": "nix", + "lastModified": 1735931735, + "narHash": "sha256-4wzEN5IPYmqLP8TAdFatoRhCZ7W9y65AWoYN0Qgvbg8=", + "owner": "wez", + "repo": "wezterm", + "rev": "8e9cf912e66f704f300fac6107206a75036de1e7", + "type": "github" + }, + "original": { + "dir": "nix", + "owner": "wez", + "repo": "wezterm", + "type": "github" + } + }, + "zlib": { + "flake": false, + "locked": { + "lastModified": 1705948357, + "narHash": "sha256-TkPLWSN5QcPlL9D0kc/yhH0/puE9bFND24aj5NVDKYs=", + "owner": "madler", + "repo": "zlib", + "rev": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf", + "type": "github" + }, + "original": { + "owner": "madler", + "ref": "v1.3.1", + "repo": "zlib", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index c7ce423..b512eab 100644 --- a/flake.nix +++ b/flake.nix @@ -73,6 +73,11 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + wezterm = { + url = "github:wez/wezterm?dir=nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + # Rose pine themes that aren't included in the above flake: # TODO: Integrate these to punkfairie/rose-pine-nix. rose-pine-amfora = { diff --git a/homes/x86_64-linux/marley@nyx/default.nix b/homes/x86_64-linux/marley@nyx/default.nix index f571272..3416da1 100644 --- a/homes/x86_64-linux/marley@nyx/default.nix +++ b/homes/x86_64-linux/marley@nyx/default.nix @@ -50,14 +50,16 @@ in { zoxide = enabled; }; services = { - clipboard = enabled; - # kanata = enabled; - syncthing = enabled; + # clipboard = enabled; + # syncthing = enabled; + }; + wayland.hyprland = { + enable = true; + monitors = [ + "desc:Apple Computer Inc LED Cinema 2A91946Z0K0, 1920x1200, 0x0, 1" + "desc:Lenovo Group Limited LT2252p Wide 6V8ACF74, 1680x1050, 1920x0, 1" + ]; }; - #xorg = { - # xsession = enabled; - # i3 = enabled; - #}; }; home.stateVersion = "24.05"; diff --git a/modules/home/options/theme/default.nix b/modules/home/options/theme/default.nix index ef9a031..71b43fa 100644 --- a/modules/home/options/theme/default.nix +++ b/modules/home/options/theme/default.nix @@ -4,9 +4,9 @@ pkgs, system, ... -}: -let - inherit (lib) +}: let + inherit + (lib) types mkOption literalMD @@ -51,16 +51,14 @@ let }; }; - mkColorThemeOpt = - mode: flavor: - (mkOption { - type = with types; either str colorThemeType; - default = { - base = "rose-pine"; - inherit flavor; - }; - description = "The color theme to use in ${mode} mode."; - }); + mkColorThemeOpt = mode: flavor: (mkOption { + type = with types; either str colorThemeType; + default = { + base = "rose-pine"; + inherit flavor; + }; + description = "The color theme to use in ${mode} mode."; + }); # https://github.com/nix-community/home-manager/blob/master/modules/misc/gtk.nix iconThemeType = types.submodule { @@ -83,8 +81,7 @@ let }; }; }; -in -{ +in { options.marleyos.theme = { colors = { default = mkOption { @@ -122,6 +119,15 @@ in default = pkgs.pinentry-gtk2; description = "The pinentry package to use."; }; + + clipboard = mkOption { + type = with types; package; + default = + if config.marleyos.wayland.hyprland.enable + then pkgs.wl-clipboard + else pkgs.clipboard-jh; + description = "The clipboard manager to use."; + }; }; config = mkMerge [ @@ -158,6 +164,7 @@ in (mkIf (is-linux system) { home.packages = [ cfg.pinentry + cfg.clipboard ]; programs.rbw = mkDefault { diff --git a/modules/home/programs/git/default.nix b/modules/home/programs/git/default.nix index 2374c22..3059cf3 100644 --- a/modules/home/programs/git/default.nix +++ b/modules/home/programs/git/default.nix @@ -3,13 +3,11 @@ config, pkgs, ... -}: -let +}: let inherit (lib) mkEnableOption mkIf; cfg = config.marleyos.programs.git; -in -{ +in { options.marleyos.programs.git.enable = mkEnableOption "git"; imports = [ @@ -19,7 +17,7 @@ in config = mkIf cfg.enable { home.packages = with pkgs; [ gum - clipboard-jh + config.marleyos.theme.clipboard ]; # ██████╗ ██╗████████╗ @@ -193,7 +191,8 @@ in }; programs.fish.functions = { - git_develop_branch = # fish + git_develop_branch = + # fish '' command git rev-parse --git-dir &>/dev/null || return set -l branch @@ -209,7 +208,8 @@ in return 1 ''; - git_main_branch = # fish + git_main_branch = + # fish '' command git rev-parse --git-dir &>/dev/null || return set -l ref @@ -226,7 +226,8 @@ in return 1 ''; - git_current_branch = # fish + git_current_branch = + # fish '' set -l ref (git symbolic-ref --quiet HEAD 2>/dev/null) set -l ret $status @@ -239,7 +240,8 @@ in echo (string replace "refs/heads/" "" $ref) ''; - git_open = # fish + git_open = + # fish '' set -f origin "$(git remote get-url origin)" @@ -264,18 +266,15 @@ in }; }; } - # ███╗ ██╗ ██████╗ ████████╗███████╗███████╗ # ████╗ ██║██╔═══██╗╚══██╔══╝██╔════╝██╔════╝ # ██╔██╗ ██║██║ ██║ ██║ █████╗ ███████╗ # ██║╚██╗██║██║ ██║ ██║ ██╔══╝ ╚════██║ # ██║ ╚████║╚██████╔╝ ██║ ███████╗███████║ # ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚══════╝╚══════╝ - # PATH VALUES: # :/ - all files within the root of the working tree, so all files in the # repo, a la git add's --all option. - # A note on reset, restore, and revert, paraphrased from `man git`, plus my # own on `rm`: # @@ -287,3 +286,4 @@ in # # These are not a description of the *possible* uses, rather a narrowing of # the *intended* uses. + diff --git a/modules/home/programs/wezterm/default.nix b/modules/home/programs/wezterm/default.nix index deb6e02..392f8a2 100644 --- a/modules/home/programs/wezterm/default.nix +++ b/modules/home/programs/wezterm/default.nix @@ -3,9 +3,9 @@ config, system, pkgs, + inputs, ... -}: -let +}: let inherit (lib) mkEnableOption mkIf; inherit (lib.snowfall.system) is-darwin; @@ -14,8 +14,7 @@ let isGenericLinux = config.targets.genericLinux.enable; isNotNixOS = isGenericLinux || (is-darwin system); -in -{ +in { options.marleyos.programs.wezterm.enable = mkEnableOption "wezterm"; config = mkIf cfg.enable { @@ -24,19 +23,25 @@ in # Generic linux: NixGL makes Wezterm shit the bed for some reason. # macOS: Prefer brew cask so a proper Applications shortcut is made. - package = mkIf isNotNixOS pkgs.emptyDirectory; + package = + if isNotNixOS + then pkgs.emptyDirectory + # TODO: make this an overlay. + else inputs.wezterm.packages."${pkgs.system}".default; # TODO: create `local config` & return it seperately, so other modules can # insert config in the middle - extraConfig = - let - # TODO: Set this in marleyos.theme - fonts = config.fonts.fontconfig.defaultFonts.monospace; - in + extraConfig = let + # TODO: Set this in marleyos.theme + fonts = config.fonts.fontconfig.defaultFonts.monospace; + in # lua '' local config = wezterm.config_builder() + -- Fix color blocks instead of text issue. + config.front_end = "WebGpu" + config.enable_tab_bar = false config.color_scheme = "${colors.base}" @@ -79,7 +84,11 @@ in }) -- TODO: on mairley this should be set to 14.0 - config.font_size = ${if (is-darwin system) then "14.0" else "11.0"} + config.font_size = ${ + if (is-darwin system) + then "14.0" + else "11.0" + } return config ''; diff --git a/modules/home/programs/wofi/default.nix b/modules/home/programs/wofi/default.nix new file mode 100644 index 0000000..94865d7 --- /dev/null +++ b/modules/home/programs/wofi/default.nix @@ -0,0 +1,17 @@ +{ + lib, + config, + ... +}: let + inherit (lib) mkEnableOption mkIf; + + cfg = config.marleyos.programs.wofi; +in { + options.marleyos.programs.wofi.enable = mkEnableOption "wofi"; + + config = mkIf cfg.enable { + programs.wofi = { + enable = true; + }; + }; +} diff --git a/modules/home/wayland/hyprland/default.nix b/modules/home/wayland/hyprland/default.nix new file mode 100644 index 0000000..1f310d6 --- /dev/null +++ b/modules/home/wayland/hyprland/default.nix @@ -0,0 +1,87 @@ +{ + lib, + config, + inputs, + system, + ... +}: let + inherit (lib) mkEnableOption mkOption mkIf getExe; + + cfg = config.marleyos.wayland.hyprland; +in { + options.marleyos.wayland.hyprland = { + enable = mkEnableOption "hyprland"; + + monitors = mkOption { + description = "Monitor configuration."; + type = with lib.types; listOf str; + default = []; + }; + }; + + config = mkIf cfg.enable { + marleyos.programs.wofi.enable = true; + + wayland.windowManager.hyprland = { + enable = true; + + systemd.enable = true; + xwayland.enable = true; + + settings = { + monitor = cfg.monitors; + + # TODO: Use overlay once it's made. + "$terminal" = getExe inputs.wezterm.packages."${system}".default; + "$launcher" = "wofi --show drun"; + + "$mod" = "SUPER"; + + bind = [ + "$mod, Q, killactive," + "$mod SHIFT, E, exit," + + "$mod SHIFT, SPACE, togglefloating" + + "$mod, RETURN, exec, $terminal" + "$mod, R, exec, $launcher" + + "$mod, h, movefocus, l" + "$mod, j, movefocus, d" + "$mod, k, movefocus, u" + "$mod, l, movefocus, r" + + "$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" + + "$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" + ]; + + # bindm = [ + # "$mod, mouse_down, workspace, e+1" + # "$mod, mouse_up, workspace, e-1" + # + # "$mod, mouse:272, movewindow" + # "$mod, mouse:273, resizewindow" + # ]; + }; + }; + }; +} diff --git a/modules/nixos/base/drivers/default.nix b/modules/nixos/base/drivers/default.nix index c7ecba2..8135b81 100644 --- a/modules/nixos/base/drivers/default.nix +++ b/modules/nixos/base/drivers/default.nix @@ -1,12 +1,15 @@ _: { - hardware.pulseaudio.enable = false; security.rtkit.enable = true; # Used for pulseaudio. - services.pipewire = { - enable = true; - alsa.enable = true; - pulse.enable = true; - }; + services = { + pulseaudio.enable = false; - services.printing.enable = true; + pipewire = { + enable = true; + alsa.enable = true; + pulse.enable = true; + }; + + printing.enable = true; + }; } diff --git a/modules/nixos/base/users/default.nix b/modules/nixos/base/users/default.nix index acf3a6a..645115d 100644 --- a/modules/nixos/base/users/default.nix +++ b/modules/nixos/base/users/default.nix @@ -20,4 +20,6 @@ in { hashedPassword = "$y$j9T$ztWf9WeUCENC2T12qS4mi1$51ihV/5cQ8mdJJrNe7MMguk4hPB61S5xHawsfi.1hL3"; }; }; + + home-manager.backupFileExtension = "bak"; } diff --git a/modules/nixos/nvidia/default.nix b/modules/nixos/nvidia/default.nix new file mode 100644 index 0000000..c337022 --- /dev/null +++ b/modules/nixos/nvidia/default.nix @@ -0,0 +1,32 @@ +{ + lib, + config, + ... +}: let + inherit (lib) mkEnableOption mkIf mkForce; + + cfg = config.marleyos.nvidia; +in { + options.marleyos.nvidia.enable = mkEnableOption "nvidia"; + + config = mkIf cfg.enable { + # NVIDIA drivers are unfree. + nixpkgs.config.allowUnfree = mkForce true; + + # Load drivers for Xorg and Wayland. + services.xserver.videoDrivers = ["nvidia"]; + + hardware = { + # openGL. + graphics.enable = true; + + nvidia = { + modesetting.enable = true; + nvidiaSettings = true; + + # Disable open-source drivers. + open = false; + }; + }; + }; +} diff --git a/modules/nixos/options/hasNvidia/default.nix b/modules/nixos/options/hasNvidia/default.nix new file mode 100644 index 0000000..88e0b92 --- /dev/null +++ b/modules/nixos/options/hasNvidia/default.nix @@ -0,0 +1,9 @@ +{lib, ...}: let + inherit (lib) mkOption types; +in { + options.marleyos.hasNvidia = mkOption { + type = with types; bool; + default = false; + description = "Whether this machine has an NVIDIA GPU."; + }; +} diff --git a/modules/nixos/services/ly/default.nix b/modules/nixos/services/ly/default.nix new file mode 100644 index 0000000..106a8f7 --- /dev/null +++ b/modules/nixos/services/ly/default.nix @@ -0,0 +1,17 @@ +{ + lib, + config, + ... +}: let + inherit (lib) mkEnableOption mkIf; + + cfg = config.marleyos.services.ly; +in { + options.marleyos.services.ly.enable = mkEnableOption "ly"; + + config = mkIf cfg.enable { + services.displayManager.ly = { + enable = true; + }; + }; +} diff --git a/modules/nixos/services/sddm/default.nix b/modules/nixos/services/sddm/default.nix new file mode 100644 index 0000000..97846a5 --- /dev/null +++ b/modules/nixos/services/sddm/default.nix @@ -0,0 +1,17 @@ +{ + lib, + config, + ... +}: let + inherit (lib) mkEnableOption mkIf; + + cfg = config.marleyos.services.sddm; +in { + options.marleyos.services.sddm.enable = mkEnableOption "sddm"; + + config = mkIf cfg.enable { + services.displayManager.sddm = { + enable = true; + }; + }; +} diff --git a/modules/nixos/wayland/hyprland/default.nix b/modules/nixos/wayland/hyprland/default.nix new file mode 100644 index 0000000..d242ad7 --- /dev/null +++ b/modules/nixos/wayland/hyprland/default.nix @@ -0,0 +1,18 @@ +{ + lib, + config, + ... +}: let + inherit (lib) mkEnableOption mkIf; + + cfg = config.marleyos.wayland.hyprland; +in { + options.marleyos.wayland.hyprland.enable = mkEnableOption "hyprland"; + + config = mkIf cfg.enable { + programs.hyprland = { + enable = true; + withUWSM = false; + }; + }; +} diff --git a/systems/x86_64-linux/nyx/autorandr.nix b/systems/x86_64-linux/nyx/autorandr.nix index 0e80c40..c9b965b 100644 --- a/systems/x86_64-linux/nyx/autorandr.nix +++ b/systems/x86_64-linux/nyx/autorandr.nix @@ -9,7 +9,7 @@ _: { "HDMI-0" = "00ffffffffffff0030ae0c0a010101011d160103802f1e78ee23c5a5574f9e260f5054bdcf00714f8180818c9500950fa9c0b300010126399030621a274068b03600da281100001c000000fd00324b1e5311000a202020202020000000fc004c54323235327020576964650a000000ff0036563841434637340a2020202000f8"; }; config = { - "DP-0" = { + "DP-1" = { enable = true; crtc = 0; primary = true; @@ -17,7 +17,7 @@ _: { position = "0x0"; rate = "59.95"; }; - "HDMI-0" = { + "HDMI-A-1" = { enable = true; crtc = 1; mode = "1680x1050"; diff --git a/systems/x86_64-linux/nyx/default.nix b/systems/x86_64-linux/nyx/default.nix index aa50c35..e0aabf2 100644 --- a/systems/x86_64-linux/nyx/default.nix +++ b/systems/x86_64-linux/nyx/default.nix @@ -16,7 +16,6 @@ in { xserver = { enable = true; - displayManager.lightdm.enable = true; desktopManager.deepin.enable = true; xkb = { @@ -31,7 +30,15 @@ in { environment.systemPackages = [pkgs.vim pkgs.git]; marleyos = { + hasNvidia = true; + mounts.babeshare = enabled; + + wayland.hyprland = enabled; + + services = { + ly = enabled; + }; }; system.stateVersion = "24.05";