How to change login command in gdm

Hello there,I want to use nvidia driver in hyprland,so instead of launching hyprland in gdm by default I want to use nvidia-offload hyprland.
But I can’t figure out which setting should be used.
How can I do this?Thank you.

Hello,

Maybe something like below would work ?

{ pkgs }:
let
  # Based on https://github.com/hyprwm/Hyprland/blob/93d05114716e847c37f49d3cc2d0c5cb01d06a24/example/hyprland.desktop
  hyprland-nvidia-session = pkgs.makeDesktopItem {
    name = "Hyprland-nvidia";
    desktopName = "Hyprland-nvidia";
    comment = "An intelligent dynamic tiling Wayland compositor (with more nvidia)";
    exec = "${pkgs.nvidia-offload} ${pkgs.hyprland}";
  };
in
{
  services.xserver.displayManager.sessionPackages = [ hyprland-nvidia-session ];
}

or alternatively, this one which puts everything in the hyprland package (but forces you to recompile hyprland):

{ pkgs }:
let

  # Based on https://github.com/hyprwm/Hyprland/blob/93d05114716e847c37f49d3cc2d0c5cb01d06a24/example/hyprland.desktop
  hyprland-nvidia-session = pkgs.makeDesktopItem {
    name = "Hyprland-nvidia";
    desktopName = "Hyprland-nvidia";
    comment = "An intelligent dynamic tiling Wayland compositor (with more nvidia)";
    exec = "${pkgs.nvidia-offload} ${pkgs.hyprland}";
  };

  hyprland-nvidia = pkgs.hyprland.overrideAttrs (old: {
    postFixup = (old.postFixup or "") + ''
      cp -r ${hyprland-nvidia-session} $out
    '';
  });
in
{
  programs.hyprland = {
    enable = true;
    package = hyprland-nvidia;
  }
}

EDIT: this one should avoid to recompile hyprland:

{ pkgs }:
let

  # Based on https://github.com/hyprwm/Hyprland/blob/93d05114716e847c37f49d3cc2d0c5cb01d06a24/example/hyprland.desktop
  hyprland-nvidia-session = pkgs.makeDesktopItem {
    name = "Hyprland-nvidia";
    desktopName = "Hyprland-nvidia";
    comment = "An intelligent dynamic tiling Wayland compositor (with more nvidia)";
    exec = "${pkgs.nvidia-offload} ${pkgs.hyprland}";
  };
in
{
  programs.hyprland = {
    enable = true;
    package = pkgs.symlinkJoin { name = "hyprland-nvidia"; paths = [pkgs.hyprland hyprland-nvidia-session];};
  }
}

Thanks for your reply,I tried the first solution.
I warns me that

  error: attribute 'nvidia-offload' missing

       at /nix/store/xmy8crl981fnvsijmnfnr5ka24z70jyp-source/system/system.nix:14:15:

           13|     comment = "An intelligent dynamic tiling Wayland compositor (with more nvidia)";
           14|     exec = "${pkgs.nvidia-offload} ${hyprland}";
             |               ^
           15|   };

But I have already set
hardware.nvidia.prime.offload.enableOffloadCmd to true
I also tried

  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

and add it to environment.systemPackages.
But I get the same error.

Ok, from hardware.nvidia.prime.offload.enableOffloadCmd , it says that nvidia-offload is added to systemPackages, so we can drop the string interpolation.

You should try to replace the exec line with:

exec = "nvidia-offload ${pkgs.hyprland}";

Hi,I now tried all of them but with no luck.
The first one,can’t build:

warning: Git tree '/home/gus/pose' is dirty
building the system configuration...
warning: Git tree '/home/gus/pose' is dirty
error:
       … while calling the 'head' builtin

         at /nix/store/y45vqv6pa8bhgag1dw86rvi6rk55xhxn-source/lib/attrsets.nix:1541:11:

         1540|         || pred here (elemAt values 1) (head values) then
         1541|           head values
             |           ^
         1542|         else

       … while evaluating the attribute 'value'

         at /nix/store/y45vqv6pa8bhgag1dw86rvi6rk55xhxn-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: Package, 'Hyprland-nvidia.desktop', did not specify any session names, as strings, in
       'passthru.providedSessions'. This is required when used as a session package.

       The session names can be looked up in:
         /nix/store/8c2vl49mgb5m5nx1zsql5slhv5b06m7s-Hyprland-nvidia.desktop/share/xsessions
         /nix/store/8c2vl49mgb5m5nx1zsql5slhv5b06m7s-Hyprland-nvidia.desktop/share/wayland-sessions
