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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# Save this file as: ./flake.nix
{
inputs = {
flakeUtils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs";
pythonOnNix.url = "github:on-nix/python/d8a7fa21b76ac3b8a1a3fedb41e86352769b09ed";
pythonOnNix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, ... } @ inputs:
inputs.flakeUtils.lib.eachSystem [ "x86_64-linux" ] (system:
let
nixpkgs = inputs.nixpkgs.legacyPackages.${system};
pythonOnNix = inputs.pythonOnNix.lib.${system};
env = pythonOnNix.python37Env {
name = "example";
projects = {
"pyjwt" = "2.1.0";
# You can add more projects here as you need
# "a" = "1.0";
# "b" = "2.0";
# ...
};
};
# `env` has two attributes:
# - dev: The activation script for the Python on Nix environment
# - out: The raw contents of the Python site-packages
in
{
devShells = {
# The activation script can be used as dev-shell
shell = env.dev;
};
packages = {
# You can also use with Nixpkgs
example = nixpkgs.stdenv.mkDerivation {
# Let's use the activation script as build input
# so the Python environment is loaded
buildInputs = [ env.dev ];
virtualEnvironment = env.out;
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
# pyjwt will be available here!
touch $out
'';
name = "example";
};
};
}
);
}
# Usage:
# First add your changes:
# $ git add flake.nix
#
# Dev Shell:
# $ nix develop .#shell
#
# Build example:
# $ nix build .#example
|