-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.nix
152 lines (149 loc) · 4.92 KB
/
lib.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{
lib,
stdenv,
poetry2nix,
lzo,
python310,
mkShellNoCC,
poetry,
runCommand,
libiconv,
darwin,
rustPlatform,
...
}:
let
poetryOverrides = [
# https://github.com/nix-community/poetry2nix/pull/899#issuecomment-1620306977
poetry2nix.defaultPoetryOverrides
(self: super: {
python-lzo = super.python-lzo.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ lzo ];
});
scriv = super.scriv.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.setuptools ];
});
backports-tarfile = super.backports-tarfile.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.setuptools ];
});
docutils = super.docutils.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.flit-core ];
});
execnet = super.execnet.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.hatchling super.hatch-vcs ];
});
pygments = super.pygments.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.hatchling super.hatch-vcs ];
});
attrs = super.attrs.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.hatchling super.hatch-vcs super.hatch-fancy-pypi-readme ];
});
urllib3 = super.urllib3.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.hatchling super.hatch-vcs ];
});
consulate-fc-nix-test = super.consulate-fc-nix-test.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.setuptools super.setuptools-scm ];
});
yarl = super.yarl.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.tomli ];
});
frozenlist = super.frozenlist.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.tomli ];
});
shortuuid = super.shortuuid.overrideAttrs (old: {
# replace poetry to avoid dependency on vulnerable python-cryptography package
nativeBuildInputs = [ super.poetry-core ] ++ builtins.filter (p: p.pname or "" != "poetry") old.nativeBuildInputs;
});
aiofiles = super.aiofiles.overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [ super.hatchling super.hatch-vcs ];
});
nh3 =
let
getCargoHash = version: {
"0.2.17" = "sha256-WomlVzKOUfcgAWGJInSvZn9hm+bFpgc4nJbRiyPCU64=";
}.${version} or (
lib.warn "Unknown nh3 version: '${version}'. Please update getCargoHash." lib.fakeHash
);
in
super.nh3.overridePythonAttrs (old: {
cargoDeps = rustPlatform.fetchCargoTarball {
inherit (old) src;
name = "${old.pname}-${old.version}";
hash = getCargoHash old.version;
};
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];
buildInputs = (old.buildInputs or [ ]) ++ lib.optional stdenv.isDarwin [
libiconv
darwin.apple_sdk.frameworks.Security
];
});
cryptography =
let
getCargoHash = version: {
"42.0.5" = "sha256-Pw3ftpcDMfZr/w6US5fnnyPVsFSB9+BuIKazDocYjTU=";
}.${version} or (
lib.warn "Unknown cryptography version: '${version}'. Please update getCargoHash." lib.fakeHash
);
sha256 = getCargoHash super.cryptography.version;
isWheel = lib.hasSuffix ".whl" super.cryptography.src;
in
super.cryptography.overridePythonAttrs (old:
lib.optionalAttrs (lib.versionAtLeast old.version "3.5" && !isWheel) {
cargoDeps =
rustPlatform.fetchCargoTarball {
inherit (old) src;
sourceRoot = "${old.pname}-${old.version}/${old.cargoRoot}";
name = "${old.pname}-${old.version}";
inherit sha256;
};
}
);
})
];
poetryEnv = poetry2nix.mkPoetryEnv {
projectDir = ./.;
python = python310;
overrides = poetryOverrides;
editablePackageSources = {
backy = ./src;
};
};
poetryApplication = poetry2nix.mkPoetryApplication {
projectDir = ./.;
doCheck = true;
python = python310;
overrides = poetryOverrides;
};
in
{
packages = {
default = poetryApplication;
venv = poetryEnv;
};
devShells = {
default = mkShellNoCC {
BACKY_CLI_CMD = "${poetryEnv}/bin/backy";
BACKY_RBD_CMD = "${poetryEnv}/bin/backy-rbd";
packages = [
poetryEnv
poetry
];
};
};
checks = {
pytest = runCommand "pytest" {
nativeBuildInputs = [ poetryEnv ];
src = ./.;
} ''
unpackPhase
cd $sourceRoot
export BACKY_CMD=${poetryApplication}/bin/backy
patchShebangs src
pytest -vv -p no:cacheprovider --no-cov
touch $out
'';
};
}