error: Recipe `update-os` failed on line 6 with exit code 1

The second one,I build successfully but I can’t select any wayland session in gdm.
The hyprland dir tree is:

❯ nix run nixpkgs#eza -- -T
.
├── 8c2vl49mgb5m5nx1zsql5slhv5b06m7s-Hyprland-nvidia.desktop
│  └── share
│     └── applications
│        └── Hyprland-nvidia.desktop
├── bin
│  ├── hyprctl
│  ├── Hyprland
│  └── hyprpm
└── share
   ├── hyprland
   │  ├── hyprland.conf
   │  ├── wall0.png
   │  ├── wall1.png
   │  └── wall2.png
   ├── wayland-sessions
   │  └── hyprland.desktop
   └── xdg-desktop-portal
      └── hyprland-portals.conf

The third one:

sudo nixos-rebuild switch
warning: Git tree '/home/gus/pose' is dirty
building the system configuration...
warning: Git tree '/home/gus/pose' is dirty
error:
       … while calling the 'head' builtin

         at /nix/store/y45vqv6pa8bhgag1dw86rvi6rk55xhxn-source/lib/attrsets.nix:1541:11:

         1540|         || pred here (elemAt values 1) (head values) then
         1541|           head values
             |           ^
         1542|         else

       … while evaluating the attribute 'value'

         at /nix/store/y45vqv6pa8bhgag1dw86rvi6rk55xhxn-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'override' missing

       at /nix/store/y45vqv6pa8bhgag1dw86rvi6rk55xhxn-source/nixos/modules/programs/wayland/hyprland.nix:31:17:

           30|       readOnly = true;
           31|       default = cfg.package.override {
             |                 ^
           32|         enableXWayland = cfg.xwayland.enable;
error: Recipe `update-os` failed on line 6 with exit code 1

Ok, I have stopped being lazy and tested the solutions in a VM. I could only test that the session appeared in GDM, not that nvidia-offload does work.

Here the two solutions that seems to work:

the “all in hyprland” solution, with the downside of having to recompile hyprland:

let
  # Based on https://github.com/hyprwm/Hyprland/blob/93d05114716e847c37f49d3cc2d0c5cb01d06a24/example/hyprland.desktop
  hyprland-nvidia-session = pkgs.makeDesktopItem {
    name = "Hyprland-nvidia";
    desktopName = "Hyprland-nvidia";
    comment = "An intelligent dynamic tiling Wayland compositor (with more nvidia)";
    exec = "nvidia-offload Hyprland";
  };
in
{
  programs.hyprland = {
    enable = true;
    package = pkgs.hyprland.overrideAttrs (old: {
    postFixup = (old.postFixup or "") + ''
      cp -r ${hyprland-nvidia-session}/share/applications/* $out/share/wayland-sessions/
    '';
  });
  };
}

And the external solution, a bit more verbose but with the advantage of not recompiling hyprland:

let
  # Based on https://github.com/hyprwm/Hyprland/blob/93d05114716e847c37f49d3cc2d0c5cb01d06a24/example/hyprland.desktop
   hyprland-nvidia-session = pkgs.writeTextFile {
    name = "hyprland-nvidia.desktop";
    destination = "/share/wayland-sessions/hyprland-nvidia.desktop";
    text = ''
      [Desktop Entry]
      Comment=An intelligent dynamic tiling Wayland compositor (with more nvidia)
      Exec=nvidia-offload Hyprland
      Name=Hyprland-nvidia
      Type=Application
      Version=1.4
    '';
    checkPhase = ''${pkgs.buildPackages.desktop-file-utils}/bin/desktop-file-validate "$target"'';
    derivationArgs = { passthru.providedSessions = [ "hyprland-nvidia" ]; };
  };
in
{
  services.xserver.displayManager.sessionPackages = [ hyprland-nvidia-session ];
}

The last solution works perfectly.
Thank you very much for your nice response and patience.