I’m trying to learn NixOS with Flakes by setting up a little game emulator on a raspberry pi using emulationstation.
I’m trying to provide emulationstation with the path to different cores to be used, for example snes9x_libretro.so
So if I run find, I see the results
which exists but doesn’t contain a /lib/retroarch/cores/snes9x_libretro.so that I’m looking for.
How/why would there be multiple retroarch-with-cores-1.16.0.3 and why would some contain a lib folder and others not?
How can I reliably refer to the package that contains the cores?
Note, if helpful: I’m running nix-collect-garbage -d regularly also to be sure find isn’t picking up old derivations or something. So I’m pretty sure there are multiple retroarch-with-cores-1.16.0.3 from a single nixos-rebuild switch ...
Thanks. That does sound like a solid theory. Unfortunately, I’m not familiar enough at this point with Nix to really debug that retroarch code.
I’m not really sure how to debug where all the different retroarch-with-cores folders come from within my flake or how to refer to one of them specifically.
If ${pkgs.retroarch} points to the wrong folder, is there a way to list the other paths available such that ${pkgs.XYZ} points to the correct one?
That’s a familiar feeling I’m getting there slowly. One other thing I notice is that two packages appear in the search: NixOS Search
There’s retroarchFull and retroarch, both indicate the name: retroarch-with-cores and both link to the same source file, but they have separate descriptions.
When I looked in pkgs/applications/emulators/retroarch/cores.nix I noticed that snes9x.meta.license = lib.licenses.unfreeRedistributable;, and IIRC those aren’t yet built and available via cache.
I’m not sure how that would manifest in this case where a bunch of free and ~unfree derivations are getting composed together, but I imagine this has something to do with configuring allowUnfree or allowUnfreePredicate?
Thanks for the context.
I was thankfully able to get past my blocker. It was (as expected) a total newbie mistake. Once I added my current state to git, the paths resolved correctly and I was able to get things working. I’m on to new errors to solve
I still do have 3 /nix/store/<hash>-retroarch-with-cores-1.16.0.3 folders that are not identical but at least ${pkgs.retroarchFull} resolves to the one I need.
I’m glad you got your problem resolved, @jaylward, but I was wondering if you might explain a bit more what you did to fix it. I didn’t understand what you meant by your quote above.
I forgot that, when using flakes, you need to add all your files to git before rebuilding. Mentioned in the Git Warning here.
In my case, the "${pkgs.retroarchFull}" was not resolving correctly because (I think) the expected package was not being copied over into the /nix/store and whatever other retroarch folders that l found using find were unrelated.
I’m still pretty confused by the whole thing but hopefully that helps. Basically, when using flakes, git add . before sudo nixos-rebuild switch --flake /etc/nixos
This isn’t that uncommon; there’s no guarantee that a package’s name is unique in Nixpkgs, and the source link that shows up in Nixpkgs search is only smart enough to point to wherever the meta.description attribute is defined, which is often (as it is in this case) a wrapper script file used in multiple packages.
If you have two package attributes (retroarchFull and retroarch, here) and you want to know how they’re different, the thing to do¹ is to look in pkgs/top-level/all-packages.nix and compare those definitions. In this case, we have:
From the use of override, we see that retroarchFull is exactly retroarch, but with all supported cores added from libretro (retroarch itself defaults to an empty list of cores, a fact you can learn from reading the wrapper script linked from the Nixpkgs search).
So it seems not to be a bug that this package appears twice. They are indeed two different packages.
¹ If you’re reading this in the future, the packages you’re looking for may not be in that file anymore. There’s a new organization scheme slowly being applied to Nixpkgs, in which package files are placed under pkgs/by-name. The thing to do then would be to compare the two package files in the directories corresponding to the attribute names.
You’re not wrong! Package names are generally a little weird, though. They used to be a primary way you’d reference a package to install it using nix-env, but nowadays imperative use of nix-env is strongly discouraged and there’s much more emphasis on using attribute paths to identify a package. I think package names are sort of left hanging around because they’re somewhat useful for identifying what a store path is, but they don’t get much care applied to them because people aren’t interacting with them directly.
I actually think the Nixpkgs search app shouldn’t display them at all, but that might be a spicy take.
and I need to manually refer to where that snes9x is installed, I can do a find /nix/store | grep '*libretro_snes9x.so' and I see multiple results inside the nix store. How do I programmatically resolve those paths?
I asked ChatGPT because it’s been surprisingly useful in learning NixOS and it says retroArchCorePath = "${pkgs.retroarch}/lib/retroarch/cores/"; but that ends up resolving to a different retroarch folder in the /nix/store.
Since ${pkgs.retroarch} is a legitimate expression, is there any way to see what other names are available, ie ${pkgs.XYZ} or ${pkgs.retroarch.XYZ}`. I really don’t understand how to infer these things yet, like listing what’s available within the language.
I feel like if I could get over this hump, I could get a lot more accomplished within the whole ecosystem. Like there’s an API document that I’m missing.
I don’t see it documented anywhere, but I checked the code and it looks like these are exposed as a set named libretro (so you should be able to reference pkgs.libretro.snes9x, and a NixOS package search for libretro. should show everything available):
This set of cores is what gets passed in to retroarchFull:
That’ll get you just the files that are reachable from the system configuration you’re currently running, so you don’t get duplicates from older generations and you don’t have to be constantly garbage collecting.
The online Nixpkgs search is useful when I have no idea where to start.
I don’t know how people who use flakes do it, but for those of us who use channels, the tab completion in nix repl is great for this: