fix(nixery): allow references to packages starting with numbers

These packages are invalid in Nix, and worked around in nixpkgs with
underscores, but the underscores are invalid in the Docker registry
protocol.

We work around this by detecting this case and adding the underscore
to yield the correct package reference. There is no case where this
workaround can break something, as there can be no valid package
matching the regular expression.

This relates to https://github.com/tazjin/nixery/issues/158

Change-Id: I7990cdb534a8e86c2ceee2c589a2636af70a4a03
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8531
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Vincent Ambo 2023-04-28 17:16:57 +03:00 committed by tazjin
parent b58f6f1d61
commit 2464ea7303

View file

@ -13,7 +13,7 @@
{ {
# Description of the package set to be used (will be loaded by load-pkgs.nix) # Description of the package set to be used (will be loaded by load-pkgs.nix)
srcType ? "nixpkgs" srcType ? "nixpkgs"
, srcArgs ? "nixos-20.09" , srcArgs ? "nixos-unstable"
, system ? "x86_64-linux" , system ? "x86_64-linux"
, importArgs ? { } , importArgs ? { }
, # Path to load-pkgs.nix , # Path to load-pkgs.nix
@ -89,6 +89,19 @@ let
in in
attrByPath path fetchLower s; attrByPath path fetchLower s;
# Workaround for a workaround in nixpkgs: Unquoted language
# identifiers can not start with numbers in Nix, but some package
# names start with numbers (such as `1password`).
#
# In nixpkgs convention, these identifiers are prefixed with
# underscores (e.g. `_1password`), however this is not accepted by
# the Docker registry protocol.
#
# To make this work, we detect these kinds of packages and add the
# missing underscore.
needsUnderscore = pkg: (builtins.match "^[0-9].*" pkg) != null;
normalisedPackages = map (p: if needsUnderscore p then "_${p}" else p) (fromJSON packages);
# allContents contains all packages successfully retrieved by name # allContents contains all packages successfully retrieved by name
# from the package set, as well as any errors encountered while # from the package set, as well as any errors encountered while
# attempting to fetch a package. # attempting to fetch a package.
@ -104,7 +117,7 @@ let
then attrs // { errors = attrs.errors ++ [ res ]; } then attrs // { errors = attrs.errors ++ [ res ]; }
else attrs // { contents = attrs.contents ++ [ res ]; }; else attrs // { contents = attrs.contents ++ [ res ]; };
init = { contents = [ ]; errors = [ ]; }; init = { contents = [ ]; errors = [ ]; };
fetched = (map (deepFetch pkgs) (fromJSON packages)); fetched = (map (deepFetch pkgs) normalisedPackages);
in in
foldl' splitter init fetched; foldl' splitter init fetched;