How to find the expression a given nixpkg is derived from

Howdy!

I am curious if there is a way to get the specific expression a nix package was derived from. In particular, I can’t seem to find the correct expression for font-awesome. None of the results from the webpage link to the source, but I have found this on github. It doesn’t seem to be the correct file, however. Specifically, none of the meta information seems to line up.

Here is the results from some commands that I think might be relevant.

> sudo nix-channel --list
nixos https://nixos.org/channels/nixos-20.09

> nix repl
nix-repl> pkgs = import <nixpkgs> {}
nix-repl> pkgs.font-awesome.meta
{ homepage = "https://github.com/FontAwesome/Font-Awesome"; }

Here is what I expect for the meta information (what can be seen in the github source file). In particular, look at the homepage.

{
   description = "Font Awesome - OTF font";
   long-description = "Font awesome gives you scalable vector ...";
   homepage = "http://fortawesome.github.io/Font-Awesome/";
}

Please feel free to correct any misunderstanding or request further information. I am new to this community/technology, so I am sure I have made several mistakes.

Thanks!
smkuehnhold

1 Like

All (or at least the vast majority) of packages are added in pkgs/top-level/all-packages.nix.

Ctrl+f for font-awesome gives:

From there you can kind of “backtrack” exactly how the package is built.

2 Likes

This is a common need. Especially when wanting to view a diff, but a tool like nix-diff shows the underlying derivation changes, not the high-level Nix expression. This is very hard for beginners.

The fact that the entire nixpkgs doesn’t enter the closure allows for a derivation to remain the same, and there are good reasons not to pollute the closure. but I’ve often wished for an impure tag/metadata in derivations that would help track down exactly what nixpkgs version it came from. This may be possible with adding a tag to passthru or meta?

NixOS has a copySystemConfiguration to aid in a related situation.

Or to put it yet another way - one can go from a runtime path to derivation info (usually aided by the Nix db), how can one climb even higher to the high-level Nix? I’d imagine this can be a tool/db that remembers this. Basically wrap “nix build” or a hook in an early stage of the evaluator.

Would something like this be of value? and make things more discoverable?

2 Likes

I seem to have the same problem, or am continuing to misunderstand something. The package being called for font-awesome contains different meta information than the one I can find on my system. Also, do you mind sharing the significance of the “c8e32eddf8” branch?

Thanks!

Sounds like it would certainly be useful to me (especially in my current situation)! Although, I am not knowledgeable enough to understand the ramifications of such an extension.

1 Like

The “c8e32eddf8” branch was simply master when I copied the link.

But I found the issue:

So, this line nixpkgs/default.nix at 76ed24ceab9ec8b520f977a2803181f0c1d86b4d · NixOS/nixpkgs · GitHub says:

[...]
font-awesome = { version, sha256, rev ? version}: fetchFromGitHub {
[...]

checking out fetchFromGitHub, at the very bottom:

[...]
fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; }

This is what mangles the meta-information from the original package. Congratulations, guess you found a bug :slight_smile:

2 Likes

If you have nix-command option enabled for nixUnstable, you can also do nix edit nixpkgs#font-awesome, which will get you:

  # all-packages.nix
  font-awesome_4 = (callPackage ../data/fonts/font-awesome-5 { }).v4;
  font-awesome_5 = (callPackage ../data/fonts/font-awesome-5 { }).v5;
  font-awesome = font-awesome_5;

For builds that are “more regular” (don’t return a set of derivations, but just derivation), you would get something like, nix edit nixpkgs#ripgrep:

# pkgs/tools/text/ripgrep/default.nix
{ lib, stdenv
, fetchFromGitHub
, rustPlatform
, asciidoctor
, installShellFiles
...
5 Likes