Show the crate…
6 releases
0.1.9 | Jul 22, 2024 |
---|---|
0.1.8 | Jul 20, 2024 |
0.1.5 | Dec 12, 2023 |
0.0.0 | Dec 13, 2023 |
#84 in #uri
42 downloads per month
Used in flake-edit
100KB
1.5K
SLoC
nix-uri
nix-uri is a rust crate that parses
the nix-uri-scheme
into a FlakeRef
struct.
Also allows for building a nix-uri
through the FlakeRef
struct.
Convenience functionality for working with nix flake.nix
references (flakerefs).
Provides types for the generic attribute set representation, but does not parse it:
{
type = "github";
owner = "NixOS";
repo = "nixpkgs";
}
Installation
To use nix-uri
, add it as a dependency in your Cargo.toml
file:
[dependencies]
nix-uri = "0.1.9"
or use cargo add
:
cargo add nix-uri
Examples
Check out the examples directory, for more information, or run an example:
cargo run --example simple
cargo run --example cli github:nixpkgs/nixos
The uri syntax representation is parsed by this library:
Example: Parsing from github:nixos/nixpkgs
:
let uri = "github:nixos/nixpkgs";
let expected = FlakeRef::new(
FlakeRefType::GitHub {
owner: "nixos".into(),
repo: "nixpkgs".into(),
ref_or_rev: None,
});
let parsed: FlakeRef = uri.try_into().unwrap();
assert_eq!(expected, parsed);
It can also be generated from FlakeRef
.
Example: Constructing the following uri github:nixos/nixpkgs
:
let expected = "github:nixos/nixpkgs";
let uri = FlakeRef::new(
FlakeRefType::GitHub {
owner: "nixos".into(),
repo: "nixpkgs".into(),
ref_or_rev: None,
}).to_string();
assert_eq!(expected, uri);
Note
This library is still an early WIP and not all cases are covered yet. Especially error handling is not properly implemented at this time.
Dependencies
~2.2–3.5MB
~78K SLoC