Pytorch. Nix not working. NixOS works

I can get Pytorch working for NixOS - but the CUDA drivers aren’t visible with Nix running on Debian 11.

Is this to be expected? Or should I try something else, e.g. use pytorch package (and compile…) instead of my current pytorch-bin package?

Nixos (working)

{ pkgs, config, ... }:
{
  imports = [
    <nixpkgs/nixos/modules/virtualisation/google-compute-image.nix>
  ];
  environment.systemPackages = with pkgs; [
                             tmux emacs-nox htop git packer nixos-generators wget mosh

			     nvtop
                             (pkgs.python3.withPackages (ps: with ps; [
                                                        numpy pytorch-bin
                                                        ]))
                             ];

  nixpkgs.config = {
                 allowUnfree = true;
                 cudaSupport = true;
                 };

  services.xserver.videoDrivers = [ "nvidia" ];
  hardware.opengl.enable = true;

}

Nix (not working):

{
  description = "A simple Python developer shell";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      gpu_driver_libs = "/usr/lib/x86_64-linux-gnu";
      pkgs = import nixpkgs {
        inherit system;
        config = {
          allowUnfree = true;
          cudaSupport = true;
          };
        overlays = [];
      };
    in {
      devShells.${system}.default = pkgs.mkShell {
        
        buildInputs = with pkgs; [
          # Include the Python interpreter
          (python3.withPackages (ps: [ ps.numpy ps.pytorch-bin ps.torchvision-bin ps.opencv4 ps.plotext ]))
          nvtopPackages.full
          cudatoolkit
          linuxPackages.nvidia_x11
        ];

        ...
      };
    };
}