I would really like to upgrade my Nix skills, but I never have time.

Follow

So I have decided to start my personal Nix FAQ, with questions I ask to myself, and to which I often don't have the answer. Please do not hesitate to provide them 🙂

otini.chnik.fr/posts/personal-

@otini "How to find the Nix store path associated to an installed package?"

I use nix-build for this (though it has the side-effect of downloading/building the package if you *didn't* have it already, it won't add it to your current environment, so no practical difference except disk space)

$ nix-build '<nixpkgs>' -A hello
/nix/store/20liz5dns3dm13gbk5synzf5qjsdpf51-hello-2.10

@telent Ah, thank you very much! 😄 Shall I credit you on the page?

@otini @amiloradovsky that works if the hello package is in your environment, otherwise `which hello` won't find it

@otini @amiloradovsky

macdbarlow:~ daniel.barlow$ which feh
macdbarlow:~ daniel.barlow$ echo $?
1
macdbarlow:~ daniel.barlow$ nix-build '<nixpkgs>' -A feh
/nix/store/6zisv5rmjwj2dziw1ifdxcddnlcv9yl8-feh-3.1.3

@telent @otini Yes, but why would you need to know exact path of a package which you haven't even installed yet? Anyway, alternatively you can use `nix-shell` for that purpose.

@otini

- How can I build a package locally instead of downloading the binary?

Add `--option substitute false`, or set it globally. (search `man nix.conf` for "substitute")

@otini

- Is there a command to delete a specific derivation from the Nix store?

$ nix-store --delete …

You have to be root for that.

Derivations are just one-file store entries, containing low-level building commands, and having .drv extension. Don't take much space.

@amiloradovsky Ok so I guessed my question was, how to uninstall a package and delete the “cached” files, without garbage-collecting entire generations? In order to rebuild a package, for example.

@otini I don't know. But you can garbage-collect only a specified amount of space: e.g.

# nix-store --gc --max-freed 1G

@otini

- How can I get the Nix directory (containing the code and Nix files) of a package?

It's all in `~/.nix-defexpr/channels_root/nixos/`, or in the user's own channel(s).
See there `pkgs/top-level/all-packages.nix`, where all the "packages" have to be registered: some are path to an actual file with a Nix-expression, some are functions, generating the "packages" for each combination of inputs.

But you can't/shouldn't edit those. Clone the repository instead and edit it in there.

Sign in to participate in the conversation
Functional Café

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!