Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install binary file into NixOS

Tags:

nixos

nixpkgs

I'm trying to install external binary inside NixOS, using declarative ways. Inside nix-pkg manual, I found such way of getting external binary inside NixOS

{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation {
  name = "goss";
  src = pkgs.fetchurl {
    url = "https://github.com/aelsabbahy/goss/releases/download/v0.3.13/goss-linux-amd64";
    sha256 = "1q0kfdbifffszikcl0warzmqvsbx4bg19l9a3vv6yww2jvzj4dgb";
  };
  phases = ["installPhase"];             
  installPhase = ''
  
  '';

But I'm wondering, what should I add inside InstallPhase, to make this binary being installed inside the system?

like image 327
dragonhaze Avatar asked Oct 15 '25 14:10

dragonhaze


1 Answers

This seems to be an open source Go application, so it's preferable to use Nixpkgs' Go support instead, which may be more straightforward than patching a binary.

That said, installPhase is responsible creating the $out path; typically mkdir -p $out/bin followed by cp, make install or similar commands.

So that's not actually installing it into the system; after all Nix derivations are not supposed to have side effects. "Installing" it into the system is the responsibility of NixOS's derivations, as configured by you.

You could say that 'installation' is the combination of modifying the NixOS configuration + switching to the new NixOS. I tend to think about the modification to the configuration only; the build and switch feel like implementation details, even though nixos-rebuild is usually a manual operation.

Example:

installPhase = ''
  install -D $src $out/bin/goss
  chmod a+x $out/bin/goss
'';

Normally chmod would be done to a local file by the build phase, but we don't really need that phase here.

like image 60
Robert Hensing Avatar answered Oct 18 '25 12:10

Robert Hensing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!