I made a flake-ref type checker ( with a full URI parser ) using YANTS:
These are type assertions, they’ll throw an error for invalid fields/urls.
Repo: github:aakropotkin/rime
Examples of Flake Ref audits:
nix-repl> :p map ( builtins.getFlake "github:aakropotkin/rime/main" ).lib.ytypes.FlakeRef.Structs.flake-ref-github [
{ url = "github:aakropotkin/rime/main"; }
{ type = "github"; url = "github:aakropotkin/rime/main"; }
{ type = "github"; owner = "aakropotkin"; repo = "rime"; ref = "main"; }
]
=>
[ { url = "github:aakropotkin/rime/main"; }
{ type = "github"; url = "github:aakropotkin/rime/main"; }
{ owner = "aakropotkin"; ref = "main"; repo = "rime"; type = "github"; }
]
nix-repl> lib.ytypes.FlakeRef.Structs.flake-ref-file { type = "file"; url = "file:./foo"; }
=>
{ type = "file"; url = "file:./foo"; }
nix-repl> lib.ytypes.FlakeRef.Structs.flake-ref-file { type = "file"; path = "./foo"; }
=>
error: {
path = "./foo";
type = "file";
} does not conform to restriction 'flake-ref[file]'
The URI parser is the more developed area of this project. This “typeclass” gathers the various parsers, type checkers, and serializers into one place so it’s a good place to navigate from: rime/uri.nix at f51d617bbb2a5e25eba265a196913bb09896a371 · aakropotkin/rime · GitHub
nix-repl> ( lib.liburi.Url "git+ssh://git@github.com/aakropotkin/rime/main?param=yep#fragment" ).val
=>
{ authority = "git@github.com"; fragment = "fragment"; path = "/aakropotkin/rime/main"; query = { param = "yep"; }; scheme = { data = "git"; transport = "ssh"; }; }
nix-repl> toString ( lib.liburi.Url { authority = "discourse.nixos.org"; path = "/t/flakeref-uri-parser-checker-with-yants/22358"; scheme = { data = "file"; transport = "https"; }; } )
=>
"file+https:/discourse.nixos.org/t/flakeref-uri-parser-checker-with-yants/22358"