ecosyste-ms / ecosyste-ms/parser

Parse flake.nix / flake.lock

Open
#1,199 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
14
Forks
4
PR merge metrics
No merged PRs in 30d

Description

### reasoning

While the whole flake system supported by Nix is de-jure not considered stable as mentioned in the manual, IMO the format of the flake inputs can be considered mostly stable, as it was not changed in any backwards-compatible way for the last 3 years (probably even longer through).

At time of writing, IMO flake.nix seems to be one de-facto standard for managing dependencies to other repositories in the Nix community. To provide examples for Nix community projects using flake.nix to declare their dependencies:
- [nix-community/flake-firefox-nightly](https://github.com/nix-community/flake-firefox-nightly/blob/master/flake.nix)
- [nix-community/home-manager](https://github.com/nix-community/home-manager/blob/master/flake.nix)
- [nix-community/nixos-anywhere](https://github.com/nix-community/nixos-anywhere/blob/main/flake.nix)
- [hercules-ci/flake-parts](https://github.com/hercules-ci/flake-parts/blob/main/flake.nix)

There are alternatives to flakes such as [npins](https://github.com/andir/npins/) as being [officially recommended](https://nix.dev/guides/recipes/dependency-management). I think adding support to those differing formats later on could be worth it, esp. when a larger amount of the community starts using them as well. Through I have no experience with e.g. npins as of today, so I will not propose it.

Also ecosyste.ms seems to not support any Nix dependency scheme for now, so it would be great to at least support one. Esp. as on projects supporting multiple schemes (e.g. flakes & npins), both schemes should point to the same dependencies.

### format & parsing

The format of the flake.nix & flake.lock files are [officially documented here](https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-format).

Parsing the flake.nix & flake.lock file can also be out-sourced to the Nix CLI via [`nix flake metadata`](https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake-metadata) which can output the data as JSON.

While Nix files generally require evaluation (= execution of Nix code) to access their content, the metadata of flakes is, by design, not allowed to be arbitrary code, see [this note](https://nix.dev/concepts/flakes.html#subset) for more context. Therefore parsing them does not actually require execution of turing-complete code.

(All links to the Nix manual redirected to Nix version 2.34 at time of writing, i.e. to view the exact pages I saw replace `/stable/` with `/2.34/` in the hyperlinks. Used hyperlinks redirect to latest stable for convenience.)

### misc

Maybe I come by again to implement this myself, so as maintainers feel free to comment e.g. "PR appreciated" so I have more motiviation to work on this, or to ask further questions in need of more clarification.

Contributor guide

Open the contributing guide

Research direction

Start by reading the documented flake.nix and flake.lock formats and running nix flake metadata to inspect the JSON output for the linked example projects. Trace how this Ruby parser handles other dependency manifests, then define completion as recognizing both flake files and reporting the same dependencies that the Nix metadata describes.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.