diff --git a/modules/common.nix b/modules/common.nix new file mode 100644 index 0000000..4e50b5b --- /dev/null +++ b/modules/common.nix @@ -0,0 +1,40 @@ +# Contains common configration for all machines + +{ + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + # Set your time zone. + time.timeZone = "Asia/Singapore"; + + # Select internationalisation properties. + i18n.defaultLocale = "en_SG.UTF-8"; + + i18n.extraLocaleSettings = { + LC_ADDRESS = "en_SG.UTF-8"; + LC_IDENTIFICATION = "en_SG.UTF-8"; + LC_MEASUREMENT = "en_SG.UTF-8"; + LC_MONETARY = "en_SG.UTF-8"; + LC_NAME = "en_SG.UTF-8"; + LC_NUMERIC = "en_SG.UTF-8"; + LC_PAPER = "en_SG.UTF-8"; + LC_TELEPHONE = "en_SG.UTF-8"; + LC_TIME = "en_SG.UTF-8"; + }; + + # Configure keymap in X11 + services.xserver.xkb = { + layout = "us"; + variant = ""; + }; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.rafiq = { + isNormalUser = true; + description = "rafiq"; + extraGroups = [ "networkmanager" "wheel" ]; + }; + + # Allow unfree packages + nixpkgs.config.allowUnfree = true; +} diff --git a/modules/home-editor.nix b/modules/home-editor.nix new file mode 100644 index 0000000..704ba95 --- /dev/null +++ b/modules/home-editor.nix @@ -0,0 +1,7 @@ +{self, pkgs, ...}: + +{ + home.packages = [ + self.packages.${pkgs.stdenv.system}.nvf + ]; +} diff --git a/modules/home-git.nix b/modules/home-git.nix new file mode 100644 index 0000000..73030c7 --- /dev/null +++ b/modules/home-git.nix @@ -0,0 +1,15 @@ +{ + home.sessionVariables.GIT_CONFIG_GLOBAL = "$HOME/.config/git/config"; + + programs.git = { + enable = true; + userName = "Mohammad Rafiq"; + userEmail = "mohammadrafiq567@gmail.com"; + extraConfig = { + init.defaultBranch = "prime"; + push.autoSetupRemote = true; + pull.rebase = false; + core.editor = "nvim"; + }; + }; +} diff --git a/modules/home-sh.nix b/modules/home-sh.nix new file mode 100644 index 0000000..d656add --- /dev/null +++ b/modules/home-sh.nix @@ -0,0 +1,9 @@ +{ + programs.bash = { + enable = true; + shellAliases = { + rebuild = "sudo nixos-rebuild switch --flake"; + gs = "git status"; + }; + }; +} diff --git a/modules/home-terminal.nix b/modules/home-terminal.nix new file mode 100644 index 0000000..5096fe4 --- /dev/null +++ b/modules/home-terminal.nix @@ -0,0 +1,7 @@ +{ pkgs, ... }: + +{ + home.packages = with pkgs; [ + kitty # default terminal emulator for hyprland + ]; +} diff --git a/modules/home-tmux.nix b/modules/home-tmux.nix new file mode 100644 index 0000000..e37c8ba --- /dev/null +++ b/modules/home-tmux.nix @@ -0,0 +1,9 @@ +{ + programs.tmux = { + enable = true; + extraConfig = '' + set -g default-terminal "tmux-256color" + set -ag terminal-overrides ",xterm-256color:RGB" + ''; + }; +} diff --git a/modules/home-utils.nix b/modules/home-utils.nix new file mode 100644 index 0000000..b85dfc3 --- /dev/null +++ b/modules/home-utils.nix @@ -0,0 +1,23 @@ +{ pkgs, ... }: + +{ + # TODO: Move wayland-specific stuff to a wayland config + + home.packages = with pkgs; [ + fastfetch # system info + wl-clipboard # provides cli copy and paste commands + ]; + + programs = { + # man page summaries (activate with tldr ) + tealdeer = { + enable = true; + enableAutoUpdates = true; + }; + }; + + services = { + # clipboard history (depends on wl-clipboard) + cliphist.enable = true; + }; +} diff --git a/modules/home-wm.nix b/modules/home-wm.nix new file mode 100644 index 0000000..edd4b4b --- /dev/null +++ b/modules/home-wm.nix @@ -0,0 +1,27 @@ +{ + wayland.windowManager.hyprland = { + enable = true; + systemd.enable = false; # Required for UWSM compat + systemd.variables = ["--all"]; + # Use tha packages defined in the system configuration + package = null; + portalPackage = null; + settings = { + monitor = [ + "HDMI-A-2, 3840x2160@60, 0x0, 2" + "DP-4, 1920x1080@60, -1920x0, 1" + ", preferred, auto, 1" + ]; + "$terminal" = "kitty"; + "$browser" = "firefox"; + "$mainMod" = "SUPER"; + bind = [ + "$mainMod, Q, exec, uwsm app -- $terminal" + "$mainMod, W, killactive" + "$mainMod, E, exec, uwsm app -- $browser" + "$mainMod, M, exec, uwsm stop" + ]; + debug.disable_logs = false; + }; + }; +} diff --git a/modules/networking.nix b/modules/networking.nix new file mode 100644 index 0000000..0340a3d --- /dev/null +++ b/modules/networking.nix @@ -0,0 +1,39 @@ +# +# Common networking settings for all machines. +# Anything system-specific should not be here. +# +{ + networking = { + # Enable networkManager + # TODO: Look into the networkManager options. + networkmanager.enable = true; + + # Configures a simple stateful firewall. + # By default, it doesn't allow any incoming connections. + firewall = { + enable = true; + allowedTCPPorts = [ + 22 # SSH + ]; + allowedUDPPorts = []; + }; + }; + + # Add binary caches to avoid having to compile them + nix.settings = { + substituters = [ + "https://hyprland.cachix.org" + "https://cuda-maintainers.cachix.org" + "https://nix-community.cachix.org" + ]; + trusted-public-keys = [ + "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" + "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + ]; + }; + + # TODO: look into openssh and tailscale settings. + services.openssh.enable = true; + services.tailscale.enable = true; +} diff --git a/modules/nvidia.nix b/modules/nvidia.nix new file mode 100644 index 0000000..cc8e619 --- /dev/null +++ b/modules/nvidia.nix @@ -0,0 +1,38 @@ +{ pkgs, config, inputs, ... }: +let + hyprland-pkgs = inputs.hyprland.inputs.nixpkgs.legacyPackages.${pkgs.stdenv.hostPlatform.system}; +in +{ + hardware = { + graphics = { + enable = true; + package = hyprland-pkgs.mesa.drivers; + extraPackages = with pkgs; [ + nvidia-vaapi-driver + ocl-icd + cudaPackages.cudatoolkit + ]; + }; + nvidia = { + open = true; + package = config.boot.kernelPackages.nvidiaPackages.latest; + }; + }; + + services.xserver = { + enable = true; + videoDrivers = [ "nvidia" ]; + }; + + environment.variables = { + NIXOS_OZONE_WL = "1"; # Hint to electron apps to use Wayland + LIBVA_DRIVER_NAME = "nvidia"; + __GLX_VENDOR_LIBRARY_NAME = "nvidia"; + NVD_BACKEND = "direct"; # Set VAAPI driver backend + }; + + environment.systemPackages = with pkgs; [ + clinfo + pciutils + ]; +} diff --git a/modules/wm-hyprland.nix b/modules/wm-hyprland.nix new file mode 100644 index 0000000..a6f864b --- /dev/null +++ b/modules/wm-hyprland.nix @@ -0,0 +1,32 @@ +{ inputs, pkgs, ... }: + +{ + # Define the Universal Wayland Session Manager. + # This will start our compositor. + # TODO: Eventually move this to a common desktop module. + programs.uwsm = { + enable = true; + waylandCompositors.hyprland = { + prettyName = "Hyprland"; + comment = "Hyprland compositor managed by UWSM"; + binPath = "/run/current-system/sw/bin/Hyprland"; + }; + }; + + programs.hyprland = { + enable = true; + # Use the packages that we have defined as inputs in our flake. + package = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland; + portalPackage = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.xdg-desktop-portal-hyprland; + # Enable sustemd integration + systemd.setPath.enable = true; + withUWSM = true; + # Enable compatibility with X11 apps + xwayland.enable = true; + }; + + services.hypridle.enable = true; + + # Run a script that launches Hyprland through UWSM on login. + services.hyprland-tty-launch.enable = true; +} diff --git a/systems/nemesis/default.nix b/systems/nemesis/default.nix index 770c115..ca04b62 100644 --- a/systems/nemesis/default.nix +++ b/systems/nemesis/default.nix @@ -2,156 +2,35 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ inputs, config, pkgs, ... }: let - hyprland-pkgs = inputs.hyprland.inputs.nixpkgs.legacyPackages.${pkgs.stdenv.hostPlatform.system}; -in { +{ pkgs, ... }: + +{ imports = [ # Include the results of the hardware scan. + ../../modules/common.nix ./hardware-configuration.nix ../../scripts/hyprland-tty-launch.nix + ../../modules/nvidia.nix # Graphics settings for Nvidia GPUs + ../../modules/networking.nix # Common networking config + ../../modules/wm-hyprland.nix # Enable the hyprland wm ]; - # Bootloader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; + networking.hostName = "nemesis"; - # Graphics settings are defined here - hardware = { - graphics.enable = true; - graphics.package = hyprland-pkgs.mesa.drivers; - graphics.extraPackages = with pkgs; [ - nvidia-vaapi-driver - ocl-icd - cudaPackages.cudatoolkit - # clinfo - ]; - nvidia = { - open = true; - package = config.boot.kernelPackages.nvidiaPackages.stable; + # Allow nemesis to access files on the windows drive. + fileSystems."/mnt/windows" = + { device = "/dev/nvme0n1p3"; + fsType = "ntfs-3g"; + options = [ "rw" "uid=rafiq" ]; }; - }; - environment.variables.NIXOS_OZONE_WL = "1"; # Hint to electron apps to use Wayland - environment.variables.LIBVA_DRIVER_NAME = "nvidia"; - environment.variables.__GLX_VENDOR_LIBRARY_NAME = "nvidia"; - environment.variables.NVD_BACKEND = "direct"; # Set VAAPI driver backend - - services.xserver = { - enable = true; - videoDrivers = [ "nvidia" ]; - }; - - # Add hyprland.cachix.org as a binary cache for Hyprland - nix.settings = { - substituters = [ - "https://hyprland.cachix.org" - "https://cuda-maintainers.cachix.org" - "https://nix-community.cachix.org" - ]; - trusted-public-keys = [ - "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" - "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - ]; - }; - - # Scripts - services.hyprland-tty-launch.enable = true; - - networking.hostName = "nemesis"; # Define your hostname. - # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. - - # Configure network proxy if necessary - # networking.proxy.default = "http://user:password@proxy:port/"; - # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; - - # Enable networking - networking.networkmanager.enable = true; - - # Set your time zone. - time.timeZone = "Asia/Singapore"; - - # Select internationalisation properties. - i18n.defaultLocale = "en_SG.UTF-8"; - - i18n.extraLocaleSettings = { - LC_ADDRESS = "en_SG.UTF-8"; - LC_IDENTIFICATION = "en_SG.UTF-8"; - LC_MEASUREMENT = "en_SG.UTF-8"; - LC_MONETARY = "en_SG.UTF-8"; - LC_NAME = "en_SG.UTF-8"; - LC_NUMERIC = "en_SG.UTF-8"; - LC_PAPER = "en_SG.UTF-8"; - LC_TELEPHONE = "en_SG.UTF-8"; - LC_TIME = "en_SG.UTF-8"; - }; - - # Configure keymap in X11 - services.xserver.xkb = { - layout = "us"; - variant = ""; - }; - - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.rafiq = { - isNormalUser = true; - description = "rafiq"; - extraGroups = [ "networkmanager" "wheel" ]; - }; - - # Allow unfree packages - nixpkgs.config.allowUnfree = true; # List packages installed in system profile. To search, run: # $ nix search wget environment.systemPackages = with pkgs; [ firefox - clinfo koboldcpp ]; - # Some programs need SUID wrappers, can be configured further or are - # started in user sessions. - # programs.mtr.enable = true; - # programs.gnupg.agent = { - # enable = true; - # enableSSHSupport = true; - # }; - - # List services that you want to enable: - - # Enable the OpenSSH daemon. - services.openssh.enable = true; - services.tailscale.enable = true; - - programs.uwsm = { - enable = true; - waylandCompositors.hyprland = { - prettyName = "Hyprland"; - comment = "Hyprland compositor managed by UWSM"; - binPath = "/run/current-system/sw/bin/Hyprland"; - }; - }; - - programs.hyprland = { - enable = true; - # Use the packages that we have defined as inputs in our flake. - package = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland; - portalPackage = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.xdg-desktop-portal-hyprland; - # Enable sustemd integration - systemd.setPath.enable = true; - withUWSM = true; - # Enable compatibility with X11 apps - xwayland.enable = true; - }; - - services.hypridle.enable = true; - - # Open ports in the firewall. - # networking.firewall.allowedTCPPorts = [ ... ]; - # networking.firewall.allowedUDPPorts = [ ... ]; - # Or disable the firewall altogether. - networking.firewall.enable = false; - # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions # on your system were taken. It‘s perfectly fine and recommended to leave diff --git a/systems/nemesis/hardware-configuration.nix b/systems/nemesis/hardware-configuration.nix index be3f647..de72be3 100644 --- a/systems/nemesis/hardware-configuration.nix +++ b/systems/nemesis/hardware-configuration.nix @@ -25,12 +25,6 @@ options = [ "fmask=0077" "dmask=0077" ]; }; - fileSystems."/mnt/windows" = - { device = "/dev/nvme0n1p3"; - fsType = "ntfs-3g"; - options = [ "rw" "uid=rafiq" ]; - }; - swapDevices = [ { device = "/dev/disk/by-uuid/1fb29964-4a65-4cf4-9b45-9534d35845bc"; } ]; diff --git a/users/rafiq/default.nix b/users/rafiq/default.nix index 0870897..9eb22c6 100644 --- a/users/rafiq/default.nix +++ b/users/rafiq/default.nix @@ -1,77 +1,26 @@ -{ self, config, pkgs, inputs, ... }: +{ self, pkgs, ... }: { + imports = [ + ../../modules/home-git.nix # git specific configs + ../../modules/home-tmux.nix # tmux specific configs (might move this) + ../../modules/home-sh.nix # bash and other shell specific configs + ../../modules/home-wm.nix # window manager configs + ../../modules/home-editor.nix # editor specific configs + ../../modules/home-terminal.nix # terminal emulator configs + ../../modules/home-utils.nix # miscellaneous utilities + ]; + + # This enables using home-manager from the command line. + programs.home-manager.enable = true; + home = { username = "rafiq"; homeDirectory = "/home/rafiq"; - packages = [ - self.packages.${pkgs.stdenv.system}.nvf - pkgs.kitty - pkgs.fastfetch - pkgs.wl-clipboard - ]; - sessionVariables = { - GIT_CONFIG_GLOBAL = "$HOME/.config/git/config"; - }; + # This defines the version home-manager + # was originally bulit against on this system. + # Do not change it. + stateVersion = "25.05"; }; - - programs = { - git = { - enable = true; - userName = "Mohammad Rafiq"; - userEmail = "mohammadrafiq567@gmail.com"; - extraConfig = { - init.defaultBranch = "prime"; - push.autoSetupRemote = true; - pull.rebase = false; - }; - }; - - tealdeer = { - enable = true; - enableAutoUpdates = true; - }; - - tmux = { - enable = true; - extraConfig = '' - set -g default-terminal "tmux-256color" - set -ag terminal-overrides ",xterm-256color:RGB" - ''; - }; - home-manager.enable = true; - }; - - wayland.windowManager.hyprland = { - enable = true; - systemd.enable = false; # Required for UWSM compat - systemd.variables = ["--all"]; - # Use tha packages defined in the system configuration - package = null; - portalPackage = null; - settings = { - monitor = [ - "HDMI-A-2, 3840x2160@60, 0x0, 2" - "DP-4, 1920x1080@60, -1920x0, 1" - ", preferred, auto, 1" - ]; - "$terminal" = "kitty"; - "$browser" = "firefox"; - "$mainMod" = "SUPER"; - bind = [ - "$mainMod, Q, exec, uwsm app -- $terminal" - "$mainMod, W, killactive" - "$mainMod, E, exec, uwsm app -- $browser" - "$mainMod, M, exec, uwsm stop" - ]; - debug.disable_logs = false; - }; - }; - - services = { - cliphist.enable = true; - }; - - home.stateVersion = "25.05"; }