2021-03-08 21:35:29 +01:00
|
|
|
{ nixpkgs, nixpkgs-unstable, nixpkgs-master, custom, hostname, rlib, inputs }:
|
2021-03-14 10:58:29 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
2021-03-14 22:22:45 +01:00
|
|
|
xserver-enable = config.services.xserver.enable;
|
2021-04-02 12:38:31 +02:00
|
|
|
nvidia-offload = nixpkgs-unstable.writeShellScriptBin "nvidia-offload" ''
|
2021-03-14 10:58:29 +01:00
|
|
|
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 -a "$0" "$@"
|
|
|
|
'';
|
|
|
|
cfg = config.magic_rb.xserver;
|
|
|
|
in
|
2020-12-26 23:36:50 +01:00
|
|
|
{
|
2021-03-14 10:58:29 +01:00
|
|
|
options.magic_rb.xserver = {
|
|
|
|
enable = mkEnableOption "XServer for my setup style";
|
|
|
|
gpu = mkOption {
|
|
|
|
description = "Which GPU type do you have?";
|
2021-03-14 22:22:45 +01:00
|
|
|
type = types.enum ["nvidia"];
|
2020-12-26 23:36:50 +01:00
|
|
|
};
|
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
nvidia = mkOption {
|
|
|
|
description = "NVidia section";
|
|
|
|
type = types.submodule {
|
|
|
|
options = {
|
|
|
|
prime = mkEnableOption "NVidia PRIME support";
|
|
|
|
|
|
|
|
intelBusId = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
nvidiaBusId = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
linux-5-11-patch = mkEnableOption "Linux 5.11 compat patch";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default = {};
|
2020-12-26 23:36:50 +01:00
|
|
|
};
|
2021-03-14 22:22:45 +01:00
|
|
|
xmonad = mkEnableOption "Enable xmonad";
|
|
|
|
setSkLayout = mkEnableOption "Set SK layout";
|
|
|
|
emacsCtrl = mkEnableOption "Rebind CapsLock to Ctrl";
|
2020-12-26 23:36:50 +01:00
|
|
|
};
|
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
services.xserver = {
|
|
|
|
enable = true;
|
2021-03-14 10:58:29 +01:00
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
windowManager = mkIf cfg.xmonad {
|
|
|
|
xmonad.enable = true;
|
|
|
|
xmonad.enableContribAndExtras = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
displayManager = mkIf cfg.xmonad {
|
|
|
|
defaultSession = "none+xmonad";
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
libinput.enable = true;
|
2021-03-14 10:58:29 +01:00
|
|
|
};
|
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
hardware = {
|
|
|
|
opengl.driSupport32Bit = true;
|
|
|
|
# opengl.extraPackages32 = with pkgs.pkgsi686Linux; [ libva ]; # What does this do??
|
2021-03-14 10:58:29 +01:00
|
|
|
};
|
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
}
|
|
|
|
(mkIf (cfg.gpu == "nvidia") {
|
|
|
|
services.xserver.videoDrivers = [ "nvidia" ];
|
2021-03-14 10:58:29 +01:00
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
environment.systemPackages = mkIf (cfg.nvidia.prime) [ nvidia-offload ];
|
2021-03-14 10:58:29 +01:00
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
hardware.nvidia.prime = mkIf cfg.nvidia.prime {
|
|
|
|
offload.enable = true;
|
|
|
|
|
|
|
|
intelBusId = cfg.nvidia.intelBusId;
|
|
|
|
nvidiaBusId = cfg.nvidia.nvidiaBusId;
|
|
|
|
};
|
|
|
|
|
2021-04-02 12:38:31 +02:00
|
|
|
# hardware.nvidia.package = mkIf
|
|
|
|
# cfg.nvidia.linux-5-11-patch
|
|
|
|
# config.hardware.nvidia.package.overrideAttrs (old:
|
|
|
|
# {
|
|
|
|
# patches = old.patches ++ [ ./nvidia-5.11.patch ];
|
|
|
|
# });
|
2021-03-14 22:22:45 +01:00
|
|
|
})
|
|
|
|
(mkIf cfg.setSkLayout {
|
|
|
|
services.xserver = {
|
|
|
|
layout = mkIf xserver-enable "us,sk";
|
|
|
|
xkbVariant = mkIf xserver-enable ",qwerty";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf cfg.emacsCtrl {
|
|
|
|
services.xserver = {
|
|
|
|
xkbOptions = mkIf xserver-enable "grp:lalt_lshift_toggle ctrl:nocaps";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
2020-12-26 23:36:50 +01:00
|
|
|
}
|