add external binary in $PATH in NixOS
If you want to install a tool / binary that is not present in the nixpkgs
, you will need to create a custom package / derivation and import in your home-manager configuration.
Info
What are derivations?
Derivations are produced in Nix (the language) by the derivation function (or any of the higher-level helpers like mkDerivation or buildPythonPackage). A derivation is saved as a .drv file to the nix store. It is ultimately this .drv file, which Nix uses to build and install the software or resources (fonts, icon packs, …).
First create a pkgs/your-package/default.nix
with the following content:
You can find multiple tutorials online to create your own derivation:
- https://nix.dev/tutorials/packaging-existing-software
- https://zero-to-nix.com/concepts/derivations
- https://ianthehenry.com/posts/how-to-learn-nix/my-first-derivation/
- https://nix.dev/manual/nix/2.22/language/derivations.html
- https://nix4noobs.com/packages/hello_world/
You can use some nice builtins functions:
- builtins.fetchTarball
- builtins.fetchUrl
- builtins.fetchGit
- builtins.fetchFromGitHub (:warning: big H)
- builints.fetchzip (:warning: small z)
Do not forget to import your new package in pkgs/default.nix
:
Then in your home-manager configuration, you can import like this:
Source: https://github.com/Misterio77/nix-starter-configs/issues/62.
You could also use nix-init for generating nix packages from URLs with hash prefetching, dependency inference, license detection, …