From ab1efec921059810dc83dd3f19844d95e9b1ca5e Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Mon, 2 Jun 2025 10:48:02 +0100 Subject: [PATCH] charmcraft: override `craft-application` to use v4 `craft-application` has been bumped to version 5, which both `snapcraft` and `rockcraft` have updated to use, but `charmcraft` has yet to make the transition. This change essentially just overrides the single dependency to the supported version just for this package, thus unblocking the evolution of other dependencies in nixpkgs. --- pkgs/by-name/ch/charmcraft/package.nix | 66 +++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/pkgs/by-name/ch/charmcraft/package.nix b/pkgs/by-name/ch/charmcraft/package.nix index ec94207f8d56..da442fc12d58 100644 --- a/pkgs/by-name/ch/charmcraft/package.nix +++ b/pkgs/by-name/ch/charmcraft/package.nix @@ -1,12 +1,54 @@ { lib, git, - python3Packages, + python3, fetchFromGitHub, nix-update-script, + testers, + charmcraft, + cacert, }: +let + python = python3.override { + self = python; + packageOverrides = self: super: { + craft-application = super.craft-application.overridePythonAttrs (old: rec { + version = "4.10.0"; + src = fetchFromGitHub { + owner = "canonical"; + repo = "craft-application"; + tag = version; + hash = "sha256-9M49/XQuWwKuQqseleTeZYcrwd/S16lNCljvlVsoXbs="; + }; -python3Packages.buildPythonApplication rec { + patches = [ ]; + + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail "setuptools==75.8.0" "setuptools" + + substituteInPlace craft_application/git/_git_repo.py \ + --replace-fail "/snap/core22/current/etc/ssl/certs" "${cacert}/etc/ssl/certs" + ''; + + preCheck = '' + export HOME=$(mktemp -d) + + # Tests require access to /etc/os-release, which isn't accessible in + # the test environment, so create a fake file, and modify the code + # to look for it. + echo 'ID=nixos' > $HOME/os-release + echo 'NAME=NixOS' >> $HOME/os-release + echo 'VERSION_ID="24.05"' >> $HOME/os-release + + substituteInPlace craft_application/util/platforms.py \ + --replace-fail "os_utils.OsRelease()" "os_utils.OsRelease(os_release_file='$HOME/os-release')" + ''; + }); + }; + }; +in +python.pkgs.buildPythonApplication rec { pname = "charmcraft"; version = "3.4.6"; @@ -23,7 +65,7 @@ python3Packages.buildPythonApplication rec { substituteInPlace charmcraft/__init__.py --replace-fail "dev" "${version}" ''; - dependencies = with python3Packages; [ + dependencies = with python.pkgs; [ craft-application craft-cli craft-parts @@ -47,7 +89,7 @@ python3Packages.buildPythonApplication rec { urllib3 ]; - build-system = with python3Packages; [ setuptools-scm ]; + build-system = with python.pkgs; [ setuptools-scm ]; pythonRelaxDeps = [ "urllib3" @@ -57,7 +99,7 @@ python3Packages.buildPythonApplication rec { ]; nativeCheckInputs = - with python3Packages; + with python.pkgs; [ freezegun hypothesis @@ -69,7 +111,10 @@ python3Packages.buildPythonApplication rec { responses setuptools ] - ++ [ git ]; + ++ [ + cacert + git + ]; preCheck = '' mkdir -p check-phase @@ -85,7 +130,14 @@ python3Packages.buildPythonApplication rec { "test_read_charm_from_yaml_file_self_contained_success[full-platforms.yaml]" ]; - passthru.updateScript = nix-update-script { }; + passthru = { + updateScript = nix-update-script { }; + tests.version = testers.testVersion { + package = charmcraft; + command = "env SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt HOME=$(mktemp -d) charmcraft --version"; + version = "charmcraft ${version}"; + }; + }; meta = { mainProgram = "charmcraft";