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:

{ stdenvNoCC, lib }: stdenvNoCC.mkDerivation {
  # ...
}

You can find multiple tutorials online to create your own derivation:

You can use some nice builtins functions:

Do not forget to import your new package in pkgs/default.nix:

pkgs: {
  your-package = pkgs.callPackage ./your-package { };
}

Then in your home-manager configuration, you can import like this:

{ outputs, pkgs, systemSettings, ... }: {
  home.packages = with pkgs; [
    outputs.packages.${systemSettings.system}.openfortivpn-webview
  ];
}

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, …