diff --git a/flake.nix b/flake.nix index 0b78650..dfe58d1 100644 --- a/flake.nix +++ b/flake.nix @@ -42,6 +42,8 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + nix-gaming.url = "github:fufexan/nix-gaming"; + }; diff --git a/system/modules/default.nix b/system/modules/default.nix index 8b9fe25..1638bcd 100644 --- a/system/modules/default.nix +++ b/system/modules/default.nix @@ -20,5 +20,14 @@ pipewire = { enable = lib.mkEnableOption "Enable pipewire module"; }; + networking = { + enable = lib.mkEnableOption "Enable networking module"; + }; + virtualisation = { + enable = lib.mkEnableOption "Enable virtualisation module"; + }; + locale = { + enable = lib.mkEnableOption "Enable locale module"; + }; }; } diff --git a/system/modules/gaming/default.nix b/system/modules/gaming/default.nix deleted file mode 100644 index e69de29..0000000 diff --git a/system/modules/hardware/backlight.nix b/system/modules/hardware/backlight/default.nix similarity index 100% rename from system/modules/hardware/backlight.nix rename to system/modules/hardware/backlight/default.nix diff --git a/system/modules/locale/default.nix b/system/modules/locale/default.nix index b2903cc..3c20c6b 100644 --- a/system/modules/locale/default.nix +++ b/system/modules/locale/default.nix @@ -1,11 +1,18 @@ -{ lib, ... }: { - i18n = { - defaultLocale = lib.mkDefault "en_US.UTF-8"; - supportedLocales = lib.mkDefault [ - "en_US.UTF-8/UTF-8" - ]; - }; - time.timeZone = lib.mkDefault "Pacific/Auckland"; - services.geoclue2.enable = true; -} +{ lib, config, ... }: +let + cfg = config.systemModules.locale; +in + +{ + config = lib.mkIf cfg.enable { + i18n = { + defaultLocale = lib.mkDefault "en_US.UTF-8"; + supportedLocales = lib.mkDefault [ + "en_US.UTF-8/UTF-8" + ]; + }; + time.timeZone = lib.mkDefault "Pacific/Auckland"; + services.geoclue2.enable = true; + }; +} diff --git a/system/modules/networking/default.nix b/system/modules/networking/default.nix index e9d2c8a..ac2c6e1 100644 --- a/system/modules/networking/default.nix +++ b/system/modules/networking/default.nix @@ -1,18 +1,25 @@ -{ lib, ... }: +{ lib, config, ... }: + +let + cfg = config.systemModules.networking; +in + { - networking.networkmanager = { - enable = true; - dns = "systemd-resolved"; - }; - networking.firewall.allowedTCPPorts = [57621]; - - services = { - openssh = { + config = lib.mkIf cfg.enable { + networking.networkmanager = { enable = true; - settings.UseDns = true; + dns = "systemd-resolved"; }; - resolved.enable = true; - }; + networking.firewall.allowedTCPPorts = [57621]; - systemd.services.NetworkManager-wait-online.enable = lib.mkForce false; + services = { + openssh = { + enable = true; + settings.UseDns = true; + }; + resolved.enable = true; + }; + + systemd.services.NetworkManager-wait-online.enable = lib.mkForce false; + }; } diff --git a/system/modules/user/default.nix b/system/modules/user/default.nix new file mode 100644 index 0000000..ad5494c --- /dev/null +++ b/system/modules/user/default.nix @@ -0,0 +1,14 @@ +{ lib, ... }: + +{ + imports = [ + ./shell + ./ooks.nix + ]; + + options.systemModules.user = { + ooks = { + enable = lib.mkEnableOption "Enable the user ooks"; + }; + }; +} diff --git a/system/modules/user/ooks.nix b/system/modules/user/ooks.nix new file mode 100644 index 0000000..05db729 --- /dev/null +++ b/system/modules/user/ooks.nix @@ -0,0 +1,28 @@ +{ lib, pkgs, config, ... }: + +let + ifTheyExist = groups: builtins.filter (group: builtins.hasAttr group config.users.groups) groups; + cfg = config.systemModule.user.ooks; +in + +{ + config = lib.mkIf cfg.enable { + users.users.ooks = { + isNormalUser = true; + extraGroups = [ + "wheel" + "video" + "audio" + ] ++ ifTheyExist [ + "git" + "network" + "libvirtd" + "deluge" + ]; + + packages = [ pkgs.home-manager ]; + }; + + home-manager.users.ooks = import ../../../../home/user/ooks/${config.networking.hostName}; + }; +} diff --git a/system/modules/user/shell/default.nix b/system/modules/user/shell/default.nix new file mode 100644 index 0000000..9bbe4c4 --- /dev/null +++ b/system/modules/user/shell/default.nix @@ -0,0 +1,40 @@ +{ lib, config, ... }: + +let + cfg = config.systemModules.user.shell; +in + +{ + imports = [ + ./fish + # ./bash + # ./zsh + ]; + + options.systemModules.user.shell = { + fish = { + enable = lib.mkEnableOption "Enable fish as the user shell"; + }; + zsh = { + enable = lib.mkEnableOption "Enable zsh as the user shell"; + }; + bash = { + enable = lib.mkEnableOption "Enable bash as the user shell"; + }; + + }; + + config = { + assertions = [ + { + assertion = + (lib.length (lib.filter (x: x) [ + cfg.fish.enable or false + cfg.zsh.enable or false + cfg.bash.enable or false + ]) <= 1); + message = "Only one user shell can be active in the configuration"; + } + ]; + }; +} diff --git a/system/modules/user/shell/fish/default.nix b/system/modules/user/shell/fish/default.nix new file mode 100644 index 0000000..d375748 --- /dev/null +++ b/system/modules/user/shell/fish/default.nix @@ -0,0 +1,19 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.systemModules.user.shell.fish; +in + +{ + config = lib.mkIf cfg.enable { + users.users.ooks.shell = pkgs.fish; + programs.fish = { + enable = true; + vendor = { + completions.enable = true; + config.enable = true; + functions.enable = true; + }; + }; + }; +} diff --git a/system/modules/userShell/default.nix b/system/modules/userShell/default.nix deleted file mode 100644 index e69de29..0000000 diff --git a/system/modules/userShell/fish/default.nix b/system/modules/userShell/fish/default.nix deleted file mode 100644 index b19e2fd..0000000 --- a/system/modules/userShell/fish/default.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ pkgs, ... }: -{ - users.users.ooks.shell = pkgs.fish; - programs.fish = { - enable = true; - vendor = { - completions.enable = true; - config.enable = true; - functions.enable = true; - }; - }; -} diff --git a/system/modules/virtulization/default.nix b/system/modules/virtulization/default.nix index 667ef31..82ec901 100644 --- a/system/modules/virtulization/default.nix +++ b/system/modules/virtulization/default.nix @@ -1,28 +1,33 @@ -{config, pkgs, ... }: +{ lib, config, pkgs, ... }: + +let + cfg = config.systemModules.virtualisation; +in { - environment.systemPackages = with pkgs; [ - virt-manager - virt-viewer - spice - spice-gtk - spice-protocol - win-virtio - win-spice - gnome.adwaita-icon-theme - ]; + config = lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + virt-manager + virt-viewer + spice + spice-gtk + spice-protocol + win-virtio + win-spice + gnome.adwaita-icon-theme + ]; - virtualisation = { - libvirtd = { - enable = true; - qemu = { - swtpm.enable = true; - ovmf.enable = true; - ovmf.packages = [ pkgs.OVMFFull.fd ]; + virtualisation = { + libvirtd = { + enable = true; + qemu = { + swtpm.enable = true; + ovmf.enable = true; + ovmf.packages = [ pkgs.OVMFFull.fd ]; + }; }; + spiceUSBRedirection.enable = true; }; - spiceUSBRedirection.enable = true; + services.spice-vdagentd.enable = true; }; - services.spice-vdagentd.enable = true; } - diff --git a/system/profiles/base/default.nix b/system/profiles/base/default.nix new file mode 100644 index 0000000..212f861 --- /dev/null +++ b/system/profiles/base/default.nix @@ -0,0 +1,17 @@ +{ lib, config, ... }: + +let + cfg = config.systemProfile.base; +in + +{ + config = lib.mkIf cfg.enable { + systemModules = { + security.enable = true; + nixOptions.enable = true; + pipewire.enable = true; + networking.enable = true; + locale.enable = true; + } + }; +} diff --git a/system/profiles/default.nix b/system/profiles/default.nix new file mode 100644 index 0000000..eb87a7d --- /dev/null +++ b/system/profiles/default.nix @@ -0,0 +1,40 @@ +{ lib, config, ... }: + +let + profileEnabler = let + reducer = l: r: {"${r}".enable = true;} // l; + in + builtins.foldl' reducer {} config.activeProfiles; +in +{ + imports = [ + ./base + ./nvidia + #./gaming + #./laptop + ]; + + options = { + activeProfiles = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = []; + }; + + systemProfiles = { + base = { + enable = lib.mkEnableOption "Enable the base profile"; + }; + gaming = { + enable = lib.mkEnableOption "Enable the gaming profile"; + }; + laptop = { + enable = lib.mkEnableOption "Enable the laptop profile"; + }; + nvidia = { + enable = lib.mkEnableOption "Enable the nvidia profile"; + }; + }; + }; + + config.profiles = profileEnabler; +} diff --git a/system/profiles/gaming/default.nix b/system/profiles/gaming/default.nix new file mode 100644 index 0000000..d03cdd8 --- /dev/null +++ b/system/profiles/gaming/default.nix @@ -0,0 +1,30 @@ +{ lib, config, pkgs, inputs, ... }: + +let + cfg = config.systemProfile.gaming; +in + +{ + imports = [ + inputs.nix-gaming.nixosModules.pipewireLowLatency + ]; + + config = lib.mkIf cfg.enable { + hardware.opengl.extraPackages = [ pkgs.gamescope ]; + programs = { + steam.enable = true; + gamescope = { + enable = true; + capsSysNice = true; + }; + gamemode = { + enable = true; + settings = { + softrealtime = "auto"; + renice = 15; + }; + }; + }; + services.pipewire.lowLatency.enable = true; + }; +} diff --git a/system/profiles/nvidia/default.nix b/system/profiles/nvidia/default.nix new file mode 100644 index 0000000..960ea38 --- /dev/null +++ b/system/profiles/nvidia/default.nix @@ -0,0 +1,29 @@ +{ lib, config, pkgs, ... }: + +let + cfg = config.systemProfile.nvidia; + production = config.boot.kernelPackages.nvidiaPackages.production; +in + +{ + config = lib.mkIf cfg.enable { + harware.nvidia = { + open = true; + package = production; + modesetting.enable = true; + nvidiaSettings = true; + powerManagement.enable = false; + }; + services.xserver.videoDrivers = [ "nvidia" ]; + environment.sessionVariables = { + LIBVA_DRIVER_NAME = "nvidia"; + }; + environment.systemPackages = with pkgs; [ + vulkan-loader + vulkan-validation-layers + vulkan-tools + ]; + }; + + +}