From ac5b19cb0e7bdd24c472ebae461f01dcbfa237eb Mon Sep 17 00:00:00 2001 From: Silvestre Zabala Date: Wed, 25 Sep 2024 13:44:56 +0200 Subject: [PATCH] chore(asdf2devbox): Only update to latest if no previous version is installed # Issue If a version of a program was not packaged in NixOS, `asdf2devbox` would update to latest which might increase the version skew. E.g. Go 1.22.4 is not packaged in NixOS, updating to it would update to `go@latest` which might be Go 1.23 - in effect a major version upgrade. # Fix asdf2devbox does not update if a version was already referenced in devbox, to minimize version skew. --- scripts/asdf2devbox.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/asdf2devbox.py b/scripts/asdf2devbox.py index 34712f9d95..f11ee30e66 100755 --- a/scripts/asdf2devbox.py +++ b/scripts/asdf2devbox.py @@ -43,9 +43,15 @@ def get_installed_version(package): try: subprocess.run(['devbox', 'add', f"{program}@{version}"], check=True) except subprocess.CalledProcessError: - # Fallback to latest in case the exact version is not available - subprocess.run(['devbox', 'add', f"{program}@latest"], check=True) - print(f"Could not find {program}@{version}, using latest instead:") + # Fallback to latest in case the exact version is not available and there's no previous version installed + if installed_version is None: + print(f"Could not find {program}@{version}, using latest instead") + subprocess.run(['devbox', 'add', f"{program}@latest"], check=True) + else: + # Readd the previously installed version + print(f"Could not find {program}@{version}, readding {program}@{installed_version}") + subprocess.run(['devbox', 'add', f"{program}@{installed_version}"], check=True) + subprocess.run(['devbox', 'info', program], check=True) else: print(f"{program}@{version} is already installed")