forked from luther7/nix-flake-python-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
84 lines (70 loc) · 1.97 KB
/
flake.nix
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
description = "My Python application";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
mach-nix = {
url = "github:DavHau/mach-nix/3.3.0";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.pypi-deps-db.follows = "pypi-deps-db";
};
pypi-deps-db = {
url = "github:DavHau/mach-nix/3.3.0";
};
};
outputs = { self, nixpkgs, flake-utils, mach-nix, pypi-deps-db }:
flake-utils.lib.eachDefaultSystem (system:
let
python = "python39";
inherit (nixpkgs.lib) concatStringsSep;
pkgs = import nixpkgs { inherit system; };
mach = import mach-nix { inherit pkgs python; };
devRequirements = ''
black
flake8
isort
mypy
pytest
'';
prodRequirements = ''
click
pip
'';
freeze = ''
mkdir -p $out
export out_file=$out/requirements.txt
pip list --format=freeze > $out/requirements.txt
'';
devPython = mach.mkPython {
requirements = concatStringsSep "\n" [
prodRequirements
devRequirements
];
};
prodPython = mach.mkPython { requirements = prodRequirements; };
in
rec {
packages.prod = mach.buildPythonPackage {
src = ./.;
requirements = prodRequirements;
};
defaultPackage = packages.prod;
packages.devRequirements = pkgs.runCommand "dev_requirements"
{
buildInputs = [ devPython ];
}
freeze;
packages.prodRequirements = pkgs.runCommand "prod_requirements"
{
buildInputs = [ prodPython ];
}
freeze;
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
fd
pyright
] ++ [ devPython ];
};
});
}