{
py ? "39" # To override the default python version: nix-shell shell.nix --argstr py 37
}:
and later contains
python = builtins.getAttr ("python" + py) pkgs;
in order to allow overriding the default python version from the CLI.
I’m trying to upgrade this shell.nix to a flake.nix and an accompanying shell.nix which contains a shim around the flake. How can the override-version-on-CLI feature be implemented in these?
Thanks. That’s what I eventually found myself: It took me a while to realize/remember that each{Default,}System not only maps but also transposes / turns inside-out / puts the system inside the attribute, even though (naively speaking) it looks like the attribute goes inside the system.
Next stumbling block: trying to set one of these python versions as the default. The obvious way seems to be to bind devShell to my choice of default from the devShells, but, once again, the inside-outedness of eachSystem seems to be foiling me.
Not sure what I was doing wrong when I tried the self-based solution earlier myself. In my case I have an explicit self parameter in outputs, but that makes a minimal difference. It works now, so I don’t know what lesson I have learned.
Also thought about the rec-based approach, but shied away from it because I recall some style guide advising against rec. Not sure I’m convinced, or rather, I don’t remember what (if any) the reasoning was behind this recommendation. Do you have any wisdom to share on the use of rec?
This works like a charm without arguments but doesn’t reproduce the parametrization described at the top of the thread. How could this be done?
Unlike the previous two steps where I was close but no cigar, here I’m hopelessly lost. I guess that the biggest problem is the mysterious relation between the shellNix requested by the shim, and the devShells provided by the flake.
This is a question about flake-compat, and maybe there is no solution. If the flake-compat implementation does not expose the dev-shells, there is nothing to do
You could try:
builtins.getFlake, if your nix version is high enough
moving your devShells implementation to some utils.nix file, and then re-use utils.nix both in flakes.nix and in shell.nix
As per the rec or no rec, it depends, I try to use it when it makes the code more readable, and avoiding otherwise. Minimizing accidental complexity is always a good idea