nix-output-monitor/README.md

151 lines
7 KiB
Markdown
Raw Permalink Normal View History

2021-03-04 19:24:35 +01:00
# nix-output-monitor
2020-10-03 16:25:19 +02:00
2020-10-03 22:05:00 +02:00
Pipe your nix-build output through the nix-output-monitor (aka nom) to get additional information while building.
2020-10-03 16:25:19 +02:00
2023-11-26 15:44:25 +01:00
While your build runs, nom will draw something like this at the bottom of your build log:
2022-03-08 02:07:52 +01:00
![](example-screenshot.png)
2022-10-22 01:31:49 +02:00
2022-10-22 01:28:50 +02:00
*(note that to reduce clutter nom only shows timers over 1s build or download time.)*
2022-03-08 02:07:52 +01:00
2021-03-04 19:24:35 +01:00
[![Packaging status](https://repology.org/badge/vertical-allrepos/nix-output-monitor.svg)](https://repology.org/project/nix-output-monitor/versions)
2020-10-03 16:25:19 +02:00
## Status
This was an experimental fun project, which proved to be useful to quite a lot of people.
2022-03-07 21:59:33 +01:00
The purpose of it is to write something fun and useful in Haskell.
2023-11-26 15:44:25 +01:00
You are free and very welcome to contribute feedback, issues or PRs.
I do not commit to maintain this project over a long time period but it doesnt look like I am stopping anytime soon.
2022-10-10 00:15:55 +02:00
2022-10-10 01:06:52 +02:00
By now, nom is quite fully featured with support for nix v1 commands (e.g. `nix-build`) and nix v2 command (e.g. `nix build`).
2022-10-10 00:09:18 +02:00
2023-11-26 15:44:25 +01:00
Issues and pull requests are welcome at https://github.com/maralorn/nix-output-monitor.
2020-10-03 16:25:19 +02:00
2023-11-26 15:44:25 +01:00
Starting from version 2.1.0, nom uses [SemVer](https://semver).
The versioning applies to the behavior of the executable.
There are no stability guarantees for the library component in the cabal project.
2022-11-28 00:30:37 +01:00
## Support
2023-11-26 15:44:25 +01:00
If your question is not answered in this README you can ask it in [#nix-output-monitor:maralorn.de](https://matrix.to/#/#nix-output-monitor:maralorn.de) on matrix or open an issue on github.
2022-11-28 00:30:37 +01:00
2020-10-03 16:25:19 +02:00
## Installing
2022-03-08 21:43:53 +01:00
* nixpkgs: nom is in nixpkgs. Just install `pkgs.nix-output-monitor` in the usual way. You might want to install it from nixos-unstable to get the newest version.
2020-10-03 16:25:19 +02:00
* cabal: Install `cabal-install` and run `cabal install` in the checked out repo.
2023-11-26 15:44:25 +01:00
* nix: or use `nix build` or `nix-env` or include the flake output of this repo in your nixos config.
2020-10-03 16:25:19 +02:00
## Running
2021-03-04 19:24:35 +01:00
### The Easy Way
2022-10-10 00:20:46 +02:00
**Warning:** The displayed build tree might be incomplete with new-style commands like `nix build` for nix versions <2.10.
2022-10-10 00:09:18 +02:00
2023-11-26 15:44:25 +01:00
The `nom` binary (starting from version 2.0) behaves as a `nix` drop in, with much more colorful output, but **only** for the following commands:
2022-10-10 00:09:18 +02:00
2022-10-10 00:15:55 +02:00
`nom build <args>`: Behaves like `nix build <args>`.
`nom shell <args>`: Behaves like `nix shell <args>`.
`nom develop <args>`: Behaves like `nix develop <args>`.
2022-10-10 00:09:18 +02:00
The latter two commands work by calling `nix shell` or `nix develop` twice, the first time with overridden `--run exit` and monitoring the output, the second time passing output through to the user. This will incur a performance cost by doubling eval time.
2022-10-10 00:09:18 +02:00
2022-10-10 00:15:55 +02:00
Furthermore when called via the corresponding provided symlinks, nom is also a drop-in for the following commands:
`nom-build <args>`: Behaves like `nix-build <args>`.
`nom-shell <args>`: Behaves like `nix-shell <args>`.
2022-10-10 00:09:18 +02:00
All aliases internally use the json-based approach (see next section) and propagate error codes.
If you want nom support for other nix commands please open an issue.
2021-03-04 19:24:35 +01:00
### The Flexible Way
2022-10-10 00:09:18 +02:00
#### JSON based
```shell
nix-build --log-format internal-json -v |& nom --json
```
2022-10-10 00:20:46 +02:00
**Warning:** Dont forget to redirect stderr. That's what the `&`, does.
2022-10-10 00:09:18 +02:00
#### Human readable log parsing
2022-10-10 00:20:46 +02:00
It his highly recommended to always append `--log-format internal-json -v` (or use the above mentioned aliases.) and call `nom` with `--json`. That will give you much more informative output.
2022-10-10 00:09:18 +02:00
If you are in a situation, where you cant use the json based nix output you can still use
2020-10-31 14:26:44 +01:00
```shell
2020-10-09 22:14:44 +02:00
nix-build |& nom
2020-10-03 16:25:19 +02:00
```
2020-10-03 21:29:29 +02:00
2022-10-10 00:20:46 +02:00
**Warning:** Dont forget to redirect stderr. That's what the `&`, does.
2022-10-10 00:09:18 +02:00
This has the advantage to also work with other commands like `nixos-rebuild` or `home-manager`, where it is not trivial to pass in the `--log-format internal-json -v` flag. nom will pass everything it reads through, if it does not understand it. This makes it ideal to attach it to scripts which output more then just `nix` output.
2020-10-03 22:05:00 +02:00
2021-03-04 19:24:35 +01:00
### Preserving Colored Text
2020-10-31 14:24:41 +01:00
2022-10-10 00:09:18 +02:00
Colored text will work as expected in json-mode.
In human-readable log mode you can preserve the color of the redirected text by using the `unbuffer` command from the `expect` package.
2020-10-31 14:24:41 +01:00
2020-10-31 14:26:44 +01:00
```shell
2020-10-31 14:24:41 +01:00
unbuffer nix-build |& nom
```
2022-03-07 21:59:33 +01:00
## Explanation
### Legend
Nom tries to convey information via symbols and colors
2022-03-07 21:59:33 +01:00
* `⏵`, yellow: running builds
* `✔`, green: completed builds
2022-10-18 03:33:05 +02:00
* `⏳︎︎︎`, blue: planned builds
* `⚠`, red: failed builds
2022-10-18 03:33:05 +02:00
* `↓ ⏵`, yellow: running downloads
* `↑ ⏵`, yellow: running uploads
* `↓ ✔`, green: completed downloads
* `↑ ✔`, green: completed uploads
* `↓ ⏳︎︎︎`, blue: waiting downloads
* `∅`: a moving average over past builds of this derivation
* `⏱︎`: running time
2022-10-18 03:33:05 +02:00
* `∑`: a summary over all packages and hosts
2020-10-09 22:42:38 +02:00
If you cant see all icons you maybe need another terminal font.
I recommend any font from `pkgs.nerdfonts` e.g. `"JetBrainsMono Nerd Font"`.
2022-03-07 21:59:33 +01:00
Also different terminals might work differently well. I recommend: `pkgs.foot`.
2020-10-09 22:42:38 +02:00
2022-03-07 21:59:33 +01:00
### How to Read the Dependency Graph
2020-10-03 21:20:06 +02:00
2022-10-18 03:33:05 +02:00
* Every entry in the nom tree stands for one derivation.
2022-03-07 21:59:33 +01:00
* Children of a node are direct dependencies.
* nom will try to show you the most relevant part of the dependency tree, roughly aiming to fill a third of your terminal
* No build will be printed twice in the tree, it will only be shown for the lower most dependency.
2022-10-10 00:09:18 +02:00
* nom will do its best to print all running or failed builds, downloads and uploads, but it does not print every direct child of a node.
2022-03-07 21:59:33 +01:00
* Use the colors from above to read the summary
2020-10-03 20:52:29 +02:00
2022-03-07 21:59:33 +01:00
## Example Runs
2020-10-03 21:20:06 +02:00
2022-03-07 21:59:33 +01:00
An example remote build:
2022-10-10 00:50:02 +02:00
[![asciicast](https://asciinema.org/a/KwCh38ujQ9wusHw8kyW4KCMZo.svg)](https://asciinema.org/a/KwCh38ujQ9wusHw8kyW4KCMZo)
2022-10-10 00:50:02 +02:00
An example with a lot of downloads:
[![asciicast](https://asciinema.org/a/7hJXH2iFLEkKxG1lL25lspqNn.svg)](https://asciinema.org/a/7hJXH2iFLEkKxG1lL25lspqNn)
2022-03-07 22:04:05 +01:00
2022-03-07 21:59:33 +01:00
## Implementation
2022-03-07 21:59:33 +01:00
Right now nom uses four sources of information:
2022-10-10 00:09:18 +02:00
1. The parsed nix-build output (json or human-readable)
2. it checks if build results exist in the nix-store (only in human-readable mode)
3. it queries `.drv` files for information about the `out` output path.
2022-03-07 21:59:33 +01:00
4. It caches build times in `$XDG_CACHE_HOME/nix-output-monitor/build-reports.csv`.
2020-10-03 20:21:32 +02:00
2022-03-07 21:59:33 +01:00
## Limitations
2020-10-03 16:37:39 +02:00
2022-03-07 21:59:33 +01:00
* This will fail in unexpected and expected ways.
2022-10-10 00:09:18 +02:00
* Luckily I dont think this program screws up anything more than your terminal.
* remote builds will sometimes be shown as running even when they are actually still waiting for uploads or downloads. This is how nix reports it.
2022-03-07 21:59:33 +01:00
* Terminal clearing and reprinting is brittle. It might fail with your terminal or terminal width. But at this point Ive invested some effort to make it usable.
2022-10-10 00:09:18 +02:00
* This program also makes assumptions like your nix-store is at "/nix/store".
2020-10-03 20:21:32 +02:00
2022-10-10 00:09:18 +02:00
### For human-readable log parsing mode:
* nix-output-monitor receives most it's information from parsing nix-build output. The parser might be to strict or to loose for use cases I didnt think of. Then **the numbers displayed will be off**!
* nix-build does not show info when a download or upload is finished, so we currently cannot differentiate between started and completed downloads.
* For completed build detection we assume that every derivation has an output called "out".