Open srid opened 1 week ago
even then we can catch the flake in local nix store before looking up YAML, falling back to Nix eval
So this is what we should do, nevermind fromYAML
What do we use to parse YAML in rust? I see three options:
I'd use serde-yaml
for now.
A maintained fork may popup later (there's one already but not ready yet: https://github.com/cafkafk/serde-norway/issues/17). There's also https://github.com/saphyr-rs/saphyr but saphyr-serde
is not available yet. So in future we can switch to one of these that the community adopts.
Also, what's the problem with using json for configs instead?
Not a problem per se, but the UX of editing the config can suck a bit.
https://x.com/i/grok/share/eulnfhBsYG4zrqRX3U96yU9Q6
For eg., multiline-strings will look like this in JSON (forced to be single line, peppered with \n
's):
TOML is another option, but nested attrs will look pretty verbose:
Do you think we should simply go with JSON instead?
re YAML, more options are listed at https://github.com/rustsec/advisory-db/issues/2132 . https://crates.io/crates/serde_yml doesnt use unsafe-libyaml
- instead it uses a fork https://github.com/sebastienrousseau/libyml which is actively maintained. I had a problem using it to parse OpenAPI schemas , but it is probably fine with simpler schemas.
Basic benchmark of fetching OmConfig
from om.nix
vs its json
equivalent. The benchmark was done using divan on an MBP M1 pro:
Timer precision: 41 ns
config fastest β slowest β median β mean β samples β iters
ββ from_flake_url 156.5 ms β 346.5 ms β 173.9 ms β 176.2 ms β 100 β 100
ββ from_json 26.16 Β΅s β 146.4 Β΅s β 29.54 Β΅s β 31.53 Β΅s β 100 β 100
β°β from_yaml 110.4 Β΅s β 478.3 Β΅s β 115.3 Β΅s β 125.5 Β΅s β 100 β 100
Edit: Iβm not sure if weβd want to include these benchmarks in juspay/omnix
, so theyβre in my fork for now. See the implementation.
Edit: Iβll also be adding YAML to this soon.
Edit: The benchmark now includes YAML too
This would mitigate #339
Our entire omnix configuration (
om.nix
), https://github.com/juspay/omnix/blob/main/nix/modules/flake-parts/om.nixcan be written as YAML as well (see below). This has the benefit of not needing to evaluate the whole flake just to get the omnix config. This would then make
om develop
faster.We may still have to support Nix-based config (but that piggyback on YAML using
builtins.fromYAML
) for cases where we evaluate a non-local flake (even then we can catch the flake in local nix store before looking up YAML, falling back to Nix eval).Blocked on #341 (after which doing this should be straightforward).