Merge pull request #12 from bwfiq/rebase/modularisation

refactor: modularise the configuration
This commit is contained in:
Mohammad Rafiq 2025-02-28 07:36:21 +08:00 committed by GitHub
commit 4c23743f43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 277 additions and 209 deletions

40
modules/common.nix Normal file
View file

@ -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;
}

7
modules/home-editor.nix Normal file
View file

@ -0,0 +1,7 @@
{self, pkgs, ...}:
{
home.packages = [
self.packages.${pkgs.stdenv.system}.nvf
];
}

15
modules/home-git.nix Normal file
View file

@ -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";
};
};
}

9
modules/home-sh.nix Normal file
View file

@ -0,0 +1,9 @@
{
programs.bash = {
enable = true;
shellAliases = {
rebuild = "sudo nixos-rebuild switch --flake";
gs = "git status";
};
};
}

View file

@ -0,0 +1,7 @@
{ pkgs, ... }:
{
home.packages = with pkgs; [
kitty # default terminal emulator for hyprland
];
}

9
modules/home-tmux.nix Normal file
View file

@ -0,0 +1,9 @@
{
programs.tmux = {
enable = true;
extraConfig = ''
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:RGB"
'';
};
}

23
modules/home-utils.nix Normal file
View file

@ -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 <command>)
tealdeer = {
enable = true;
enableAutoUpdates = true;
};
};
services = {
# clipboard history (depends on wl-clipboard)
cliphist.enable = true;
};
}

27
modules/home-wm.nix Normal file
View file

@ -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;
};
};
}

39
modules/networking.nix Normal file
View file

@ -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;
}

38
modules/nvidia.nix Normal file
View file

@ -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
];
}

32
modules/wm-hyprland.nix Normal file
View file

@ -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;
}

View file

@ -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. Its perfectly fine and recommended to leave

View file

@ -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"; }
];

View file

@ -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";
}