Run custom bash commands in configuration.nix

Hello, i want to enable CUDA, but not use nix-shell, but i need to use this command

shellHook = ''
      export CUDA_PATH=${pkgs.cudatoolkit}
      export LD_LIBRARY_PATH=/usr/lib/wsl/lib:${pkgs.linuxPackages.nvidia_x11}/lib:${pkgs.ncurses5}/lib
      export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
      export EXTRA_CCFLAGS="-I/usr/include"
   '';

What is the alternative in the pure configuration.nix file? Cannot find the option.

Use dev shells, that’t what they’re meant for. And definitely do not set LD_LIBRARY_PATH.

So i cannot install this as permanent? Only entering the shell?

Installing libraries globally is not the intended usecase for NixOS. Of course there are ways to make using dev shells easier, e.g. nix-direnv can automatically enter the dev shell when you’re in the project dir.

1 Like

You could do something insane and put them enviroment.variables, you could do something marginally less insane and add them to sessionVariables under home-manager,. but really you actually want a shell.nix or whatever the flake equivalent is so that you aren’t carrying this around everywhere, but instead access it when you are presumably developing with cuda / curses.

1 Like