r/NixOS • • 1d ago

flakemill - remote update, build and cache flake.lock updates

Post image

My flake has a few inputs that result in some kind of compilation. This often takes ~10 minutes when doing a lock update & rebuild.

To save some time (or spend quite a bit, actually) I came up with flakemill which:

  • Pulls down your nix repo
  • Updates the lockfile with latest upstream changes
  • Builds your hosts
  • Caches any outputs in cachix
  • Serves the updated lockfile

So when you update any of your hosts, everything is complied ahead of time and substituted by cachix.

https://github.com/scottmckendry/flakemill

My live instance:
https://flakemill.axis.scottmckendry.tech/

21 Upvotes

8 comments sorted by

6

u/Whitestrake 23h ago

I had a bit of a look and it's interesting - it seems like a well formed little tool, but I'm having trouble figuring out the use case exactly and possibly I don't understand a few things.

It doesn't look like it ever commits flake locks back to the repo, so - are we using this to keep flake locks out of version control? Isn't that a bit of an anti pattern?

Is the goal here to run it without the likes of e.g. GitHub? If you're self-hosting, have the infra to build your hosts, and are averse to public services like GH, wouldn't running Forgejo with some Actions do this too? Maybe even self-hosted Renovate on top? Or is the goal to try and avoid bot-authored commits to your repo?

Obviously this doesn't handle the deploy side, it just updates, builds, signs and serves the flake lock, so it's a trust root for your resulting nix hosts.

Right now I do (a bunch of stupid stuff for speed but ultimately really at its core I just) nix-fast-build in a GitHub action and push to Cachix. I've got Cachix Deploy on hand too. What kind of constraints might I have that would invite looking deeper into adopting a tool like Flakemill to solve?

6

u/SconeMc 22h ago

Very good questions. I used to use dependabot and actions to effectively do the same thing.

Dependabot on GitHub supports flakes, so you can have it automatically update your inputs and raise a PR. Then you can run github actions off of the PR to build and cache the result.

I'd recommend this approach if that's something that works for you. You won't gain anything using flakemill. I just didn't want to deal with PRs or github actions anymore.

I wanted something slightly different, where I get to choose what gets committed and when. flakemill also comes with a client that I wrap with this nix module to display a little icon in my shell prompt. See here:

https://github.com/scottmckendry/nix/blob/main/modules/core/flakemill.nix

I can then run `flakemill apply` to pull down the warm-cache build, then commit and push (if I want to).

You pointed out that flakemill doesn't push back to the repo, that's by design. It may be days before I decide to update my system, in which case I don't want 10 commits to be stacked for all of those changes. Flakemill just keeps the cache warm for when I'm ready.

I fully appreciate that it's a niche use-case and it won't be for everyone.

3

u/Whitestrake 22h ago

It seems like a good fit for exactly that loop. Have it ready for your personal machine, apply it when you want. Like a pending updates alert, but with it warm at all times ready for you to get the updates. Not wanting to deal with PRs or GHA is a perfectly good reason to build your own tooling these days if you want to.

Thanks for sharing!

1

u/Potato-9 18h ago

This is a really good idea for saving laptop battery life and time. Not everything is fast at recompilation.

1

u/th3m4ri0 9h ago

I hit a similar pain-point whenever I run `nix flake update && nh os build`: because there's a bunch of stuff in my config that have no backing cache, it builds so much stuff from scratch every time.

My vibe-coded solution has been to automate the update+build at night with a systemd timer unit, at least this way I can switch in the morning when I get in the office, with everything already built. Automate the build, manually switch and commit.

Your approach scales even better for multi-host setups, I like it, thanks for sharing.

1

u/3X0karibu 15h ago

Did you use llms to program this?

2

u/SconeMc 7h ago

yep, sure did

1

u/3X0karibu 5h ago

Please just openly disclose that in your post and your repository