summary refs log tree commit diff
path: root/pkgs/desktops
diff options
context:
space:
mode:
authorAmbroz Bizjak <ambrop7@gmail.com>2018-06-30 09:33:45 +0200
committerAmbroz Bizjak <ambrop7@gmail.com>2018-07-09 18:46:13 +0200
commitf26153754a1b6ac0d72adde9c75e1473463b4dbb (patch)
treea880b8725bfd44d4ad765220fa560c01363e6141 /pkgs/desktops
parent49f6ea40b0a8375a9f183e465f5475f63d4c1421 (diff)
downloadnixlib-f26153754a1b6ac0d72adde9c75e1473463b4dbb.tar
nixlib-f26153754a1b6ac0d72adde9c75e1473463b4dbb.tar.gz
nixlib-f26153754a1b6ac0d72adde9c75e1473463b4dbb.tar.bz2
nixlib-f26153754a1b6ac0d72adde9c75e1473463b4dbb.tar.lz
nixlib-f26153754a1b6ac0d72adde9c75e1473463b4dbb.tar.xz
nixlib-f26153754a1b6ac0d72adde9c75e1473463b4dbb.tar.zst
nixlib-f26153754a1b6ac0d72adde9c75e1473463b4dbb.zip
nixos/xserver: Implement configuration of NVIDIA Optimus via PRIME
This adds configuration options which automate the configuration of NVIDIA Optimus using PRIME. This allows using the NVIDIA proprietary driver on Optimus laptops, in order to render using the NVIDIA GPU while outputting to displays connected only to the integrated Intel GPU. It also adds an option for enabling kernel modesetting for the NVIDIA driver (via a kernel command line flag); this is particularly useful together with Optimus/PRIME because it fixes tearing on PRIME-connected screens.

The user still needs to enable the Optimus/PRIME feature and specify the bus IDs of the Intel and NVIDIA GPUs, but this is still much easier for users and more reliable. The implementation handles both the X configuration file as well as getting display managers to run certain necessary `xrandr` commands just after X has started.

Configuration of commands run after X startup is done using a new configuration option `services.xserver.displayManager.setupCommands`. Support for this option is implemented for LightDM, GDM and SDDM; all of these have been tested with this feature including logging into a Plasma session.

Note: support of `setupCommands` for GDM is implemented by making GDM run the session executable via a wrapper; the wrapper will run the `setupCommands` before execing. This seemed like the simplest and most reliable approach, and solves running these commands both for GDM's X server and user X servers (GDM starts separate X servers for itself and user sessions). An alternative approach would be with autostart files but that seems harder to set up and less reliable.

