Mic92 / nix-fast-build

Combine the power of nix-eval-jobs with nix-output-monitor to speed-up your evaluation and building process.
MIT License
258 stars 12 forks source link

Ram usage building .#nixosConfigurations #73

Closed covert8 closed 1 month ago

covert8 commented 3 months ago

Hi love the project, thinking of doing some work on it and I would like some feedback before starting.

By default the .#checks get build and I added my .#nixosConfigurations like so:

checks.x86_64-linux = lib.mapAttrs' (name: config: lib.nameValuePair "${name}" config.config.system.build.toplevel) self.nixosConfigurations;

However, this resulted in additional downloads when doing a plain nix flake check and prolonging the check duration; so I found this sub optimal as I like to check on a tmpfs.

To avoid the default .#checks I passed -f .#nixosConfigurations but that results in an OOM on the evaluator (>64GB;no tmpfs ; 5 hosts) and not completing any derivation in a timely fashion. I ended with this:

hosts=$(nix flake show --json | jq -r '.nixosConfigurations | keys | .[] | select(. != "C60006") |  ".#nixosConfigurations." + . + ".config.system.build.toplevel"')
while read -r host; do
    nix-fast-build -f "$host" --no-nom -j 1 --eval-workers 1 --skip-cached
done <<<$hosts

My questions:

Mic92 commented 3 months ago

My questions:

* Is there a way to simplify the while loop?

If you only run one eval thread at the time, you can also just pass all hosts at once, it shouldn't make a big difference.

* Do you think it is feasible to remove already uploaded derivations (when using the cachix daemon) to make more ram available during a build?

This is what --skip-cached should do, assuming you have configured your system correctly to use the cache.

* Would you accept a pr supporting the `attic` client?

Attic support is fine, it's probably pretty similar to cachix.

covert8 commented 2 months ago

If you only run one eval thread at the time, you can also just pass all hosts at once, it shouldn't make a big difference.

Could you give an example of this? I can't seem to get it to build multiple hosts if i specify multiple flake urls or if i combine them.

Mic92 commented 1 month ago

I would expose nixos hosts in checks actually:

https://github.com/Mic92/dotfiles/blob/f44bac5dd6970ed3fbb4feb906917331ec3c2be5/flake.nix#L191

Than you don't need a loop at all.

Mic92 commented 1 month ago

And for RAM usage, you can always change the number of concurrent evaluations:

https://github.com/nix-community/nix-eval-jobs?tab=readme-ov-file#nix-eval-jobs-consumes-too-much-memory--is-too-slow

covert8 commented 1 month ago

Thanks for all the help and good work!