question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flakes: add system-independent outputs?

See original GitHub issue

As far as I know an “appropriate” flakes interface for mach-nix is still more or less an open question, and it has already been discussed in: https://github.com/DavHau/mach-nix/issues/153

As a resolution of that discussion, the mk(Python|...) functions have been added as lib.mk... flake outputs, which made them, well, accessible in the importing flakes.

However, those functions are currently extracted from default-mach-nix which has already been populated with a concrete version of nixpkgs, imported in a let in statement in mach-nix’s flake.nix. This means that one can’t pass those functions their own version of nixpkgs (e.g. final or prev in an overlay) without re-importing mach-nix manually as a non-flake.

One resolution could be to make lib functions system-independent (I thought they are, by-convention, supposed to be, but I’m not sure and I can’t find references for that)

The other (and probably optimal, at the moment) resolution would be to provide a flake .overlay output, which would be a function final: prev: adding a mach-nix attrset to nixpkgs possessing all the appropriate functions. and derivations. If I understand correctly, this is what poetry2nix does.

P.S. I’m unsure, again, if it’s a convention, but I saw in some repos that with an overlay output it might be convenient to refactor packages of flake.nix to just inherit the respective outputs from pkgs, where pkgs would be imported with this exact overlay. Thus we’d have a system-independent overlay output and the packages that refer to nixpkgs version pinned in the flake.lock, addressing the questions raised in the previous issue in a rather un-confusing way

P.P.S. I still don’t know anything about whether pypy-deps-db and nixpkgs versions need to be matched in any way. E.g. if one uses a mach-nix overlay on their own revision of nixpkgs, would they ever need to pass a custom pypy-deps-db too? Should we make pypy-deps-db an argument of something, or perhaps pass it through the pkgs as well, so as to leave an option to override it in another overlay?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DavHaucommented, Jun 14, 2021

P.S. I’m unsure, again, if it’s a convention, but I saw in some repos that with an overlay output it might be convenient to refactor packages of flake.nix to just inherit the respective outputs from pkgs, where pkgs would be imported with this exact overlay. Thus we’d have a system-independent overlay output and the packages that refer to nixpkgs version pinned in the flake.lock, addressing the questions raised in the previous issue in a rather un-confusing way

I bet that there isn’t a convention. The flakes feature of nix is in experimental status. Everything could still be changed in a way that is not backward compatible. Also the lib output is not listed by flake show, so I very much assume that there is no specific structure expected by any nix tooling. It’s just a random output. There aren’t even official docs for flakes outputs at all AFAIK.

1reaction
DavHaucommented, Jun 14, 2021

Thanks for that. I’m not using mach-nix much with flakes for myself. Your input is useful. Providing an overlay might be a reasonable approach to deal with the dependency on nixpkgs. I’m open to experiment with the overlay. We can just add it and see how it goes. Are you motivated to work on this?

Concerning the import arguments which are unpractical to use for flake users: One solution would be to add all arguments to the individual lib functions. There would be a default but it can be overridden on each function call. The problem with this is, that it opens the door for bugs which are hard to debug. If for example a buildPythonPackage result is used inside mkPython, then they both must be executed on the same pypi-deps-db, otherwise collisions might happen. It would be better if those arguments could be passed once via some init method to lower the risk of stuff being mixed the wrong way. An alternative solution could be, instead of providing flakes users with a readily imported mach-nix, offer just a mach-nix initialization function that requires a set of attributes being passed (can be empty), similar to the current import function of mach-nix.

P.P.S. I still don’t know anything about whether pypy-deps-db and nixpkgs versions need to be matched in any way. E.g. if one uses a mach-nix overlay on their own revision of nixpkgs, would they ever need to pass a custom pypy-deps-db too? Should we make pypy-deps-db an argument of something, or perhaps pass it through the pkgs as well, so as to leave an option to override it in another overlay?

pypi-deps-db should always be newer than nixpkgs. If used via flakes, it will raise an error if it is not. So that isn’t an issue. The user will be informed if action needs to be traken. And yes, it definitely needs to be an argument either for the init functions and also for the lib functions.

The next question which arises, do we want to keep the API downward compatible or not? I vote for no, to reduce the amount of possible ways to call mach-nix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Practical Nix Flakes - Serokell
Flakes are self-contained units that have inputs (dependencies) and outputs (packages, deployment instructions, Nix functions for use in ...
Read more >
Flakes - NixOS Wiki
nixConfig is an attribute set of values which reflect the values given to nix.conf. This can extend the normal behavior of a user's...
Read more >
Anatomy of a Flake - Fluree Developers
Every piece of data inside of a Fluree ledger is held in a data structure called a Flake. A Flake is an atomic...
Read more >
Switching non-NixOS Home Manager to flakes
Frequently, this is done by including a Home Manager configuration in the (also flakified) system configuration. Home Manager can, however, be ...
Read more >
NixOS Series 2: Basic Config, Nix Flake & Batch Deploy
Basic config ; # Add these lines environment.systemPackages = [ # This is a package definition, is an object instead of a string...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found