Note that some simple features for X configuration file generation (in `xserver.nix`) are added which are used in the implementation:
- `services.xserver.extraConfig`: Allows adding arbitrary new sections. This is used to add the Device section for the Intel GPU.
- `deviceSection` and `screenSection` within `services.xserver.drivers`. This allows the nvidia configuration module to add additional contents into the `Device` and `Screen` sections of the "nvidia" driver, and not into such sections for other drivers that may be enabled.
Diffstat (limited to 'pkgs/desktops')
-rw-r--r--pkgs/desktops/gnome-3/core/gdm/default.nix16
-rw-r--r--pkgs/desktops/gnome-3/core/gdm/gdm-session-worker_forward-vars.patch31
-rw-r--r--pkgs/desktops/gnome-3/core/gdm/gdm-session-worker_xserver-path.patch17
-rw-r--r--pkgs/desktops/gnome-3/core/gdm/gdm-x-session_session-wrapper.patch40
4 files changed, 86 insertions, 18 deletions
diff --git a/pkgs/desktops/gnome-3/core/gdm/default.nix b/pkgs/desktops/gnome-3/core/gdm/default.nix
index 2f7452dbc572..0d6bb9484421 100644
--- a/pkgs/desktops/gnome-3/core/gdm/default.nix
+++ b/pkgs/desktops/gnome-3/core/gdm/default.nix
@@ -36,13 +36,27 @@ stdenv.mkDerivation rec {
 
   # Disable Access Control because our X does not support FamilyServerInterpreted yet
   patches = [
+    # Change hardcoded paths to nix store paths.
     (substituteAll {
       src = ./fix-paths.patch;
       inherit coreutils plymouth xwayland;
     })
+
+    # The following patches implement certain environment variables in GDM which are set by
+    # the gdm configuration module (nixos/modules/services/x11/display-managers/gdm.nix).
+
+    # Look for session definition files in the directory specified by GDM_SESSIONS_DIR.
     ./sessions_dir.patch
+
+    # Allow specifying X server arguments with GDM_X_SERVER_EXTRA_ARGS.
     ./gdm-x-session_extra_args.patch
-    ./gdm-session-worker_xserver-path.patch
+
+    # Allow specifying a wrapper for running the session command.
+    ./gdm-x-session_session-wrapper.patch
+
+    # Forwards certain environment variables to the gdm-x-session child process
+    # to ensure that the above two patches actually work.
+    ./gdm-session-worker_forward-vars.patch
   ];
 
   installFlags = [
diff --git a/pkgs/desktops/gnome-3/core/gdm/gdm-session-worker_forward-vars.patch b/pkgs/desktops/gnome-3/core/gdm/gdm-session-worker_forward-vars.patch
new file mode 100644
index 000000000000..401b6aea0c28
--- /dev/null
+++ b/pkgs/desktops/gnome-3/core/gdm/gdm-session-worker_forward-vars.patch
@@ -0,0 +1,31 @@
+diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
+index 9ef4c5b..94da834 100644
+--- a/daemon/gdm-session-worker.c
++++ b/daemon/gdm-session-worker.c
+@@ -1515,6 +1515,16 @@ gdm_session_worker_load_env_d (GdmSessionWorker *worker)
+         g_object_unref (dir);
+ }
+ 
++static void
++gdm_session_worker_forward_var (GdmSessionWorker *worker, char const *var)
++{
++        char const *value = g_getenv(var);
++        if (value != NULL) {
++                g_debug ("forwarding %s= %s", var, value);
++                gdm_session_worker_set_environment_variable(worker, var, value);
++        }
++}
++
+ static gboolean
+ gdm_session_worker_accredit_user (GdmSessionWorker  *worker,
+                                   GError           **error)
+@@ -1559,6 +1569,9 @@ gdm_session_worker_accredit_user (GdmSessionWorker  *worker,
+                 goto out;
+         }
+ 
++        gdm_session_worker_forward_var(worker, "GDM_X_SERVER_EXTRA_ARGS");
++        gdm_session_worker_forward_var(worker, "GDM_X_SESSION_WRAPPER");
++
+         gdm_session_worker_update_environment_from_passwd_info (worker,
+                                                                 uid,
+                                                                 gid,
diff --git a/pkgs/desktops/gnome-3/core/gdm/gdm-session-worker_xserver-path.patch b/pkgs/desktops/gnome-3/core/gdm/gdm-session-worker_xserver-path.patch
deleted file mode 100644
index d020752fef3a..000000000000
--- a/pkgs/desktops/gnome-3/core/gdm/gdm-session-worker_xserver-path.patch
+++ /dev/null
@@ -1,17 +0,0 @@
-diff --git a/daemon/gdm-session-worker.c.orig b/daemon/gdm-session-worker.c
-index 7bbda49..592691d 100644
---- a/daemon/gdm-session-worker.c.orig
-+++ b/daemon/gdm-session-worker.c
-@@ -1557,6 +1557,12 @@ gdm_session_worker_accredit_user (GdmSessionWorker  *worker,
-                 goto out;
-         }
- 
-+        if (g_getenv ("GDM_X_SERVER_EXTRA_ARGS") != NULL) {
-+                g_debug ("forwarding GDM_X_SERVER_EXTRA_ARGS= %s", g_getenv("GDM_X_SERVER_EXTRA_ARGS"));
-+                gdm_session_worker_set_environment_variable (worker, "GDM_X_SERVER_EXTRA_ARGS",
-+                                                             g_getenv("GDM_X_SERVER_EXTRA_ARGS"));
-+        }
-+
-         gdm_session_worker_update_environment_from_passwd_info (worker,
-                                                                 uid,
-                                                                 gid,
diff --git a/pkgs/desktops/gnome-3/core/gdm/gdm-x-session_session-wrapper.patch b/pkgs/desktops/gnome-3/core/gdm/gdm-x-session_session-wrapper.patch
new file mode 100644
index 000000000000..58481f0730fa
--- /dev/null
+++ b/pkgs/desktops/gnome-3/core/gdm/gdm-x-session_session-wrapper.patch
@@ -0,0 +1,40 @@
+diff --git a/daemon/gdm-x-session.c b/daemon/gdm-x-session.c
+index 88fe96f..b1b140a 100644
+--- a/daemon/gdm-x-session.c
++++ b/daemon/gdm-x-session.c
+@@ -664,18 +664,34 @@ spawn_session (State        *state,
+                                                           state->session_command,
+                                                           NULL);
+         } else {
++                char const *session_wrapper;
++                char *eff_session_command;
+                 int ret;
+                 char **argv;
+ 
+-                ret = g_shell_parse_argv (state->session_command,
++                session_wrapper = g_getenv("GDM_X_SESSION_WRAPPER");
++                if (session_wrapper != NULL) {
++                        char *quoted_wrapper = g_shell_quote(session_wrapper);
++                        eff_session_command = g_strjoin(" ", quoted_wrapper, state->session_command, NULL);
++                        g_free(quoted_wrapper);
++                } else {
++                        eff_session_command = state->session_command;
++                }
++
++                ret = g_shell_parse_argv (eff_session_command,
+                                           NULL,
+                                           &argv,
+                                           &error);
+ 
++                if (session_wrapper != NULL) {
++                        g_free(eff_session_command);
++                }
++
+                 if (!ret) {
+                         g_debug ("could not parse session arguments: %s", error->message);
+                         goto out;
+                 }
++
+                 subprocess = g_subprocess_launcher_spawnv (launcher,
+                                                            (const char * const *) argv,
+                                                            &error);