-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
100 lines (92 loc) · 2.79 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{
description = "Python SHV Tree";
inputs = {
pyshv.url = "git+https://gitlab.com/silicon-heaven/pyshv";
};
outputs = {
self,
flake-utils,
nixpkgs,
pyshv,
}: let
inherit (builtins) match;
inherit (flake-utils.lib) eachDefaultSystem filterPackages;
inherit (nixpkgs.lib) head foldl trivial hasSuffix attrValues getAttrs composeManyExtensions;
pyproject = trivial.importTOML ./pyproject.toml;
inherit (pyproject.project) name version;
src = builtins.path {
path = ./.;
filter = path: _: ! hasSuffix ".nix" path;
};
pypi2nix = list: pypkgs:
attrValues (getAttrs (map (n: let
pyname = head (match "([^ =<>;]*).*" n);
pymap = {
"ruamel.yaml" = "ruamel-yaml";
};
in
pymap."${pyname}" or pyname)
list)
pypkgs);
requires = pypi2nix pyproject.project.dependencies;
requires-test = pypi2nix pyproject.project.optional-dependencies.test;
requires-docs = pypi2nix pyproject.project.optional-dependencies.docs;
pypackage = {
buildPythonPackage,
pytestCheckHook,
pythonPackages,
setuptools,
sphinxHook,
}:
buildPythonPackage {
pname = pyproject.project.name;
inherit version src;
pyproject = true;
build-system = [setuptools];
outputs = ["out" "doc"];
propagatedBuildInputs = requires pythonPackages;
nativeBuildInputs = [sphinxHook] ++ requires-docs pythonPackages;
nativeCheckInputs = [pytestCheckHook] ++ requires-test pythonPackages;
};
in
{
overlays = {
pythonPackagesExtension = final: _: {
"${name}" = final.callPackage pypackage {};
};
noInherit = _: prev: {
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [self.overlays.pythonPackagesExtension];
};
default = composeManyExtensions [
self.overlays.noInherit
pyshv.overlays.default
];
};
}
// eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system}.extend self.overlays.default;
in {
packages.default = pkgs.python3Packages."${name}";
legacyPackages = pkgs;
devShells = filterPackages system {
default = pkgs.mkShell {
packages = with pkgs; [
editorconfig-checker
statix
deadnix
gitlint
ruff
(python3.withPackages (p:
[p.build p.twine p.sphinx-autobuild p.mypy]
++ foldl (prev: f: prev ++ f p) [] [
requires
requires-docs
requires-test
]))
];
};
};
checks.default = self.packages.${system}.default;
formatter = pkgs.alejandra;
});
}