user12345432109890
user12345432109890

Reputation: 83

(Replit) Nix: How do I add a package to .nix?

Edit: Solution


I have a python script, and I need to run the script by running python3 myscript.py, however I get this message:

python3: command not installed. Multiple versions of this command were found in Nix.

And then when choosing the .out, python starts.

I found out I need to add python3 to .nix so that nix can automatically run python39Full if I type python3, in order to skip the message above.

Add 'python39Full' to replit.nix if you want to install 'python3' in this repl.

Unfortunately, I don't know how to add a package to .nix, so can anyone please tell me how to add a package to .nix? thanks.

(In case you need to see the .nix file)

replit.nix

{ pkgs }: {
    deps = [
        pkgs.bashInteractive
    ];
}

Upvotes: 2

Views: 4126

Answers (1)

user12345432109890
user12345432109890

Reputation: 83

Fortunately, I have found a way to add packages to .nix (at least on replit):


If you would like to skip the following message:

python3: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
> 
qtile.out
python39Full.out
python38Full.out
python3Minimal.out
python310.out
python37Full.out
python37.out
python38.out
sourcehut.python.out
python36.out

  1. Get the package name you would like nix to automatically choose (I will use python39Full.out in my case)

  1. Open the .nix file, which would look something like this:

replit.nix

{ pkgs }: {
    deps = [
        pkgs.bashInteractive
    ];
}

  1. Add the package name to .nix, so the .nix would now look something like this:

replit.nix

{ pkgs }: {
    deps = [
        pkgs.bashInteractive
        python39Full.out
    ];
}

  1. Add 'pkgs.' in the beginning of the package name, and remove '.out' from the package name, so the .nix file is now:

replit.nix

{ pkgs }: {
    deps = [
        pkgs.bashInteractive
        pkgs.python39Full
    ];
}

  1. Save the file, and the next time you run python3, nix will not ask you everytime and it will automatically start python 3.9 for you.

Demo

john@doe:~$ python3 
Python 3.9.6 (default, Jun 28 2021, 08:57:49) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Upvotes: 4

Related Questions