Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to combine this with Cachix? #15

Open
hraban opened this issue Jun 28, 2023 · 8 comments
Open

How to combine this with Cachix? #15

hraban opened this issue Jun 28, 2023 · 8 comments

Comments

@hraban
Copy link

hraban commented Jun 28, 2023

Hi, I've been trying to combine this with Cachix but I'm unable to get it to not download derivations that are already present in cachix. Do I misunderstand something about how the magic cache should work? I thought it was more like a local /nix/store, which should prevent redownloading from cachix?

I'm working on the ci/magic branch on https://github.com/hraban/cl-nix-lite :

Backstory: I am working on a pretty large nix module for Common Lisp which contains a derivation for many of the popular packages (a few hundred). I currently use cachix and a custom sed script to only rebuild those derivations that are not yet in Cachix, and I'm playing around with this magic cache to see if it can remove the need for that custom sed script. So far I'm not seeing exactly how they're supposed to work together though. Particularly the "don't rebuild existing derivations" part of the magic cache seems elusive to me.

Here is a nightly run on my master branch using just the sed script:

Is that a workflow which the magic cache automates?

@lucperkins
Copy link
Member

The issue here, I think, is that the Magic Nix Cache doesn't cache what's available in your upstream cache. The goal of the MNC is essentially to build less, not necessarily to fetch less. If something is available upstream, the MNC knows that it can be fetched in the future. This saves cache space on the Actions Cache side (GitHub is generous but cache space is not unlimited). So if you prefer to cache things on the Actions side, I'd recommend un-setting the upstream-cache parameter.

@hraban
Copy link
Author

hraban commented Jun 29, 2023

Thanks @lucperkins :) honestly I don't really have a clear plan, I was just playing around to see what this offers.

I followed your advice and removed the upstream-cache param but I get the exact same results:

Do I understand correctly that it should have had those cached, at that point?

@lucperkins
Copy link
Member

@hraban In that first run you linked, the MNC copies 320 paths to the cache, while in the second it copies zero. So it is indeed caching. I don't really know the details of the Cachix Action but it's possible that they're not compatible. I don't really know Haskell so I'm not 100% sure how the cachix use command works, but I suspect it also updates the Nix configuration. It may be worth seeing the contents of $HOME/.config/nix/nix.conf after both Actions have been run. In general, though, it's not clear to me what benefit it would serve to use both Cachix and the Magic Nix Cache.

@dpc
Copy link

dpc commented Jul 3, 2023

I arrived here to ask about combining MNC with cachix as well. We're using cachix already, and it works well, but maybe there's room for improvements still.

In general, though, it's not clear to me what benefit it would serve to use both Cachix and the Magic Nix Cache.

One problem with cachix in Github Action CI is that every run starts on a fresh VM and has to fetch all the artifacts from cachix, which seems slower than expected.

I was hoping that MNC would be faster, because it might serve data from infrastructure inside same data center etc. So MNC + cachix could be used as a hybrid cache, where MNC would be fetched from first (if available), then all the new artifacts would go to both.

Though I understand this is additional complexity and might not be the goal of this project (if it even does lead to any speedups).

@hraban
Copy link
Author

hraban commented Jul 7, 2023

@dpc are you building one single large final derivation, or are you building many small independent ones?

@dpc
Copy link

dpc commented Jul 7, 2023

We have a somewhat extensive CI pipeline building large Rust project natively, running tests as Nix derivations, cross-compiling to various platforms, and all sorts of things.

@Zimmi48
Copy link

Zimmi48 commented Jul 13, 2023

In general, though, it's not clear to me what benefit it would serve to use both Cachix and the Magic Nix Cache.

Cachix has lots of advantages (cross-project availability, populates a cache that can be used locally, etc.) that may make it the preferred way to cache Nix builds. But it has a major drawback (as highlighted in #19) which is that it requires a secret to be set, which won't happen for pull requests coming from forks. Users might hope to use the Magic Nix Cache action as a fallback in this case, to still be able to share builds across jobs and across rebuilds.

@hraban
Copy link
Author

hraban commented Mar 2, 2024

In general, though, it's not clear to me what benefit it would serve to use both Cachix and the Magic Nix Cache.

Cachix has lots of advantages (cross-project availability, populates a cache that can be used locally, etc.) that may make it the preferred way to cache Nix builds. But it has a major drawback (as highlighted in #19) which is that it requires a secret to be set, which won't happen for pull requests coming from forks. Users might hope to use the Magic Nix Cache action as a fallback in this case, to still be able to share builds across jobs and across rebuilds.

On the other hand, it seems that GH Actions seems to be quite conservative with sharing caches between branches, so you will end up having similar issues if e.g. you have two very similar feature branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants