aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: 3c153d396d4175f75ea88fb1f670f6e284eb5812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{
  description = "A very basic flake for developing in python";
  # Provides abstraction to boiler-code when specifying multi-platform outputs.
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:nixos/nixpkgs";
  };
  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = nixpkgs.legacyPackages.${system};
      venvDir = "./.venv";
      pythonPackages = pkgs.python38Packages;
    in {
      devShell = pkgs.mkShell {
        nativeBuildInputs = with pkgs; [
          hello
          pythonPackages.python
        ];
        shellHook = ''
          SOURCE_DATE_EPOCH=$(date +%s)

          if [ -d "${venvDir}" ]; then
            echo "Skipping venv creation, '${venvDir}' already exists"
          else
            echo "Creating new venv environment in path: '${venvDir}'"
            # Note that the module venv was only introduced in python 3, so for 2.7
            # this needs to be replaced with a call to virtualenv
            ${pythonPackages.python.interpreter} -m venv "${venvDir}"
          fi

          # Under some circumstances it might be necessary to add your virtual
          # environment to PYTHONPATH, which you can do here too;
          # PYTHONPATH=$PWD/${venvDir}/${pythonPackages.python.sitePackages}/:$PYTHONPATH

          source "${venvDir}/bin/activate"

          # As in the previous example, this is optional.
          pip install -r requirements.txt
        '';
      };
    });
}