flake-checker/README.md

112 lines
5.3 KiB
Markdown
Raw Normal View History

2023-06-14 23:38:03 +03:00
# Nix Flake Checker
2023-06-14 20:04:11 +03:00
2023-09-19 19:17:20 +03:00
[![FlakeHub](https://img.shields.io/endpoint?url=https://flakehub.com/f/DeterminateSystems/flake-checker/badge)](https://flakehub.com/flake/DeterminateSystems/flake-checker)
2023-06-14 23:38:03 +03:00
**Nix Flake Checker** is a tool from [Determinate Systems][detsys] that performs "health" checks on the [`flake.lock`][lockfile] files in your [flake][flakes]-powered Nix projects.
2023-06-14 20:04:11 +03:00
Its goal is to help your Nix projects stay on recent and supported versions of [Nixpkgs].
2023-06-14 23:38:03 +03:00
To run the checker in the root of a Nix project:
2023-05-19 17:01:20 +03:00
```shell
2023-05-26 15:16:27 +03:00
nix run github:DeterminateSystems/flake-checker
2023-06-14 20:04:11 +03:00
# Or point to an explicit path for flake.lock
2023-05-26 15:16:27 +03:00
nix run github:DeterminateSystems/flake-checker /path/to/flake.lock
2023-05-19 17:02:42 +03:00
```
2023-06-14 23:38:03 +03:00
Nix Flake Checker looks at your `flake.lock`'s root-level [Nixpkgs] inputs and checks that:
2023-05-19 17:02:42 +03:00
2023-06-14 20:04:11 +03:00
- Any explicit Nixpkgs Git refs are in this list:
2023-06-07 19:45:56 +03:00
- `nixos-23.05`
- `nixos-23.05-small`
- `nixos-unstable`
- `nixos-unstable-small`
2023-06-07 19:45:56 +03:00
- `nixpkgs-23.05-darwin`
- `nixpkgs-unstable`
2023-06-14 20:04:11 +03:00
- Any Nixpkgs dependencies are less than 30 days old
2023-07-18 07:08:02 +03:00
- Any Nixpkgs dependencies have the [`NixOS`][nixos-org] org as the GitHub owner (and thus that the dependency isn't a fork or non-upstream variant)
2023-06-14 20:04:11 +03:00
2023-06-14 23:38:03 +03:00
If you're running it locally, Nix Flake Checker reports any issues via text output in your terminal.
But you can also use Nix Flake Checker [in CI](#the-flake-checker-action).
2023-06-14 20:04:11 +03:00
2023-06-14 23:38:03 +03:00
## The Nix Flake Checker Action
2023-06-14 20:04:11 +03:00
2023-06-14 23:38:03 +03:00
You can automate Nix Flake Checker by adding Determinate Systems' [Nix Flake Checker Action][action] to your GitHub Actions workflows:
2023-06-14 20:04:11 +03:00
```yaml
checks:
steps:
- uses: actions/checkout@v3
- name: Check Nix flake Nixpkgs inputs
uses: DeterminateSystems/flake-checker-action@main
```
2023-06-14 23:38:03 +03:00
When run in GitHub Actions, Nix Flake Checker always exits with a status code of 0 by default—and thus never fails your workflows—and reports its findings as a [Markdown summary][md].
2023-06-14 20:04:11 +03:00
## Telemetry
2023-06-14 23:38:03 +03:00
The goal of Nix Flake Checker is to help teams stay on recent and supported versions of Nixpkgs.
The flake checker collects a little bit of telemetry information to help us make that true.
2023-06-14 20:04:11 +03:00
Here is a table of the [telemetry data we collect][telemetry]:
| Field | Use |
| -------------- | ------------------------------------------------------------------------------------------------------ |
2023-06-14 20:04:11 +03:00
| `distinct_id` | An opaque string that represents your project, by sha256 hashing repository and organization details. |
2023-06-14 23:38:03 +03:00
| `version` | The version of Nix Flake Checker. |
2023-06-14 20:07:31 +03:00
| `is_ci` | Whether the checker is being used in CI (GitHub Actions). |
| `disallowed` | The number of inputs using unsupported branches of Nixpkgs. |
| `outdated` | The number of inputs using outdated versions of Nixpkgs. |
| `non_upstream` | The number of inputs using forks of Nixpkgs. |
To disable diagnostic reporting, set the diagnostics URL to an empty string by passing `--no-telemetry` or setting `FLAKE_CHECKER_NO_TELEMETRY=true`.
2023-06-14 23:38:03 +03:00
You can read the full privacy policy for [Determinate Systems][detsys], the creators of this tool and the [Determinate Nix Installer][installer], [here][privacy].
## Rust library
The Nix Flake Checker is written in [Rust].
This repo exposes a [`parse-flake-lock`](./parse-flake-lock) crate that you can use to parse [`flake.lock` files][lockfile] in your own Rust projects.
To add that dependency:
```toml
[dependencies]
parse-flake-lock = { git = "https://github.com/DeterminateSystems/flake-checker", branch = "main" }
```
Here's an example usage:
```rust
2023-07-10 01:49:23 +03:00
use std::path::Path;
2023-07-10 01:49:23 +03:00
use parse_flake_lock::{FlakeLock, FlakeLockParseError};
fn main() -> Result<(), FlakeLockParseError> {
let flake_lock = FlakeLock::new(Path::new("flake.lock"))?;
println!("flake.lock info:");
println!("version: {version}", version=flake_lock.version);
println!("root node: {root:?}", root=flake_lock.root);
println!("all nodes: {nodes:?}", nodes=flake_lock.nodes);
Ok(())
}
```
The `parse-flake-lock` crate doesn't yet exhaustively parse all input node types, instead using a "fallthrough" mechanism that parses input types that don't yet have explicit struct definitions to a [`serde_json::value::Value`][val].
If you'd like to help make the parser more exhaustive, [pull requests][prs] are quite welcome.
2023-06-14 20:04:11 +03:00
[action]: https://github.com/DeterminateSystems/flake-checker-action
[detsys]: https://determinate.systems
[flakes]: https://zero-to-nix.com/concepts/flakes
2023-06-14 23:38:03 +03:00
[install]: https://zero-to-nix.com/start/install
2023-06-14 20:07:31 +03:00
[installer]: https://github.com/DeterminateSystems/nix-installer
2023-06-14 20:04:11 +03:00
[lockfile]: https://zero-to-nix.com/concepts/flakes#lockfile
[md]: https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries
[nixos-org]: https://github.com/NixOS
[nixpkgs]: https://github.com/NixOS/nixpkgs
[privacy]: https://determinate.systems/privacy
[prs]: /pulls
[rust]: https://rust-lang.org
2023-06-14 20:04:11 +03:00
[telemetry]: https://github.com/DeterminateSystems/nix-flake-checker/blob/main/src/telemetry.rs#L29-L43
[val]: https://docs.rs/serde_json/latest/serde_json/value/enum.Value.html