Skip to content

Add host attribute of github/gitlab flakerefs to URL serialization#12580

Merged
edolstra merged 1 commit intoNixOS:masterfrom
ysndr:fix/fetchers/host-in-locked-url
Feb 28, 2025
Merged

Add host attribute of github/gitlab flakerefs to URL serialization#12580
edolstra merged 1 commit intoNixOS:masterfrom
ysndr:fix/fetchers/host-in-locked-url

Conversation

@ysndr
Copy link
Copy Markdown
Member

@ysndr ysndr commented Feb 28, 2025

Motivation

GitArchiveInputScheme::toUrl currently drops the host attribute, creating invalid urls when locking github: or gitlab: urls pointing to alterative instances and serializing the input back to a url.

Context

❯ cat flake.nix
{
  inputs.gnome-2048 = {
    url = "gitlab:GNOME/gnome-2048?host=gitlab.gnome.org";
    flake = false;
  };

  outputs = inputs: {};
}
f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35
❯ nix flake metadata
warning: creating lock file '/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35/flake.lock':
• Added input 'gnome-2048':
    'gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D' (2025-02-21)
Resolved URL:  path:/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35
Locked URL:    path:/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35?lastModified=1740744684&narHash=sha256-nxUL/JiTYbZX2c1XiN/TC6aA1hf%2B1YXsUvhL7ASY2uE%3D
Path:          /nix/store/f4xczpwhdxs8gal1rika1c5bvhyd472l-source
Last modified: 2025-02-28 13:11:24
Inputs:
└───gnome-2048: gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D (2025-02-21 23:18:46)

Note the gnome-2048 input url missing the original host query.

The Url after this commit:

[...]
Inputs:
└───gnome-2048: gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?host=gitlab.gnome.org&narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D (2025-02-21 23:18:46)

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

`GitArchiveInputScheme::toUrl` currently drops the `host` attribute,
creating invalid urls when locking `github:` or `gitlab:` urls pointing to alterative instances and serializing the input back to a url.

```
❯ cat flake.nix
{
  inputs.gnome-2048 = {
    url = "gitlab:GNOME/gnome-2048?host=gitlab.gnome.org";
    flake = false;
  };

  outputs = inputs: {};
}
f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35
❯ nix flake metadata
warning: creating lock file '/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35/flake.lock':
• Added input 'gnome-2048':
    'gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D' (2025-02-21)
Resolved URL:  path:/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35
Locked URL:    path:/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35?lastModified=1740744684&narHash=sha256-nxUL/JiTYbZX2c1XiN/TC6aA1hf%2B1YXsUvhL7ASY2uE%3D
Path:          /nix/store/f4xczpwhdxs8gal1rika1c5bvhyd472l-source
Last modified: 2025-02-28 13:11:24
Inputs:
└───gnome-2048: gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D (2025-02-21 23:18:46)
```

Note the gnome-2048 input url missing the original host query.

The Url after this commit:

```
[...]
Inputs:
└───gnome-2048: gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?host=gitlab.gnome.org&narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D (2025-02-21 23:18:46)
```
@ysndr ysndr requested a review from edolstra as a code owner February 28, 2025 12:15
@github-actions github-actions bot added the fetching Networking with the outside (non-Nix) world, input locking label Feb 28, 2025
ysndr added a commit to flox/flox that referenced this pull request Feb 28, 2025
Backport of upstream PR targeting nix >= 2.27
<NixOS/nix#12580>

When installing `github` or `gitlab` flake refs with an alternative host to an environment,
the environment will fail to build in the general case where the store paths are not substitutable:

```
flox install gitlab:foo/bar?host=gitlab.example.com

❌ ERROR: Failed to build environment:

Failed to realise 'bar':
error:
       … while fetching the input 'gitlab:foo/bar/87687do78you0876ear1eallya2eacd62read77cadthis'

       error: unable to download 'https://gitlab.com/api/v4/projects/foo%2bar/repository/archive.tar.gz?sha= 87687do78you0876ear1eallya2eacd62read77cadthis': HTTP error 404

       response body:

       {"message":"404 Project Not Found"}
```

That is because nix drops the `host` parameter when serializing the locked flakeref to a url.
The included patch adds the `?host` query back to the locked url.
@edolstra edolstra merged commit d8a7c50 into NixOS:master Feb 28, 2025
12 checks passed
mkenigs pushed a commit to flox/flox that referenced this pull request Feb 28, 2025
Backport of upstream PR targeting nix >= 2.27
<NixOS/nix#12580>

When installing `github` or `gitlab` flake refs with an alternative host to an environment,
the environment will fail to build in the general case where the store paths are not substitutable:

```
flox install gitlab:foo/bar?host=gitlab.example.com

❌ ERROR: Failed to build environment:

Failed to realise 'bar':
error:
       … while fetching the input 'gitlab:foo/bar/87687do78you0876ear1eallya2eacd62read77cadthis'

       error: unable to download 'https://gitlab.com/api/v4/projects/foo%2bar/repository/archive.tar.gz?sha= 87687do78you0876ear1eallya2eacd62read77cadthis': HTTP error 404

       response body:

       {"message":"404 Project Not Found"}
```

That is because nix drops the `host` parameter when serializing the locked flakeref to a url.
The included patch adds the `?host` query back to the locked url.
@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-2-29-0-released/64609/1

ysndr added a commit to flox/flox that referenced this pull request Jul 18, 2025
Originally introduced in <#2789>
the patch was merged upstream into master
in February via <NixOS/nix#12580>.
Assuming it was available via Nix in nixpkgs in late June,
we removed the patch in <#3176>,
which bumped our nix distribution to v2.28.2.

It turns out that the upstream patch was only released via nix **2.29.0**,
thus by removing our patch we regressed that behavior.

This commit reintroduces the patch, while we use nix 2.28.3.
tomberek pushed a commit to flox/flox that referenced this pull request Jul 18, 2025
Originally introduced in <#2789>
the patch was merged upstream into master
in February via <NixOS/nix#12580>.
Assuming it was available via Nix in nixpkgs in late June,
we removed the patch in <#3176>,
which bumped our nix distribution to v2.28.2.

It turns out that the upstream patch was only released via nix **2.29.0**,
thus by removing our patch we regressed that behavior.

This commit reintroduces the patch, while we use nix 2.28.3.
ysndr added a commit to flox/flox that referenced this pull request Nov 6, 2025
Drops the patches for 

* NixOS/nix#12580
* NixOS/nix#12642
* NixOS/nix#13340

All three have been merged upstream
in the current release of nix (v2.31.2).
ysndr added a commit to flox/flox that referenced this pull request Nov 6, 2025
Drops the patches for 

* NixOS/nix#12580
* NixOS/nix#12642
* NixOS/nix#13340

All three have been merged upstream
in the current release of nix (v2.31.2).
ysndr added a commit to flox/flox that referenced this pull request Nov 6, 2025
Drops the patches for 

* NixOS/nix#12580
* NixOS/nix#12642
* NixOS/nix#13340

All three have been merged upstream
in the current release of nix (v2.31.2).
ysndr added a commit to flox/flox that referenced this pull request Nov 7, 2025
Drops the patches for 

* NixOS/nix#12580
* NixOS/nix#12642
* NixOS/nix#13340

All three have been merged upstream
in the current release of nix (v2.31.2).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants