Hello,
I am very new to the nix ecosystem so I apologise in advance if my question is already answered somewhere, but after a few hours search I still haven’t found a solution.
Problem background: I connect to a remote workstation using visual studio code and its remote extension. This extensions starts a login shell on the workstation which is a usual bash shell. However, I need to develop in python and for this I need a python interpreter and a few python packages. I can install these packages using nix-env -i imperatively (i.e. from the console) and that works, i.e., they are accessible from the login shell as they are in my user profile. However, I would like to have a nix file that specifies the full environment so that (1) other users can install the same environment and (2) the environment can be started as a nix-shell for testing. In other words, I would like to have a .nix file that I can install as a package in my profile using nix-env -if filename.nix and can also start as a nix-shell using nix-shell filename.nix. The idea is that I would be adding more packages to this expression to make it a complete data science development environment.
what I tried: currently I have the following basic attempt:
with import <nixpkgs> {};
let
py = pkgs.python36;
in
stdenv.mkDerivation rec {
name = "ds-dev-environment";
buildInputs = [
py
py.pkgs.numpy
py.pkgs.pandas
py.pkgs.scipy
];
}
This works when I use nix-shell on it; it drops me into a shell with the buildInputs on the path. However when I try to use nix-env -if it fails because it complains that it doesn’t find a source argument that is passed to the mkDerivation function. As far as I understand this is because nix-env -if is trying to build the nix expression (as opposed to starting a transient shell from it?).
Now looking further into mkDerivation and stdenv I understand that these are especially used to write nix expressions to build a package from source, hence the default parameters and the various phases described in the nixpkgs manual. However in this case I do not have any source; I would rather like to create an expression that I can install as a package with nix-env -if and the only thing it should do is give me a user environment with the python interpreter and the libraries above and all the other packages specified in buildInputs. Kind of like a “meta-package” if you understand what I mean.
Now I tried to play around with the phases in mkDerivation but couldn’t make it work. I also looked at the overlays stuff but it seems rather complicated so I’m not sure if that’s what I need.
Looking forward to someone guiding me here