From 19895355358f01dd30215563241cb1378e471ee6 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Thu, 27 Mar 2025 03:04:21 +0800 Subject: [PATCH] refactor: move system modules into proper directories --- systems/default.nix | 73 ++----------------- systems/modules/boot.nix | 18 +++++ systems/modules/bootloaders/extlinux.nix | 6 -- systems/modules/hardware/nvidia.nix | 21 ++++-- systems/modules/{hardware => }/networking.nix | 0 systems/modules/nix.nix | 28 +++++++ systems/modules/programs/tailscale.nix | 2 - systems/modules/security/sops.nix | 8 -- systems/modules/users.nix | 13 +++- systems/modules/users/rafiq.nix | 16 ---- 10 files changed, 80 insertions(+), 105 deletions(-) create mode 100644 systems/modules/boot.nix delete mode 100644 systems/modules/bootloaders/extlinux.nix rename systems/modules/{hardware => }/networking.nix (100%) create mode 100644 systems/modules/nix.nix delete mode 100644 systems/modules/programs/tailscale.nix delete mode 100644 systems/modules/security/sops.nix delete mode 100644 systems/modules/users/rafiq.nix diff --git a/systems/default.nix b/systems/default.nix index c61acfe..70cb483 100644 --- a/systems/default.nix +++ b/systems/default.nix @@ -1,13 +1,8 @@ { lib, hostname, - pkgs, type, modulesPath, - inputs, - config, - specialArgs, - username, ... }: { @@ -15,13 +10,14 @@ # Common options for all machines. [ (modulesPath + "/installer/scan/not-detected.nix") - ./modules/bootloaders/systemd-boot.nix + ./modules/boot.nix + ./modules/networking.nix + ./modules/nix.nix ./modules/programs/zsh.nix - ./modules/hardware/networking.nix ./modules/security.nix ./modules/users.nix ] - # Options for desktops. + # Options for graphical systems. (lib.optionals (type == "desktop") [ ./modules/hardware/audio.nix ./modules/hardware/bluetooth.nix @@ -33,66 +29,9 @@ # Options for specific hostnames. (lib.optionals (hostname == "nemesis") [ ./hw-nemesis.nix - ./modules/hardware/nvidia.nix + ./modules/bootloaders/systemd-boot.nix ./modules/hardware/cpu_amd.nix + ./modules/hardware/nvidia.nix ]) ]; - - boot = { - loader = { - timeout = 5; - efi.canTouchEfiVariables = true; - }; - kernelPackages = pkgs.linuxPackages_latest; - initrd.availableKernelModules = [ - "nvme" - "xhci_pci" - "ahci" - "usbhid" - "usb_storage" - "sd_mod" - ]; - }; - - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - extraSpecialArgs = specialArgs; - }; - - system.stateVersion = "24.11"; - - users.mutableUsers = false; # Always reset users on system activation - - nixpkgs.config.allowUnfree = true; - nix = { - settings.experimental-features = [ - "nix-command" - "flakes" - "pipe-operators" - ]; - - # Add binary caches to avoid having to compile them - settings = { - substituters = [ - "https://hyprland.cachix.org" - "https://cuda-maintainers.cachix.org" - "https://nix-community.cachix.org" - "https://nvf.cachix.org" - "https://yazi.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=" - "nvf.cachix.org-1:GMQWiUhZ6ux9D5CvFFMwnc2nFrUHTeGaXRlVBXo+naI=" - "yazi.cachix.org-1:Dcdz63NZKfvUCbDGngQDAZq6kOroIrFoyO064uvLh8k=" - ]; - }; - }; - - time.timeZone = "Asia/Singapore"; - - i18n.defaultLocale = "en_SG.UTF-8"; - } diff --git a/systems/modules/boot.nix b/systems/modules/boot.nix new file mode 100644 index 0000000..b414edb --- /dev/null +++ b/systems/modules/boot.nix @@ -0,0 +1,18 @@ +{ pkgs, ... }: +{ + boot = { + loader = { + timeout = 5; + efi.canTouchEfiVariables = true; + }; + kernelPackages = pkgs.linuxPackages_latest; + initrd.availableKernelModules = [ + "nvme" + "xhci_pci" + "ahci" + "usbhid" + "usb_storage" + "sd_mod" + ]; + }; +} diff --git a/systems/modules/bootloaders/extlinux.nix b/systems/modules/bootloaders/extlinux.nix deleted file mode 100644 index ebc62e8..0000000 --- a/systems/modules/bootloaders/extlinux.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - # Use the extlinux boot loader. (NixOS wants to enable GRUB by default) - boot.loader.grub.enable = false; - # Enables the generation of /boot/extlinux/extlinux.conf - boot.loader.generic-extlinux-compatible.enable = true; -} diff --git a/systems/modules/hardware/nvidia.nix b/systems/modules/hardware/nvidia.nix index 58a9d37..2bb831d 100644 --- a/systems/modules/hardware/nvidia.nix +++ b/systems/modules/hardware/nvidia.nix @@ -3,10 +3,17 @@ pkgs, config, ... -}: { +}: +{ # Accept the license by default; needed for some packages. nixpkgs.config.nvidia.acceptLicense = true; - services.xserver.videoDrivers = ["nvidia"]; + nix.settings = { + substituters = [ "https://cuda-maintainers.cachix.org" ]; + trusted-public-keys = [ + "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E=" + ]; + }; + services.xserver.videoDrivers = [ "nvidia" ]; environment.variables = { GBM_BACKEND = "nvidia-drm"; LIBVA_DRIVER_NAME = "nvidia"; @@ -17,19 +24,23 @@ nvidia-container-toolkit.enable = true; graphics = { enable = true; - package = inputs.hyprland.inputs.nixpkgs.legacyPackages.${pkgs.stdenv.hostPlatform.system}.mesa.drivers; + package = inputs.hyprland.inputs.nixpkgs.legacyPackages.${pkgs.stdenv.hostPlatform.system}.mesa; extraPackages = with pkgs; [ nvidia-vaapi-driver # hardware acceleration ]; }; nvidia = { modesetting.enable = true; - # powerManagement.enable = true; open = false; nvidiaSettings = true; nvidiaPersistenced = true; package = config.boot.kernelPackages.nvidiaPackages.latest; }; }; - boot.initrd.availableKernelModules = ["nvidia" "nvidia_modeset" "nvidia_uvm" "nvidia_drm"]; + boot.initrd.availableKernelModules = [ + "nvidia" + "nvidia_modeset" + "nvidia_uvm" + "nvidia_drm" + ]; } diff --git a/systems/modules/hardware/networking.nix b/systems/modules/networking.nix similarity index 100% rename from systems/modules/hardware/networking.nix rename to systems/modules/networking.nix diff --git a/systems/modules/nix.nix b/systems/modules/nix.nix new file mode 100644 index 0000000..ec7f66f --- /dev/null +++ b/systems/modules/nix.nix @@ -0,0 +1,28 @@ +{ + system.stateVersion = "24.11"; + + nixpkgs.config.allowUnfree = true; + nix = { + settings = { + experimental-features = [ + "nix-command" + "flakes" + "pipe-operators" + ]; + + # Add binary caches to avoid having to compile them + substituters = [ + "https://hyprland.cachix.org" + "https://nix-community.cachix.org" + "https://nvf.cachix.org" + "https://yazi.cachix.org" + ]; + trusted-public-keys = [ + "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "nvf.cachix.org-1:GMQWiUhZ6ux9D5CvFFMwnc2nFrUHTeGaXRlVBXo+naI=" + "yazi.cachix.org-1:Dcdz63NZKfvUCbDGngQDAZq6kOroIrFoyO064uvLh8k=" + ]; + }; + }; +} diff --git a/systems/modules/programs/tailscale.nix b/systems/modules/programs/tailscale.nix deleted file mode 100644 index 2c63c08..0000000 --- a/systems/modules/programs/tailscale.nix +++ /dev/null @@ -1,2 +0,0 @@ -{ -} diff --git a/systems/modules/security/sops.nix b/systems/modules/security/sops.nix deleted file mode 100644 index 55c6f5b..0000000 --- a/systems/modules/security/sops.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ inputs, ... }: -{ - sops = { - defaultSopsFile = ../../../secrets/secrets.yaml; - age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ]; - secrets.password.neededForUsers = true; - }; -} diff --git a/systems/modules/users.nix b/systems/modules/users.nix index f9b11af..5b7c471 100644 --- a/systems/modules/users.nix +++ b/systems/modules/users.nix @@ -1,5 +1,16 @@ -{ config, ... }: +{ config, specialArgs, ... }: { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + extraSpecialArgs = specialArgs; + }; + + users.mutableUsers = false; # Always reset users on system activation + + time.timeZone = "Asia/Singapore"; + i18n.defaultLocale = "en_SG.UTF-8"; + home-manager.users.rafiq.imports = [ ../../users/rafiq.nix ]; users.users.rafiq = { isNormalUser = true; diff --git a/systems/modules/users/rafiq.nix b/systems/modules/users/rafiq.nix deleted file mode 100644 index 93906b4..0000000 --- a/systems/modules/users/rafiq.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ inputs, config, ... }: -{ - home-manager.users.rafiq.imports = [ ../../../users/rafiq.nix ]; - users.users.rafiq = { - isNormalUser = true; - description = "rafiq"; - hashedPasswordFile = config.sops.secrets.password.path; - extraGroups = [ - "networkmanager" - "wheel" - ]; - openssh.authorizedKeys.keys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n" - ]; - }; -}