Move nvidia to a module

This commit is contained in:
marc
2022-11-19 15:42:26 +01:00
parent 890b05d352
commit 40d468b433
5 changed files with 49 additions and 33 deletions

View File

@@ -65,10 +65,14 @@
#+END_SRC #+END_SRC
7. Install nixos! 7. Install nixos!
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo nixos-install --impure --root /mnt --flake .#reykjavik sudo nixos-install --impure --root /mnt --flake '.#reykjavik'
#+END_SRC #+END_SRC
8. Set up the user 8. Set up the user
You'll set the root password during the installation. You can then reboot and use the installed OS. First thing you'll have to do is log in as root and set the password for your user: You'll set the root password during the installation. You can then reboot and use the installed OS. First thing you'll have to do is log in as root and set the password for your user:
#+BEGIN_SRC bash #+BEGIN_SRC bash
passwd marc passwd marc
#+END_SRC #+END_SRC
* Rebuilding
#+BEGIN_SRC bash
sudo nixos-rebuild switch --impure --flake '.#reykjavik'
#+END_SRC

View File

@@ -29,7 +29,6 @@
desktop = { desktop = {
enable = true; enable = true;
laptop = true; laptop = true;
}; };
# - Editors and development ------------------ # - Editors and development ------------------

View File

@@ -3,7 +3,6 @@
{ {
imports = [ imports = [
./hardware.nix ./hardware.nix
./nvidia.nix
]; ];
# - Basic -------------------------------------- # - Basic --------------------------------------
@@ -24,12 +23,16 @@
# - System ----------------------------------- # - System -----------------------------------
system.bluetooth.enable = true; system.bluetooth.enable = true;
system.nvidia = {
enable = true;
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
# - Desktop ---------------------------------- # - Desktop ----------------------------------
desktop = { desktop = {
enable = true; enable = true;
laptop = true; laptop = true;
}; };
# - Editors and development ------------------ # - Editors and development ------------------

View File

@@ -1,29 +0,0 @@
{ config, pkgs, ... }:
let
nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec "$@"
'';
in
{
environment.systemPackages = [ nvidia-offload ];
services.xserver.videoDrivers = [ "nvidia" ];
hardware.opengl.enable = true;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
hardware.nvidia.prime = {
offload.enable = true;
# Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
intelBusId = "PCI:0:2:0";
# Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
nvidiaBusId = "PCI:1:0:0";
};
}

39
modules/system/nvidia.nix Normal file
View File

@@ -0,0 +1,39 @@
{ config, pkgs, lib, ... }:
let
nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec "$@"
'';
cfg = config.samfelag.modules.system.nvidia;
in
{
options.samfelag.modules.system.nvidia = {
enable = lib.mkEnableOption "nvidia";
intelBusId = lib.mkOption { type = lib.types.str; };
nvidiaBusId = lib.mkOption { type = lib.types.str; };
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ nvidia-offload ];
services.xserver.videoDrivers = [ "nvidia" ];
hardware.opengl.enable = true;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
hardware.nvidia.prime = {
offload.enable = true;
# Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
intelBusId = cfg.intelBusId;
# Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
nvidiaBusId = cfg.nvidiaBusId;
};
};
}