1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 nix-update-script,
6 packaging,
7 platformdirs,
8 pydantic_1,
9 pyyaml,
10 requests-unixsocket,
11 setuptools,
12 setuptools-scm,
13 urllib3,
14 pytest-check,
15 pytest-mock,
16 pytestCheckHook,
17 responses,
18 freezegun,
19 pytest-subprocess,
20 pytest-logdog,
21}:
22
23buildPythonPackage rec {
24 pname = "craft-providers";
25 version = "1.24.1";
26
27 pyproject = true;
28
29 src = fetchFromGitHub {
30 owner = "canonical";
31 repo = "craft-providers";
32 rev = "refs/tags/${version}";
33 hash = "sha256-l57Y+sdCD0/3sBK48N/3p3ns3o0LB4h9FQ35ha1AOV4=";
34 };
35
36 patches = [
37 # This lib will try to inject snaps *from the host system* into the build
38 # system. This patch short-circuits that logic and ensures that snaps are
39 # installed on the build system from the snap store - because there is no
40 # snapd on NixOS hosts that can be used for the injection. This patch will
41 # likely never be accepted upstream.
42 ./inject-snaps.patch
43 ];
44
45 postPatch = ''
46 substituteInPlace craft_providers/lxd/installer.py \
47 --replace-fail "/var/snap/lxd/common/lxd/unix.socket" "/var/lib/lxd/unix.socket"
48
49 substituteInPlace craft_providers/__init__.py \
50 --replace-fail "dev" "${version}"
51
52 # The urllib3 incompat: https://github.com/msabramo/requests-unixsocket/pull/69
53 # This is already patched in nixpkgs.
54 substituteInPlace pyproject.toml \
55 --replace-fail "setuptools==" "setuptools>=" \
56 --replace-fail "urllib3<2" "urllib3"
57 '';
58
59 pythonRelaxDeps = [ "requests" ];
60
61 nativeBuildInputs = [
62 setuptools
63 setuptools-scm
64 ];
65
66 propagatedBuildInputs = [
67 packaging
68 platformdirs
69 pydantic_1
70 pyyaml
71 requests-unixsocket
72 urllib3
73 ];
74
75 pythonImportsCheck = [ "craft_providers" ];
76
77 nativeCheckInputs = [
78 freezegun
79 pytest-check
80 pytest-mock
81 pytest-subprocess
82 pytest-logdog
83 pytestCheckHook
84 responses
85 ];
86
87 preCheck = ''
88 mkdir -p check-phase
89 export HOME="$(pwd)/check-phase"
90 '';
91
92 pytestFlagsArray = [ "tests/unit" ];
93
94 disabledTestPaths = [
95 # Relies upon "logassert" python package which isn't in nixpkgs
96 "tests/unit/bases/test_ubuntu_buildd.py"
97 "tests/unit/bases/test_centos_7.py"
98 "tests/unit/bases/test_almalinux.py"
99 "tests/unit/actions/test_snap_installer.py"
100 # Relies upon "pytest-time" python package which isn't in nixpkgs
101 "tests/unit/multipass"
102 "tests/unit/lxd"
103 "tests/unit/test_base.py"
104 "tests/unit/util/test_retry.py"
105 ];
106
107 passthru.updateScript = nix-update-script { };
108
109 meta = {
110 description = "Interfaces for instantiating and controlling a variety of build environments";
111 homepage = "https://github.com/canonical/craft-providers";
112 changelog = "https://github.com/canonical/craft-providers/releases/tag/${version}";
113 license = lib.licenses.lgpl3Only;
114 maintainers = with lib.maintainers; [ jnsgruk ];
115 platforms = lib.platforms.linux;
116 };
117}