Skip to content

Instantly share code, notes, and snippets.

@sortofsleepy
Last active July 12, 2026 21:14
Show Gist options
  • Select an option

  • Save sortofsleepy/cdaa4c2fb8c89a44fd55fa8022450714 to your computer and use it in GitHub Desktop.

Select an option

Save sortofsleepy/cdaa4c2fb8c89a44fd55fa8022450714 to your computer and use it in GitHub Desktop.
Nix package derivation example
# Fetches the specified version of Odin
odin-fetch = pkgs.stdenv.mkDerivation {
pname = "odin-source";
version = odin-version; # references a variable declared earlier in the file
src = pkgs.fetchurl {
url="https://github.com/odin-lang/Odin/releases/download/${odin-version}/odin-linux-amd64-${odin-version}.tar.gz";
# When you change versions, you should get an error pointing to the correct SHA
hash = "sha256-zX7CzRqyhAoLfrwY5ctBxnG86HsS8Fb92+8/CAtN3n0=";
};
#nativeBuildInputs = [pkgs.makeWrapper];
#postFixup = ''
#wrapProgram $out/bin/odin \
#--set ODIN_ROOT $out/share/odin
#'';
buildInputs = [
pkgs.llvm
pkgs.clang
pkgs.libiconv
];
installPhase = ''
mkdir -p $out/bin $out/share/odin
cp odin $out/bin
cp -r base core vendor $out/share/odin/
'';
};
@sortofsleepy

sortofsleepy commented Jun 9, 2026

Copy link
Copy Markdown
Author

This shows a basic derivation of how to download a package outside of Nix packages and use it in the rest of your flake.

note that for Odin specifically, you'll need to either add

ODIN_ROOT = "${self.packages.${system}.odin-fetch}/share/odin";

to any derivations that need to utilize Odin or adjust odin-fetch to include

nativeBuildInputs = [pkgs.autoPatchelfHook];

and add a phase

postFixup = ''
  wrapProgram $out/bin/odin \
   --set ODIN_ROOT $out/share/odin
'';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment