Skip to content

Commit

Permalink
Add support for updating Mix dependencies for Elixir projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin authored and mergify[bot] committed Jul 29, 2024
1 parent 2c1937e commit f6f817b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ designed to work with nixpkgs but also other package sets.
- update buildNpmPackage's npmDepsHash and npmConfigHook's npmDeps
- update buildComposerProject's vendorHash
- update buildMavenPackage's mvnHash
- update mixRelease's mixFodDeps
- update fetchYarnDeps offlineCache output hash
- update flake outputs (see `--flake`)
- build and run the resulting package (see `--build`,
Expand Down
2 changes: 2 additions & 0 deletions nix_update/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Package:
yarn_deps: str | None
composer_deps: str | None
maven_deps: str | None
mix_deps: str | None
tests: list[str]
has_update_script: bool

Expand Down Expand Up @@ -189,6 +190,7 @@ def eval_expression(
pnpm_deps = pkg.pnpmDeps.outputHash or null;
yarn_deps = pkg.offlineCache.outputHash or null;
maven_deps = pkg.fetchedMavenDeps.outputHash or null;
mix_deps = pkg.mixFodDeps.outputHash or null;
tests = builtins.attrNames (pkg.passthru.tests or {{}});
has_update_script = {has_update_script};
src_homepage = pkg.src.meta.homepage or null;
Expand Down
8 changes: 8 additions & 0 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ def update_maven_deps_hash(opts: Options, filename: str, current_hash: str) -> N
replace_hash(filename, current_hash, target_hash)


def update_mix_deps_hash(opts: Options, filename: str, current_hash: str) -> None:
target_hash = nix_prefetch(opts, "mixFodDeps")
replace_hash(filename, current_hash, target_hash)


def update_version(
package: Package, version: str, preference: VersionPreference, version_regex: str
) -> bool:
Expand Down Expand Up @@ -399,6 +404,9 @@ def update(opts: Options) -> Package:
if package.maven_deps:
update_maven_deps_hash(opts, package.filename, package.maven_deps)

if package.mix_deps:
update_mix_deps_hash(opts, package.filename, package.mix_deps)

if isinstance(package.cargo_lock, CargoLockInSource) or isinstance(
package.cargo_lock, CargoLockInStore
):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_mix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess

import conftest

from nix_update.options import Options
from nix_update.update import update


def test_update(helpers: conftest.Helpers) -> None:
with helpers.testpkgs() as path:
opts = Options(attribute="mix", import_path=str(path))
update(opts)
mix_hash = subprocess.run(
[
"nix",
"eval",
"--raw",
"--extra-experimental-features",
"nix-command",
"-f",
path,
"mix.mixFodDeps.outputHash",
],
text=True,
stdout=subprocess.PIPE,
).stdout.strip()
assert mix_hash != "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
1 change: 1 addition & 0 deletions tests/testpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
npm-package = pkgs.callPackage ./npm-package.nix { };
pnpm = pkgs.callPackage ./pnpm.nix { };
maven = pkgs.callPackage ./maven.nix { };
mix = pkgs.callPackage ./mix.nix { };
}
18 changes: 18 additions & 0 deletions tests/testpkgs/mix.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ beamPackages, fetchFromGitHub }:

beamPackages.mixRelease rec {
pname = "credo-language-server";
version = "0.2.0";

src = fetchFromGitHub {
owner = "elixir-tools";
repo = "credo-language-server";
rev = "refs/tags/v${version}";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};

mixFodDeps = beamPackages.fetchMixDeps {
inherit pname version src;
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
}

0 comments on commit f6f817b

Please sign in to comment.