From b67847e7eb7a0ec487de29f0d9355fcebf5db6ab Mon Sep 17 00:00:00 2001 From: Austreelis Date: Sat, 4 Oct 2025 00:40:05 +0000 Subject: [PATCH] fix: Correctly resolve packages from `preferences.packages.version` (#33) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this, a value that does not correspond to an attribute under a package alias' `versions` would make it default to the latest as defined by `lib.packages.getLatest`, which isn't a silver bullt: it choose "bash5.2.15-bootstrap" for instance instead of stage1-passthrough (and I don;t think we have an easy fix for that). Given values like `"1.2.3"` makes little sense in `config.preferences.packages.version` (because it's a package-set-wide preference), this means it was hardly ever useful. before: ```console ❯ nix eval -f tidepool --apply 't: t.extend {modules = [{config.preferences.packages.version = "latest";}];} |> (t: t.config.lib.packages.resolve t.config.packages.foundation.bash) |> (p: p.version)' "5.2.15-bootstrap" ❯ nix eval -f tidepool --apply 't: t.extend {modules = [{config.preferences.packages.version = "stable";}];} |> (t: t.config.lib.packages.resolve t.config.packages.foundation.bash) |> (p: p.version)' "5.2.15-bootstrap" ``` after: ```console ❯ nix eval -f tidepool --apply 't: t.extend {modules = [{config.preferences.packages.version = "latest";}];} |> (t: t.config.lib.packages.resolve t.config.packages.foundation.bash) |> (p: p.version)' "5.2.15-stage1-passthrough" ❯ nix eval -f tidepool --apply 't: t.extend {modules = [{config.preferences.packages.version = "stable";}];} |> (t: t.config.lib.packages.resolve t.config.packages.foundation.bash) |> (p: p.version)' "5.2.15-bootstrap" ``` Co-authored-by: austreelis Reviewed-on: https://git.auxolotl.org/auxolotl/labs/pulls/33 Reviewed-by: Ruby Iris Juric Co-authored-by: Austreelis Co-committed-by: Austreelis --- tidepool/src/lib/packages.nix | 17 ++++++++++++++--- tidepool/src/lib/types.nix | 3 +++ tidepool/src/packages/default.nix | 5 +---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tidepool/src/lib/packages.nix b/tidepool/src/lib/packages.nix index fafb17d..af91689 100644 --- a/tidepool/src/lib/packages.nix +++ b/tidepool/src/lib/packages.nix @@ -243,11 +243,22 @@ in in outputs; + WELL_KNOWN_ALIASES = [ + # NOTE: When adding a version alias here, update lib.types.alias and lib.types.platforms' alias sub-option + "stable" + "latest" + ]; + resolve = alias: - if alias ? versions then - alias.versions.${config.preferences.packages.version} - or (alias.versions.${lib.packages.getLatest alias}) + let + prefered = config.preferences.packages.version; + isWellKnown = builtins.elem prefered lib.packages.WELL_KNOWN_ALIASES; + in + if isWellKnown && alias ? ${prefered} then + alias.${prefered} + else if alias ? versions then + alias.versions.${prefered} or (alias.versions.${lib.packages.getLatest alias}) else alias; diff --git a/tidepool/src/lib/types.nix b/tidepool/src/lib/types.nix index a34b42d..9ca3b01 100644 --- a/tidepool/src/lib/types.nix +++ b/tidepool/src/lib/types.nix @@ -307,6 +307,7 @@ in type = lib.types.artifact; default.value = null; }; + # NOTE: When adding a version alias here, update lib.packages.WELL_KNOWN_ALIASES versions = lib.options.create { description = "Available versions of the artifact."; type = lib.types.attrs.of lib.types.artifact; @@ -401,6 +402,8 @@ in if config.versions == { } then null else config.versions.${lib.packages.getLatest config}; }; + # NOTE: When adding a version alias here, update lib.packages.WELL_KNOWN_ALIASES + versions = lib.options.create { description = "Available versions of the package."; type = lib.types.attrs.of lib.types.package; diff --git a/tidepool/src/packages/default.nix b/tidepool/src/packages/default.nix index f92eeaf..e30188b 100644 --- a/tidepool/src/packages/default.nix +++ b/tidepool/src/packages/default.nix @@ -37,10 +37,7 @@ in preferences.packages = { version = lib.options.create { description = "The preferred package version when using aliases."; - type = lib.types.enum [ - "latest" - "stable" - ]; + type = lib.types.enum lib.packages.WELL_KNOWN_ALIASES; default.value = "latest"; };