Add package from github in shell.nix

I need to create an environment with python 3.7.9 but this version is not in available as package. I found nixpgks-python but I don’t know how to add the github url as build input in my shell.nix script:

{ pkgs ? import <nixpkgs> {} }:

with pkgs;

mkShell {
  buildInputs = [
    ??
  ];
}

I have thoroughly read the documentaion but I can’t see if it’s even possible to do that (I’m fairly new to NixOS and still learning how it works).

Any pointers?

Thanks!

  1. Add nixpkgs-python as a source
  2. use it

Something like this (untested):

{
  pkgs ? import <nixpkgs> {},
  nixpkgs-python ? (builtins.getFlake "github:cachix/nixpkgs-python/01263eeb28c09f143d59cd6b0b7c4cc8478efd48").packages.x86_64-linux
}:

pkgs.mkShell {
  buildInputs = [
    nixpkgs-python."3.12.5"
  ];
}

Thank you @drupol .

I tried running nix-shell with this script in a shell.nix file and I get an error with getFlake:

error: attribute 'getFlake' missing

I’m not using flakes. I don’t quite get how they work.

Have you enabled the experimental flake feature on your system ?

(builtins.getFlake "...") can be replaced with (builtins.fetchGit "https://github.com/cachix/nixpkgs-python.git")

However, there’s some caveats to using that, and I highly recommend moving to some lockfile schema when you can, such as npins, nvfetcher, or yes, flakes.

I didn’t. It works now. Thanks you very much for your help!

Thank you @waffle8946 for your help. I finally did it with flakes