Skip to content

Commit

Permalink
feat: redesign flake-ref parsing (#15)
Browse files Browse the repository at this point in the history
This PR implements nix supported flakerefs.
Unlike the previous implementation all flakerefs are individual (generic) types.
This allows implementing converting to and from string representations on a per-type basis,
rather than necessarily covering all possible references in a single match statement.
As a side effect, implementing flake references one by one,
allowed us to match nix' behavior more closely (#3, #16).

Some flakerefs allow multiple protocols, but are essentially equivalent.
This includes `file`, `tarball`, `git` and "git forges" (e.g. `github`).
Such flakerefs have been implemented as generic types in order to share parsing logic,
and at the same time retain the ability to enforce individual origins statically.
For instance, it is now possible to define a composite type that requires local files (i.e. `git+file`, `path` `[file+]file://` or `[tarball+]file://`).

All tests that existed with the old flake_ref work with the new ones and I added a couple of "roundtrips" to assure, we do not lose information on the way.

I stumbled over a very annoying [`serde` bug](serde-rs/serde#1547 (comment)) that basically says, `deny_unknown_fields` and `flatten` cannot be used together.

That and the fact that `url` queries are not self describing structures (which [triggers](nox/serde_urlencoded#33) another [`serde` bug](serde-rs/serde#1183) related to flattening), lets me wonder if we should use serde at all for query parsing or do the parsing manually, at the cost of legibility (https://github.com/flox/runix/pull/12/files#diff-fa82b2796286fd4622869172f2187af6691578ffbdf972e853826db2d4277fbcR200-R226).
---------

Co-authored-by: Matthew Kenigsberg <mkenigs@users.noreply.github.com>
  • Loading branch information
ysndr and mkenigs committed Mar 27, 2023
1 parent 09b326c commit 89f136b
Show file tree
Hide file tree
Showing 11 changed files with 1,576 additions and 523 deletions.
6 changes: 5 additions & 1 deletion crates/runix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ runix-derive = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "2.2.0"
serde_urlencoded = "0.7.1"
url = { version = "2.3", features = ["serde"] }
shell-escape = "0.1.5"
tokio = { version = "1.21", features = ["full"] }
tokio-stream = { version = "0.1.11", features = ["tokio-util", "io-util"] }
thiserror = "1.0"
url = "2.3"
chrono = { version = "0.4.24", features = ["serde"] }
regex = "1.7.2"
once_cell = "1.17.1"
Loading

0 comments on commit 89f136b

Please sign in to comment.