juspay / omnix

🚧 A Nix companion to improve developer experience
https://omnix.page
GNU Affero General Public License v3.0
106 stars 10 forks source link

YAML for config #343

Open srid opened 1 week ago

srid commented 1 week ago

This would mitigate #339

Our entire omnix configuration (om.nix), https://github.com/juspay/omnix/blob/main/nix/modules/flake-parts/om.nix

can 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).

ci:
  default:
    omnix:
      dir: "."
      steps:
        # build:
        #   enable: false
        flake-check:
          enable: false  # Not necessary
        custom:
          om-show:
            type: "app"
            # name: "default"
            args:
              - "show"
              - "."
          binary-size-is-small:
            type: "app"
            name: "check-closure-size"
            systems:
              - "x86_64-linux"  # We have static binary for Linux only.
          omnix-source-is-buildable:
            type: "app"
            name: "omnix-source-is-buildable"
          cargo-tests:
            type: "devshell"
            command:
              - "just"
              - "cargo-test"
            systems:
              - "x86_64-linux"
              - "aarch64-darwin"  # Avoid emulated systems
          cargo-clippy:
            type: "devshell"
            command:
              - "just"
              - "clippy"
            systems:
              - "x86_64-linux"
              - "aarch64-darwin"  # Avoid emulated systems
          cargo-doc:
            type: "devshell"
            command:
              - "just"
              - "cargo-doc"
            systems:
              - "x86_64-linux"
              - "aarch64-darwin"  # Avoid emulated systems
    doc:
      dir: "doc"
    registry:
      dir: "crates/omnix-init/registry"
      steps:
        build:
          enable: false
        custom: {}
    cli-test-dep-cache:
      dir: "crates/omnix-cli/tests"
      steps:
        lockfile:
          enable: false
        flake_check:
          enable: false
        custom: {}
health:
  default:
    nix-version:
      min-required: "2.16.0"
    caches:
      required:
        - "https://om.cachix.org"
    direnv:
      required: true
develop:
  default:
    readme: |
      🍾 Welcome to the **omnix** project

      To run omnix,

      ```sh-session
      just watch <args>
  (Now, as you edit the Rust sources, the above will reload!)

  🍎🍎 Run 'just' to see more commands. See <https://nixos.asia/en/vscode> for IDE setup.
srid commented 1 week ago

Oh well https://github.com/NixOS/nix/pull/7340

srid commented 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

image

shivaraj-bh commented 1 week ago

What do we use to parse YAML in rust? I see three options:

srid commented 1 week ago

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.

shivaraj-bh commented 1 week ago

Also, what's the problem with using json for configs instead?

srid commented 1 week ago

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):

image

TOML is another option, but nested attrs will look pretty verbose:

image


Do you think we should simply go with JSON instead?

jayvdb commented 1 week ago

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.

shivaraj-bh commented 4 days ago

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