Skip to main content

Crate nix_uri

Crate nix_uri 

Source
Expand description

nix-uri is a rust crate that parses the nix-uri-scheme into a flakeref::FlakeRef struct.

Also allows for building a nix-uri through the flakeref::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.2.0"

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:nixos/nixpkgs

The uri syntax representation is parsed by this library:

§Example: Parsing from github:nixos/nixpkgs:

 let uri = "github:nixos/nixpkgs";
 let parsed: FlakeRef = uri.parse().unwrap();
 match parsed.kind() {
     FlakeRefType::GitForge(forge) => {
         assert_eq!(forge.platform, GitForgePlatform::GitHub);
         assert_eq!(forge.owner, "nixos");
         assert_eq!(forge.repo, "nixpkgs");
         assert!(forge.ref_.is_none() && forge.rev.is_none());
     }
     _ => panic!("expected GitForge"),
 }

The Display round-trip preserves the original form:

§Example: Round-tripping github:nixos/nixpkgs:

let uri = "github:nixos/nixpkgs";
let parsed: FlakeRef = uri.parse().unwrap();
assert_eq!(uri, parsed.to_string());

Structs§

FlakeRef
The General Flake Ref Schema
ForgeIdentity
Identity of a git-forge flake ref: (platform, owner, repo, domain).
GitForge
A reference into a git forge (github:, gitlab:, sourcehut:).
LocationParameters
Query-string parameters that decorate a FlakeRef.
ResourceUrl
A resource-style flake reference (git+https://..., hg+ssh://..., file+https://..., tarball+https://...).

Enums§

FlakeRefType
GitForgePlatform
Which git-forge scheme a GitForge reference uses. Spelled in the URL as the leading github:, gitlab:, or sourcehut: token; also drives the canonical-domain lookup in super::ForgeIdentity.
NixUriError
Failures the parser may produce.
ParseExpected
What the parser was looking for when it failed.
RefKind
Discriminates the four ref/rev presence states without forcing callers to read both FlakeRef::ref_ and FlakeRef::rev and reason about the cross product.
RefLocation
Names where a ref or rev is rendered in a FlakeRef.
ResourceType
The resource flavour of a ResourceUrl: which canonical Nix scheme (git+, hg+, file+, tarball+) the URL belongs to. Used to pick the leading scheme token on Display.
TransportLayer
Specifies the +<layer> component, e.g. git+https://.
UnsupportedReason
Categorised reason an Unsupported URI was rejected.

Type Aliases§

NixUriResult