Skip to content

Add user@address:port support#3425

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
mkg20001:pr
Aug 6, 2025
Merged

Add user@address:port support#3425
Ericson2314 merged 1 commit intoNixOS:masterfrom
mkg20001:pr

Conversation

@mkg20001
Copy link
Copy Markdown
Member

@mkg20001 mkg20001 commented Mar 19, 2020

This patch allows users to specify the connection port
in the store URLS like so:

nix store info --store "ssh-ng://localhost:22" --json

Previously this failed with: error: failed to start SSH connection to 'localhost:22',
because the code did not distinguish the port from the hostname. This
patch remedies that problem by introducing a ParsedURL::Authority type
for working with parsed authority components of URIs.

Now that the URL parsing code is less ad-hoc we can
add more long-awaited fixes for specifying SSH connection
ports in store URIs.

Builds upon the work from bd1d2d1.

Fixes #7044.

@edolstra
Copy link
Copy Markdown
Member

Not really opposed to this, but it's a lot of code to support something that can already be achieved via ssh_config.

@mkg20001 mkg20001 changed the title Add user@address:port support (+ more debug logs) Add user@address:port support Apr 25, 2020
@mkg20001 mkg20001 force-pushed the pr branch 2 times, most recently from 356b8ba to 081ad63 Compare April 25, 2020 14:17
@mkg20001
Copy link
Copy Markdown
Member Author

I'll move the additional debug logs to another PR

Right now just IPv6 support is missing

Meanwhile I learned how to C++, so that's why that took so long

@stale
Copy link
Copy Markdown

stale bot commented Feb 13, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 13, 2021
@stale
Copy link
Copy Markdown

stale bot commented Apr 16, 2022

I closed this issue due to inactivity. → More info

@stale stale bot closed this Apr 16, 2022
@tomberek
Copy link
Copy Markdown
Contributor

tomberek commented Oct 5, 2022

Still interested

@tomberek tomberek reopened this Oct 5, 2022
@stale stale bot removed the stale label Oct 5, 2022
@vincentbernat
Copy link
Copy Markdown
Member

There is already code for compression and SSH key, both of them can also be set in ssh_config. One can also use NIX_SSHOPTS. I am also interested into this to make darwin.builder work on another port than 22. I think the idea to support it in the URI of the builder is to avoid messing with too many user files.

@fricklerhandwerk fricklerhandwerk added cli The old and/or new command line interface UX The way in which users interact with Nix. Higher level than UI. and removed cli The old and/or new command line interface labels Mar 3, 2023
@Ericson2314
Copy link
Copy Markdown
Member

Note if we do this, we should also consider doing it with

Use the same notion of a Machine config for remote builders.

from NixOS/hydra#1164

This syntax would be used in the build machines files too, and we don't want that to drift further apart between Nix and Hydra.

@mkg20001
Copy link
Copy Markdown
Member Author

mkg20001 commented Mar 11, 2023

Currently I've got no intention of updating this pr, so feel free to force push / make a new one

(I should mention again I barely know c++ so it would be a pita for me to code this to the end anyways)

@Ericson2314 Ericson2314 marked this pull request as draft March 11, 2023 14:56
@Ericson2314
Copy link
Copy Markdown
Member

OK, very understandable after 3 years! I converted it to a draft.

@thufschmitt thufschmitt added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label Apr 7, 2023
@Ericson2314 Ericson2314 self-assigned this Apr 7, 2023
@Ericson2314
Copy link
Copy Markdown
Member

Ericson2314 commented Apr 10, 2023

Discussed last Nix team meeting.

Verdict: Idea sounds good. Port parsing however should be pat of the URL parser in general, not extracted in this special case. Stores that don't support ports can just fail on that; stores that do like this one can set it very easily.

@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/2023-04-10-nix-team-meeting-minutes-47/27357/1

This patch allows users to specify the connection port
in the store URLS like so:

```
nix store info --store "ssh-ng://localhost:22" --json
```

Previously this failed with: `error: failed to start SSH connection to 'localhost:22'`,
because the code did not distinguish the port from the hostname. This
patch remedies that problem by introducing a ParsedURL::Authority type
for working with parsed authority components of URIs.

Now that the URL parsing code is less ad-hoc we can
add more long-awaited fixes for specifying SSH connection
ports in store URIs.

Builds upon the work from bd1d2d1.

Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
Co-authored-by: John Ericson <John.Ericson@Obsidian.Systems>
@Ericson2314 Ericson2314 enabled auto-merge August 6, 2025 21:02
@Ericson2314 Ericson2314 merged commit 9ff4c44 into NixOS:master Aug 6, 2025
14 checks passed
@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-31-0-released/68465/1

@cole-h
Copy link
Copy Markdown
Member

cole-h commented Oct 3, 2025

FYI: this appears to have broken NIX_SSHOPTS, c.f. #14148

EDIT: only when using a host like root@localhost, it seems

oss << authority.host;
return std::move(oss).str();
}())
, fakeSSH(authority.host == "localhost")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cole-h, this will make it behave as it used to:

Suggested change
, fakeSSH(authority.host == "localhost")
, fakeSSH(authority.to_string() == "localhost")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation fetching Networking with the outside (non-Nix) world, input locking idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. store Issues and pull requests concerning the Nix store UX The way in which users interact with Nix. Higher level than UI. with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssh-ng://host:port treats host:port as the hostname