feat: Add GPU support to new user template
Some checks are pending
Code Check / Run nixfmt and statix (push) Waiting to run
Some checks are pending
Code Check / Run nixfmt and statix (push) Waiting to run
This commit is contained in:
parent
54f4de49f4
commit
2590f106b6
|
@ -46,6 +46,7 @@ in
|
||||||
# Configure the system.
|
# Configure the system.
|
||||||
aux.system = {
|
aux.system = {
|
||||||
# Enable to allow unfree (e.g. closed source) packages.
|
# Enable to allow unfree (e.g. closed source) packages.
|
||||||
|
# Some settings may override this (e.g. enabling NVIDIA GPU support).
|
||||||
# https://nixos.org/manual/nixpkgs/stable/#sec-allow-unfree
|
# https://nixos.org/manual/nixpkgs/stable/#sec-allow-unfree
|
||||||
allowUnfree = false;
|
allowUnfree = false;
|
||||||
|
|
||||||
|
@ -53,21 +54,47 @@ in
|
||||||
# IMPORTANT: Read the README before enabling this option!
|
# IMPORTANT: Read the README before enabling this option!
|
||||||
bootloader.secureboot.enable = false;
|
bootloader.secureboot.enable = false;
|
||||||
|
|
||||||
# Enable or disable Bluetooth support.
|
|
||||||
bluetooth.enable = true;
|
|
||||||
|
|
||||||
# Change the default text editor. Options are "emacs", "nano", or "vim".
|
# Change the default text editor. Options are "emacs", "nano", or "vim".
|
||||||
editor = "nano";
|
editor = "nano";
|
||||||
|
|
||||||
|
# Additional system packages to install.
|
||||||
|
packages = [ ];
|
||||||
|
|
||||||
# Change how long old generations are kept for.
|
# Change how long old generations are kept for.
|
||||||
retentionPeriod = "30d";
|
retentionPeriod = "30d";
|
||||||
|
|
||||||
|
# Enable GPU support.
|
||||||
|
gpu = {
|
||||||
|
# Enable AMD GPU support.
|
||||||
|
amd.enable = false;
|
||||||
|
|
||||||
|
# Enable Intel GPU support.
|
||||||
|
intel.enable = false;
|
||||||
|
|
||||||
|
nvidia = {
|
||||||
|
# Enable NVIDIA GPU support.
|
||||||
|
enable = false;
|
||||||
|
|
||||||
|
# Define the bus IDs for your GPUs.
|
||||||
|
# For more info on where to find bus IDs, see https://nixos.wiki/wiki/Nvidia#Configuring_Optimus_PRIME:_Bus_ID_Values_.28Mandatory.29
|
||||||
|
busIDs = {
|
||||||
|
nvidia = "";
|
||||||
|
intel = "";
|
||||||
|
amd = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Enable sync mode for faster performance at the cost of higher battery usage.
|
||||||
|
# If sync is disabled, you'll need to run GPU-accelerated applications using 'nvidia-offload <command>'.
|
||||||
|
sync = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
ui.desktops = {
|
ui.desktops = {
|
||||||
# Enable the Budgie desktop environment.
|
# Enable the Budgie desktop environment.
|
||||||
# https://buddiesofbudgie.org/
|
# https://buddiesofbudgie.org/
|
||||||
budgie.enable = false;
|
budgie.enable = false;
|
||||||
|
|
||||||
# Enables the Hyperland desktop environment.
|
# Enable the Hyperland desktop environment.
|
||||||
# https://hyprland.org/
|
# https://hyprland.org/
|
||||||
hyprland.enable = false;
|
hyprland.enable = false;
|
||||||
|
|
||||||
|
|
30
system/modules/system/gpu/amd.nix
Normal file
30
system/modules/system/gpu/amd.nix
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Enables AMD GPU support.
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.aux.system.gpu.amd;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
aux.system.gpu.amd.enable = lib.mkEnableOption (lib.mdDoc "Enables AMD GPU support.");
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
boot.initrd.kernelModules = [ "amdgpu" ];
|
||||||
|
services.xserver = {
|
||||||
|
enable = true;
|
||||||
|
videoDrivers = [ "amdgpu" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
hardware.opengl = {
|
||||||
|
extraPackages = [ pkgs.amdvlk ];
|
||||||
|
# 32-bit application compatibility
|
||||||
|
driSupport32Bit = true;
|
||||||
|
extraPackages32 = with pkgs; [ driversi686Linux.amdvlk ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
44
system/modules/system/gpu/intel.nix
Normal file
44
system/modules/system/gpu/intel.nix
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# Enables Intel GPU support.
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.aux.system.gpu.intel;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
aux.system.gpu.intel.enable = lib.mkEnableOption (lib.mdDoc "Enables Intel GPU support.");
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
# Configuration options from NixOS-Hardware: https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/intel/default.nix
|
||||||
|
boot.initrd.kernelModules = [ "i915" ];
|
||||||
|
|
||||||
|
environment.variables.VDPAU_DRIVER = "va_gl";
|
||||||
|
|
||||||
|
hardware.opengl.extraPackages = with pkgs; [
|
||||||
|
(
|
||||||
|
if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") then
|
||||||
|
vaapiIntel
|
||||||
|
else
|
||||||
|
intel-vaapi-driver
|
||||||
|
)
|
||||||
|
libvdpau-va-gl
|
||||||
|
intel-media-driver
|
||||||
|
];
|
||||||
|
|
||||||
|
hardware.opengl.extraPackages32 = with pkgs.driversi686Linux; [
|
||||||
|
(
|
||||||
|
if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") then
|
||||||
|
vaapiIntel
|
||||||
|
else
|
||||||
|
intel-vaapi-driver
|
||||||
|
)
|
||||||
|
libvdpau-va-gl
|
||||||
|
intel-media-driver
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
76
system/modules/system/gpu/nvidia.nix
Normal file
76
system/modules/system/gpu/nvidia.nix
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
# Enables NVIDIA GPU support.
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.aux.system.gpu.nvidia;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
aux.system.gpu.nvidia = {
|
||||||
|
enable = lib.mkEnableOption (lib.mdDoc "Enables NVIDIA GPU support.");
|
||||||
|
sync = lib.mkEnableOption (
|
||||||
|
lib.mdDoc "Enables sync mode for faster performance at the cost of higher battery usage."
|
||||||
|
);
|
||||||
|
busIDs = {
|
||||||
|
nvidia = lib.mkOption {
|
||||||
|
description = "The bus ID for your Nvidia GPU.";
|
||||||
|
type = lib.types.str;
|
||||||
|
example = "PCI:0:2:0";
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
intel = lib.mkOption {
|
||||||
|
description = "The bus ID for your integrated Intel GPU. If you don't have an Intel GPU, you can leave this blank.";
|
||||||
|
type = lib.types.str;
|
||||||
|
example = "PCI:14:0:0";
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
amd = lib.mkOption {
|
||||||
|
description = "The bus ID for your integrated AMD GPU. If you don't have an AMD GPU, you can leave this blank.";
|
||||||
|
type = lib.types.str;
|
||||||
|
example = "PCI:54:0:0";
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = (cfg.busIDs.nvidia == "");
|
||||||
|
message = "You need to define a bus ID for your Nvidia GPU. To learn how to find the bus ID, see https://nixos.wiki/wiki/Nvidia#Configuring_Optimus_PRIME:_Bus_ID_Values_.28Mandatory.29.";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assertion = (cfg.busIDs.intel == "" && cfg.busIDs.amd == "");
|
||||||
|
message = "You need to define a bus ID for your non-Nvidia GPU. To learn how to find your bus ID, see https://nixos.wiki/wiki/Nvidia#Configuring_Optimus_PRIME:_Bus_ID_Values_.28Mandatory.29.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
aux.system.allowUnfree = true;
|
||||||
|
|
||||||
|
services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ];
|
||||||
|
hardware.opengl.extraPackages = with pkgs; [ vaapiVdpau ];
|
||||||
|
hardware.nvidia = {
|
||||||
|
modesetting.enable = true;
|
||||||
|
nvidiaSettings = lib.mkIf (config.aux.system.ui.desktops.enable) true;
|
||||||
|
prime = {
|
||||||
|
|
||||||
|
offload = lib.mkIf (!cfg.sync) {
|
||||||
|
enable = true;
|
||||||
|
enableOffloadCmd = true; # Provides `nvidia-offload` command.
|
||||||
|
};
|
||||||
|
|
||||||
|
sync.enable = lib.mkIf cfg.sync true;
|
||||||
|
|
||||||
|
nvidiaBusId = cfg.busIDs.nvidia;
|
||||||
|
intelBusId = lib.mkIf (cfg.busIDs.intel != "") cfg.busIDs.intel;
|
||||||
|
amdgpuBusId = lib.mkIf (cfg.busIDs.amd != "") cfg.busIDs.amd;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -6,18 +6,32 @@
|
||||||
inputs,
|
inputs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.aux.system;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
|
options = {
|
||||||
|
aux.system.packages = lib.mkOption {
|
||||||
|
description = "Additional system packages to install. This is just a wrapper for environment.systemPackages.";
|
||||||
|
type = lib.types.listOf lib.types.package;
|
||||||
|
default = [ ];
|
||||||
|
example = lib.literalExpression "[ pkgs.firefox pkgs.thunderbird ]";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = {
|
||||||
# Set up the environment
|
# Set up the environment
|
||||||
environment = {
|
environment = {
|
||||||
# Install base packages
|
# Install base packages
|
||||||
systemPackages = with pkgs; [
|
systemPackages =
|
||||||
|
config.aux.system.packages
|
||||||
|
++ (with pkgs; [
|
||||||
bash
|
bash
|
||||||
dconf # Needed to fix an issue with Home-manager. See https://github.com/nix-community/home-manager/issues/3113
|
dconf # Needed to fix an issue with Home-manager. See https://github.com/nix-community/home-manager/issues/3113
|
||||||
direnv
|
direnv
|
||||||
git
|
git
|
||||||
home-manager
|
home-manager
|
||||||
p7zip
|
p7zip
|
||||||
];
|
]);
|
||||||
};
|
};
|
||||||
services = {
|
services = {
|
||||||
# Enable fwupd (firmware updater)
|
# Enable fwupd (firmware updater)
|
||||||
|
@ -32,4 +46,5 @@
|
||||||
autodetect = true;
|
autodetect = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ in
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
aux.system.ui.audio.enable = true;
|
aux.system.ui.audio.enable = true;
|
||||||
|
|
||||||
|
hardware.bluetooth.enable = true;
|
||||||
|
|
||||||
boot = {
|
boot = {
|
||||||
# Enable Plymouth for graphical bootsplash.
|
# Enable Plymouth for graphical bootsplash.
|
||||||
plymouth = {
|
plymouth = {
|
||||||
|
|
Loading…
Reference in a new issue