Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create StoreReference and use it in Machine #9839

Merged
merged 4 commits into from
May 22, 2024

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jan 23, 2024

Motivation

Separating parsing the URI from opening the store allows for a more robust Machine data type that is easier to use.

Context

Helps with Hydra dedup too NixOS/hydra#1164

Depends on #9850

Priorities and Process

Add 👍 to pull requests you find important.

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

@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Jan 23, 2024
}


std::string StoreURI::render() const
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you chose "render" over "to_string"? Seems like an odd choice to me.

src/libstore/store-uri.hh Outdated Show resolved Hide resolved
src/libstore/store-api.hh Outdated Show resolved Hide resolved
src/libstore/store-uri.hh Outdated Show resolved Hide resolved
src/libstore/store-uri.hh Outdated Show resolved Hide resolved
src/libstore/store-uri.hh Outdated Show resolved Hide resolved
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Jan 25, 2024
In particular `local://<path>` and `unix://` (without any path) now
work, and mean the same things as `local` and `daemon`, respectively. We
thus now have the opportunity to desguar `local` and `daemon` early.

This will allow me to make a change to
NixOS#9839 requested during review to
desugar those earlier.
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Jan 25, 2024
In particular `local://<path>` and `unix://` (without any path) now
work, and mean the same things as `local` and `daemon`, respectively. We
thus now have the opportunity to desguar `local` and `daemon` early.

This will allow me to make a change to
NixOS#9839 requested during review to
desugar those earlier.
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Jan 30, 2024
In particular `local://<path>` and `unix://` (without any path) now
work, and mean the same things as `local` and `daemon`, respectively. We
thus now have the opportunity to desguar `local` and `daemon` early.

This will allow me to make a change to
NixOS#9839 requested during review to
desugar those earlier.

Co-authored-by: Théophane Hufschmitt <[email protected]>
@Ericson2314 Ericson2314 marked this pull request as draft February 23, 2024 14:00
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/2024-02-03-nix-team-meeting-127/40309/1

Ericson2314 added a commit to Ericson2314/nix that referenced this pull request May 21, 2024
In particular `local://<path>` and `unix://` (without any path) now
work, and mean the same things as `local` and `daemon`, respectively. We
thus now have the opportunity to desguar `local` and `daemon` early.

This will allow me to make a change to
NixOS#9839 requested during review to
desugar those earlier.

Co-authored-by: Théophane Hufschmitt <[email protected]>
Ericson2314 added a commit to Ericson2314/nix that referenced this pull request May 21, 2024
In particular `local://<path>` and `unix://` (without any path) now
work, and mean the same things as `local` and `daemon`, respectively. We
thus now have the opportunity to desguar `local` and `daemon` early.

This will allow me to make a change to
NixOS#9839 requested during review to
desugar those earlier.

Co-authored-by: Théophane Hufschmitt <[email protected]>
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label May 21, 2024
@Ericson2314 Ericson2314 marked this pull request as ready for review May 21, 2024 16:20
@Ericson2314 Ericson2314 force-pushed the more-machine-cleanup branch 2 times, most recently from 82f2d76 to 5660d44 Compare May 21, 2024 16:50
@@ -37,7 +37,7 @@ static std::string currentLoad;

static AutoCloseFD openSlotLock(const Machine & m, uint64_t slot)
{
return openLockFile(fmt("%s/%s-%d", currentLoad, escapeUri(m.storeUri), slot), true);
return openLockFile(fmt("%s/%s-%d", currentLoad, escapeUri(m.storeUri.render()), slot), true);
Copy link
Member

Choose a reason for hiding this comment

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

I think we have a problem here. Considering that we also have params in the URI, which do not affect the identity of the store to be opened, is this actually suitable for use in the name of a lock?
It's a pre-existing issue, fwiw.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes definitely a preexisting issue. If anything, we're better able to deal with it now.

src/libstore/ssh-store-config.hh Outdated Show resolved Hide resolved
@Ericson2314 Ericson2314 changed the base branch from master to nix-init-command May 21, 2024 17:11
@Ericson2314 Ericson2314 changed the base branch from nix-init-command to master May 21, 2024 17:11
@Ericson2314 Ericson2314 changed the title Create StoreURI and use it in Machine Create StoreReference and use it in Machine May 21, 2024
storeUri([&storeUri]{
try {
return StoreReference::parse(storeUri);
} catch (UsageError &) {
Copy link
Member

Choose a reason for hiding this comment

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

This is nasty. Should we deprecate this old syntax?

Copy link
Member

Choose a reason for hiding this comment

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

Could this be done during config parsing instead? That way nix show-config will show the correct syntax.

Also no chance to accidentally keep using this hack when we improve the settings format.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to parse more eagerly, but that felt like a change best kept for later. (Similarly, using Setting<StoreReference> for a bunch of things.)

Right now, this is just supposed to match the back compat hack that was there before.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just restored the old method of compat for now. We can decide separately whether such try-catch is worth it.

} catch (UsageError &) {
// Backwards compatibility: if the URI is invalid, it might
// be bare host name.
return StoreReference::parse("ssh://" + storeUri);
Copy link
Member

Choose a reason for hiding this comment

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

If this fails, we should throw the error for the unmodified string, not the new one.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just restored the old method of compat for now. We can decide separately whether such try-catch is worth it.

src/libstore/store-reference.hh Show resolved Hide resolved
src/libstore/machines.cc Show resolved Hide resolved
@Ericson2314 Ericson2314 force-pushed the more-machine-cleanup branch 2 times, most recently from 849c8ab to a63c888 Compare May 22, 2024 12:49
Ericson2314 and others added 3 commits May 22, 2024 09:20
For long expressions, one argument or parameter per line is just easier.
Need to decouple parsing from actually opening a store for Machine
configs.

Co-authored-by: Théophane Hufschmitt <[email protected]>
Co-authored-by: Robert Hensing <[email protected]>
This will be needed for the next step.

Also allows us to write round trip tests.
This makes the remote builder abstract syntax more robust.
@Ericson2314 Ericson2314 merged commit 4a19f4a into NixOS:master May 22, 2024
9 checks passed
@Ericson2314 Ericson2314 deleted the more-machine-cleanup branch May 22, 2024 21:02
Ericson2314 added a commit to NixOS/hydra that referenced this pull request May 23, 2024
With NixOS/nix#9839, the `storeUri` field is
much better structured, so we can use it while still opening the SSH
connection ourselves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
store Issues and pull requests concerning the Nix store with-tests Issues related to testing. PRs with tests have some priority
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants