From 9d150a377aadebe447a971b4f75bc68d32e09c8d Mon Sep 17 00:00:00 2001 From: Maaz Khokhar Date: Sun, 5 Jul 2026 22:53:04 -0500 Subject: [PATCH] core modules have options now --- modules/core/config.nix | 93 +++++++++++++++++++++++++++++++++++ modules/core/default.nix | 101 +++------------------------------------ modules/core/options.nix | 46 ++++++++++++++++++ modules/core/shared.nix | 9 ++++ 4 files changed, 155 insertions(+), 94 deletions(-) create mode 100644 modules/core/config.nix create mode 100644 modules/core/options.nix create mode 100644 modules/core/shared.nix diff --git a/modules/core/config.nix b/modules/core/config.nix new file mode 100644 index 0000000..d11c79a --- /dev/null +++ b/modules/core/config.nix @@ -0,0 +1,93 @@ +{ + config, + pkgs, + shared, + ... +}: +let + cfg = config.homelab.core; + + allowRootSSH = if cfg.ssh.PermitRootLogin then "yes" else "no"; +in +{ + + config = { + boot.kernelPackages = shared.kernelMap.${cfg.kernel}; + + time.timeZone = "America/Chicago"; + + programs.${cfg.user.shell}.enable = true; + + users.users.${cfg.user.name} = with cfg.user; { + isNormalUser = true; + description = fullName; + extraGroups = [ + "wheel" + "networkmanager" + "input" + ]; + + shell = pkgs.${shell}; + }; + + nixpkgs.config.allowUnfree = true; + + environment.systemPackages = with pkgs; [ + gitFull + neovim + git-credential-manager + gnupg + ]; + + nix = { + gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 7d"; + }; + settings = { + trusted-users = [ + "root" + cfg.user.name + ]; + experimental-features = [ + "nix-command" + "flakes" + ]; + auto-optimise-store = true; + }; + }; + + programs.nix-ld.enable = true; + + i18n = { + defaultLocale = "en_US.UTF-8"; + + extraLocaleSettings = { + LC_ADDRESS = "en_US.UTF-8"; + LC_IDENTIFICATION = "en_US.UTF-8"; + LC_MEASUREMENT = "en_US.UTF-8"; + LC_MONETARY = "en_US.UTF-8"; + LC_NAME = "en_US.UTF-8"; + LC_NUMERIC = "en_US.UTF-8"; + LC_PAPER = "en_US.UTF-8"; + LC_TELEPHONE = "en_US.UTF-8"; + LC_TIME = "en_US.UTF-8"; + }; + }; + + security.rtkit.enable = true; + + services = { + xserver.xkb = { + layout = "us"; + variant = ""; + }; + + openssh = { + enable = true; + settings.PermitRootLogin = allowRootSSH; + }; + }; + }; +} diff --git a/modules/core/default.nix b/modules/core/default.nix index 27dbb39..2fe6fc3 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -1,100 +1,13 @@ { pkgs, ... }: +let + shared = import ./shared.nix { inherit pkgs; }; +in { - boot.kernelPackages = pkgs.linuxPackages_latest; - - time.timeZone = "America/Chicago"; - - programs.fish.enable = true; - - users.users.river = { - isNormalUser = true; - description = "Maaz Khokhar"; - extraGroups = [ - "wheel" - "networkmanager" - "input" - ]; - - shell = pkgs.fish; - }; - - nixpkgs.config.allowUnfree = true; - - environment.systemPackages = with pkgs; [ - gitFull - neovim - btop - unzip - mpv - wl-clipboard - wireplumber - brightnessctl - pulseaudio - pavucontrol - ghostty - git-credential-manager - gnupg - yazi + imports = [ + ./options.nix + ./config.nix ]; - nix = { - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 7d"; - }; - settings = { - trusted-users = [ - "root" - "river" - ]; - experimental-features = [ - "nix-command" - "flakes" - ]; - auto-optimise-store = true; - }; - }; - - programs.nix-ld.enable = true; - - i18n = { - defaultLocale = "en_US.UTF-8"; - - extraLocaleSettings = { - LC_ADDRESS = "en_US.UTF-8"; - LC_IDENTIFICATION = "en_US.UTF-8"; - LC_MEASUREMENT = "en_US.UTF-8"; - LC_MONETARY = "en_US.UTF-8"; - LC_NAME = "en_US.UTF-8"; - LC_NUMERIC = "en_US.UTF-8"; - LC_PAPER = "en_US.UTF-8"; - LC_TELEPHONE = "en_US.UTF-8"; - LC_TIME = "en_US.UTF-8"; - }; - }; - - security.rtkit.enable = true; - - services = { - xserver.xkb = { - layout = "us"; - variant = ""; - }; - - pipewire = { - enable = true; - alsa.enable = true; - alsa.support32Bit = true; - pulse.enable = true; - }; - - openssh = { - enable = true; - settings.PermitRootLogin = "no"; - }; - - printing.enable = true; - }; + _module.args.shared = shared; } diff --git a/modules/core/options.nix b/modules/core/options.nix new file mode 100644 index 0000000..ffb8f50 --- /dev/null +++ b/modules/core/options.nix @@ -0,0 +1,46 @@ +{ + lib, + shared, + ... +}: +{ + options.homelab.core = { + kernel = lib.mkOption { + type = with lib.types; enum (builtins.attrNames shared.kernelOptions); + default = "lts"; + description = "The kernel of the machine"; + }; + + user = { + name = lib.mkOption { + type = lib.types.str; + default = "river"; + description = "The username of the primary user"; + }; + + fullName = lib.mkOption { + type = lib.types.str; + default = "Maaz Khokhar"; + description = "The full name of the user"; + }; + + shell = lib.mkOption { + type = with lib.types; listOf str; + default = "fish"; + description = "The shell the primary user uses"; + }; + }; + + allowUnfree = lib.mkEnableOption { + enable = true; + default = true; + }; + + ssh = { + permitRootLogin = lib.mkEnableOption { + enable = true; + default = false; + }; + }; + }; +} diff --git a/modules/core/shared.nix b/modules/core/shared.nix new file mode 100644 index 0000000..9c56ac4 --- /dev/null +++ b/modules/core/shared.nix @@ -0,0 +1,9 @@ +{ pkgs, ... }: + +{ + kernelOptions = { + stable = pkgs.linuxPackages; + lts = pkgs.linuxPackages_lts; + latest = pkgs.linuxPackages_latest; + }; +}