Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / pkgs / by-name / sn / snapcraft / package.nix
blob1af08c97fd1af088cc0349f4f255148e8a8eaad7
2   fetchFromGitHub,
3   git,
4   glibc,
5   lib,
6   makeWrapper,
7   nix-update-script,
8   python3,
9   squashfsTools,
10   stdenv,
13 let
14   python = python3.override {
15     packageOverrides = self: super: {
16       pydantic-yaml = super.pydantic-yaml.overridePythonAttrs (old: rec {
17         version = "0.11.2";
18         src = fetchFromGitHub {
19           owner = "NowanIlfideme";
20           repo = "pydantic-yaml";
21           rev = "refs/tags/v${version}";
22           hash = "sha256-AeUyVav0/k4Fz69Qizn4hcJKoi/CDR9eUan/nJhWsDY=";
23         };
24         dependencies = with self; [
25           deprecated
26           importlib-metadata
27           pydantic_1
28           ruamel-yaml
29           types-deprecated
30         ];
31       });
32     };
33   };
35 python.pkgs.buildPythonApplication rec {
36   pname = "snapcraft";
37   version = "8.3.1";
39   pyproject = true;
41   src = fetchFromGitHub {
42     owner = "canonical";
43     repo = "snapcraft";
44     rev = "refs/tags/${version}";
45     hash = "sha256-cdRlUY9hAJ8US93aiJymzsV27JVPY7lWCK7IUdjDmYE=";
46   };
48   patches = [
49     # Snapcraft is only officially distributed as a snap, as is LXD. The socket
50     # path for LXD must be adjusted so that it's at the correct location for LXD
51     # on NixOS. This patch will likely never be accepted upstream.
52     ./lxd-socket-path.patch
53     # In certain places, Snapcraft expects an /etc/os-release file to determine
54     # host info which doesn't exist in our test environment. This is a
55     # relatively naive patch which helps the test suite pass - without it *many*
56     # of the tests fail. This patch will likely never be accepted upstream.
57     ./os-platform.patch
58     # Snapcraft will try to inject itself as a snap *from the host system* into
59     # the build system. This patch short-circuits that logic and ensures that
60     # Snapcraft is installed on the build system from the snap store - because
61     # there is no snapd on NixOS hosts that can be used for the injection. This
62     # patch will likely never be accepted upstream.
63     ./set-channel-for-nix.patch
64     # Certain paths (for extensions, schemas) are packaged in the snap by the
65     # upstream, so the paths are well-known, except here where Snapcraft is
66     # *not* in a snap, so this patch changes those paths to point to the correct
67     # place in the Nix store. This patch will likely never be accepted upstream.
68     ./snapcraft-data-dirs.patch
69   ];
71   postPatch = ''
72     substituteInPlace setup.py \
73       --replace-fail 'version=determine_version()' 'version="${version}"' \
74       --replace-fail 'gnupg' 'python-gnupg'
76     substituteInPlace requirements.txt \
77       --replace-fail 'gnupg==2.3.1' 'python-gnupg'
79     substituteInPlace snapcraft/__init__.py \
80       --replace-fail '__version__ = _get_version()' '__version__ = "${version}"'
82     substituteInPlace snapcraft_legacy/__init__.py \
83       --replace-fail '__version__ = _get_version()' '__version__ = "${version}"'
85     substituteInPlace snapcraft/elf/elf_utils.py \
86       --replace-fail 'arch_linker_path = Path(arch_config.dynamic_linker)' \
87       'return str(Path("${glibc}/lib/ld-linux-x86-64.so.2"))'
89     substituteInPlace pyproject.toml \
90       --replace-fail '"pytest-cov>=4.0",' "" \
91       --replace-fail "--cov=snapcraft" ""
92   '';
94   nativeBuildInputs = [ makeWrapper ];
96   dependencies = with python.pkgs; [
97     attrs
98     catkin-pkg
99     click
100     craft-application
101     craft-archives
102     craft-cli
103     craft-grammar
104     craft-parts
105     craft-providers
106     craft-store
107     debian
108     docutils
109     jsonschema
110     launchpadlib
111     lazr-restfulclient
112     lxml
113     macaroonbakery
114     mypy-extensions
115     overrides
116     packaging
117     progressbar
118     pyelftools
119     pygit2
120     pylxd
121     pymacaroons
122     python-apt
123     python-gnupg
124     pyxdg
125     pyyaml
126     raven
127     requests-toolbelt
128     requests-unixsocket
129     simplejson
130     snap-helpers
131     tabulate
132     toml
133     tinydb
134     typing-extensions
135     urllib3
136     validators
137   ];
139   build-system = with python.pkgs; [ setuptools ];
141   pythonRelaxDeps = [
142     "docutils"
143     "jsonschema"
144     "pygit2"
145     "urllib3"
146     "validators"
147   ];
149   postInstall = ''
150     wrapProgram $out/bin/snapcraft --prefix PATH : ${squashfsTools}/bin
151   '';
153   nativeCheckInputs =
154     with python.pkgs;
155     [
156       pytest-check
157       pytest-mock
158       pytest-subprocess
159       pytestCheckHook
160       responses
161       setuptools
162     ]
163     ++ [
164       git
165       squashfsTools
166     ];
168   preCheck = ''
169     mkdir -p check-phase
170     export HOME="$(pwd)/check-phase"
171   '';
173   pytestFlagsArray = [ "tests/unit" ];
175   disabledTests = [
176     "test_bin_echo"
177     "test_classic_linter_filter"
178     "test_classic_linter"
179     "test_complex_snap_yaml"
180     "test_core24_try_command"
181     "test_get_base_configuration_snap_channel"
182     "test_get_base_configuration_snap_instance_name_default"
183     "test_get_base_configuration_snap_instance_name_not_running_as_snap"
184     "test_get_extensions_data_dir"
185     "test_get_os_platform_alternative_formats"
186     "test_get_os_platform_linux"
187     "test_get_os_platform_windows"
188     "test_lifecycle_pack_components_with_output"
189     "test_lifecycle_pack_components"
190     "test_lifecycle_write_component_metadata"
191     "test_parse_info_integrated"
192     "test_patch_elf"
193     "test_remote_builder_init"
194     "test_setup_assets_remote_icon"
195     "test_snap_command_fallback"
196     "test_validate_architectures_supported"
197     "test_validate_architectures_unsupported"
198   ] ++ lib.optionals stdenv.isAarch64 [ "test_load_project" ];
200   disabledTestPaths = [
201     "tests/unit/commands/test_remote.py"
202     "tests/unit/elf"
203     "tests/unit/linters/test_classic_linter.py"
204     "tests/unit/linters/test_library_linter.py"
205     "tests/unit/parts/test_parts.py"
206     "tests/unit/services"
207   ];
209   passthru.updateScript = nix-update-script { };
211   meta = {
212     mainProgram = "snapcraft";
213     description = "Build and publish Snap packages";
214     homepage = "https://github.com/canonical/snapcraft";
215     changelog = "https://github.com/canonical/snapcraft/releases/tag/${version}";
216     license = lib.licenses.gpl3Only;
217     maintainers = with lib.maintainers; [ jnsgruk ];
218     platforms = lib.platforms.linux;
219   };