this post was submitted on 24 Oct 2023
2 points (100.0% liked)

nixos

1244 readers
1 users here now

All about NixOS - https://nixos.org/

founded 4 years ago
 

This is something that I struggle with. I know how to find top-level packages like git or cowsay. But what about utilities under nested paths? I always spend ages digging through the nixpkgs source code to try to find utilities to use in my nix expressions.

Today I want to use buildRustPackage. It's defined here, and is propagated here. But how do I access it given a pkgs variable? I have no idea!

https://search.nixos.org/packages is no help

nix search nixpkgs doesn't find it

I think I need to search by attribute name, not by derivation name. But I don't know how to do that.

top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 3 points 10 months ago (1 children)

There was a talk about that problem at this years NixCon, maybe it'll give you some ideas.

https://media.ccc.de/v/nixcon-2023-36333-finding-things-in-nixpkgs-and-nixos-source

[–] [email protected] 1 points 10 months ago

Oh very nice - thanks!

[–] [email protected] 1 points 10 months ago* (last edited 10 months ago)

After some more digging I think I figured it out.

I was trying to use nix repl nixpkgs to interactively query packages. But I forgot that that command loads the flake, not the package set. You have to prefix everything with legacyPackages.x86_64-linux. to access packages in this environment. I got better results running nix repl followed by :l angle-bracket nixpkgs angle-bracket. (Btw the repl tells me how many variables have been loaded. Is there a way to list them? That would be helpful.) (Edit: nix repl nixpkgs#legacyPackages.x86_64-linux also works)

I eventually found https://github.com/NixOS/nixpkgs/blob/35d87899f7c8f6fad50447301465d51b5dd87753/doc/languages-frameworks/rust.section.md?plain=1#L18 which tells me that what I want is pkgs.rustPlatform.buildRustPackage

I would still like a way to search for nested attributes.