refactor(nixos): move nvidia config to its own module
This commit is contained in:
parent
5f71bc8925
commit
bf63f44875
5 changed files with 43 additions and 33 deletions
|
@ -8,12 +8,10 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./nvidia.nix
|
|
||||||
./audio.nix
|
./audio.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
options.hardware = {
|
options.hardware = {
|
||||||
gpu = lib.pantheon.mkStrOption;
|
|
||||||
platform = lib.pantheon.mkStrOption;
|
platform = lib.pantheon.mkStrOption;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
41
modules/nixos/hardware/gpu/default.nix
Normal file
41
modules/nixos/hardware/gpu/default.nix
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib)
|
||||||
|
mkMerge
|
||||||
|
mkIf
|
||||||
|
mkEnableOption
|
||||||
|
singleton
|
||||||
|
;
|
||||||
|
cfg = config.hardware.gpu;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.hardware.gpu = {
|
||||||
|
nvidia.enable = mkEnableOption "";
|
||||||
|
};
|
||||||
|
config = mkMerge [
|
||||||
|
(mkIf cfg.nvidia.enable {
|
||||||
|
hardware = {
|
||||||
|
graphics.enable = true;
|
||||||
|
graphics.extraPackages = singleton pkgs.nvidia-vaapi-driver;
|
||||||
|
nvidia.open = true;
|
||||||
|
nvidia.package = config.boot.kernelPackages.nvidiaPackages.latest;
|
||||||
|
};
|
||||||
|
services.xserver.videoDrivers = [ "nvidia" ];
|
||||||
|
nixpkgs.config.allowUnfree = true;
|
||||||
|
environment.variables = {
|
||||||
|
LIBVA_DRIVER_NAME = "nvidia";
|
||||||
|
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
|
||||||
|
NVD_BACKEND = "direct";
|
||||||
|
};
|
||||||
|
nix.settings.substituters = [ "https://cuda-maintainers.cachix.org" ];
|
||||||
|
nix.settings.trusted-public-keys = [
|
||||||
|
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
|
||||||
|
];
|
||||||
|
})
|
||||||
|
];
|
||||||
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
{
|
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
config = lib.mkIf (config.hardware.gpu == "nvidia") {
|
|
||||||
hardware = {
|
|
||||||
graphics.enable = true;
|
|
||||||
graphics.extraPackages = with pkgs; [
|
|
||||||
nvidia-vaapi-driver
|
|
||||||
];
|
|
||||||
nvidia.open = true;
|
|
||||||
nvidia.package = config.boot.kernelPackages.nvidiaPackages.latest;
|
|
||||||
};
|
|
||||||
services.xserver.videoDrivers = [ "nvidia" ];
|
|
||||||
nixpkgs.config.allowUnfree = true;
|
|
||||||
environment.variables = {
|
|
||||||
LIBVA_DRIVER_NAME = "nvidia";
|
|
||||||
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
|
|
||||||
NVD_BACKEND = "direct";
|
|
||||||
};
|
|
||||||
nix.settings.substituters = [ "https://cuda-maintainers.cachix.org" ];
|
|
||||||
nix.settings.trusted-public-keys = [
|
|
||||||
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -15,7 +15,7 @@ mkWebApp {
|
||||||
};
|
};
|
||||||
extraConfig = {
|
extraConfig = {
|
||||||
assertions = singleton {
|
assertions = singleton {
|
||||||
assertion = config.hardware.gpu == "nvidia";
|
assertion = config.hardware.gpu.nvidia.enable;
|
||||||
message = "You must run the sd-webui-forge service only with an nvidia gpu.";
|
message = "You must run the sd-webui-forge service only with an nvidia gpu.";
|
||||||
};
|
};
|
||||||
services.sd-webui-forge = {
|
services.sd-webui-forge = {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
ephemeralRoot = true;
|
ephemeralRoot = true;
|
||||||
};
|
};
|
||||||
platform = "amd";
|
platform = "amd";
|
||||||
gpu = "nvidia";
|
gpu.nvidia.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
desktop = {
|
desktop = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue