2022-07-31 11:03:59 +02:00
|
|
|
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
2021-03-14 22:22:45 +01:00
|
|
|
xserver-enable = config.services.xserver.enable;
|
2021-04-11 00:25:36 +02:00
|
|
|
nvidia-offload = pkgs.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;
|
2022-07-31 11:03:59 +02:00
|
|
|
in {
|
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 = {
|
2022-04-15 09:53:16 +02:00
|
|
|
primeOffload = mkEnableOption "NVidia PRIME sync support";
|
|
|
|
primeSync = mkEnableOption "NVidia PRIME offload support";
|
2022-07-31 11:03:59 +02:00
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
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";
|
2021-04-11 00:25:36 +02:00
|
|
|
lightdm = mkEnableOption "Enable lightdm";
|
2021-05-12 23:57:02 +02:00
|
|
|
qwertyNeo2 = mkEnableOption "Add custom qwerty neo layout.";
|
2021-06-27 18:55:40 +02:00
|
|
|
mimickInTty = mkEnableOption "Mimick xkb set keyboard layouts in TTYs.";
|
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 {
|
2021-04-11 00:25:36 +02:00
|
|
|
lightdm.enable = mkIf cfg.lightdm true;
|
2021-03-14 22:22:45 +01:00
|
|
|
defaultSession = "none+xmonad";
|
|
|
|
};
|
2022-07-31 11:03:59 +02:00
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
libinput.enable = true;
|
2021-03-14 10:58:29 +01:00
|
|
|
};
|
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
hardware = {
|
2022-04-15 09:53:16 +02:00
|
|
|
opengl.enable = true;
|
2021-03-14 22:22:45 +01:00
|
|
|
opengl.driSupport32Bit = true;
|
2021-03-14 10:58:29 +01:00
|
|
|
};
|
2021-03-14 22:22:45 +01:00
|
|
|
}
|
|
|
|
(mkIf (cfg.gpu == "nvidia") {
|
2022-07-31 11:03:59 +02:00
|
|
|
services.xserver.videoDrivers = ["nvidia"];
|
2022-04-15 09:53:16 +02:00
|
|
|
hardware.nvidia.modesetting.enable = mkIf cfg.nvidia.primeSync true;
|
2021-03-14 10:58:29 +01:00
|
|
|
|
2022-04-15 09:53:16 +02:00
|
|
|
services.xserver.deviceSection = mkIf cfg.nvidia.primeSync ''
|
|
|
|
Option "Coolbits" "28"
|
|
|
|
Option "UseEvents" "on"
|
|
|
|
'';
|
|
|
|
|
2022-07-31 11:03:59 +02:00
|
|
|
environment.systemPackages =
|
|
|
|
mkIf cfg.nvidia.primeOffload
|
|
|
|
[nvidia-offload pkgs.libglvnd];
|
2021-03-14 10:58:29 +01:00
|
|
|
|
2022-04-15 09:53:16 +02:00
|
|
|
hardware.nvidia.prime = mkIf (cfg.nvidia.primeSync || cfg.nvidia.primeOffload) {
|
|
|
|
sync.enable = cfg.nvidia.primeSync;
|
|
|
|
offload.enable = cfg.nvidia.primeOffload;
|
2022-07-31 11:03:59 +02:00
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
intelBusId = cfg.nvidia.intelBusId;
|
|
|
|
nvidiaBusId = cfg.nvidia.nvidiaBusId;
|
|
|
|
};
|
|
|
|
})
|
2021-05-12 23:57:02 +02:00
|
|
|
(mkIf cfg.qwertyNeo2 {
|
2023-01-15 01:19:19 +01:00
|
|
|
|
|
|
|
services.xserver.displayManager.sessionCommands =
|
|
|
|
"${pkgs.xorg.xmodmap}/bin/xmodmap ${pkgs.writeText "xkb-layout" ''
|
|
|
|
! bind the omen key to switching layouts
|
|
|
|
keycode 212 = ISO_Next_Group
|
|
|
|
''}";
|
|
|
|
|
2021-03-14 22:22:45 +01:00
|
|
|
services.xserver = {
|
2023-01-15 01:19:19 +01:00
|
|
|
layout = "de,de,mine,us";
|
|
|
|
xkbVariant = "koy,neo_qwerty,mine,";
|
2021-06-27 18:55:40 +02:00
|
|
|
xkbOptions = "ctrl:swap_lalt_lctl_lwin, altwin:menu_win, grp:sclk_toggle";
|
2021-05-28 09:01:35 +02:00
|
|
|
|
|
|
|
extraLayouts."neo_qwerty" = {
|
|
|
|
description = "QWERTY neo2 layout.";
|
2022-07-31 11:03:59 +02:00
|
|
|
languages = ["de"];
|
2021-05-28 09:01:35 +02:00
|
|
|
symbolsFile = ./qwerty_neo.xkb;
|
|
|
|
};
|
2023-01-09 13:07:05 +01:00
|
|
|
|
|
|
|
extraLayouts."mine" = {
|
|
|
|
description = "mine neo layout.";
|
2023-01-15 01:19:19 +01:00
|
|
|
languages = ["de"];
|
2023-01-09 13:07:05 +01:00
|
|
|
symbolsFile = ./mine.xkb;
|
|
|
|
};
|
2021-03-14 22:22:45 +01:00
|
|
|
};
|
|
|
|
})
|
2021-06-27 18:55:40 +02:00
|
|
|
(mkIf cfg.mimickInTty {
|
|
|
|
console.useXkbConfig = true;
|
|
|
|
})
|
2021-03-14 22:22:45 +01:00
|
|
|
]);
|
2020-12-26 23:36:50 +01:00
|
|
|
}
|