Nix 101 Course / Section 5: Packaging real software with stdenv.mkDerivation
Premium

5.8 Fetching sources: fetchurl, fetchgit, and fixed-output derivations

Lesson 37 of 68 · 12:41

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Pinning Nix Sources and Updates
  2. 1:24 Fixed-Output Derivations and Fetchers
  3. 4:18 Hash Mismatches and Prefetching
  4. 8:14 Fetcher Variants and Next Steps
Transcript

Pinning Nix Sources and Updates

0:00 Okay, so we just had an early and quick glance in how do you even fetch Nix packages from a crisp and defined source that's easy to update, where you could just run nixtamal refresh and do that every week. That's kind of the same like npins update or niv update or Nix flake update. So these tools all work similar. And we just learned how to use one non flake tool for that. And the rest of the process will be later very analogous. However, now we also have seen what a fixed output derivation is and how do we actually download other things than just Nix packages from those.

0:39 So if you end up with a derivation where you say, okay, this is some package, but we don't host it in our own Git repository, it's somewhere outside, maybe it's something that's not contained by Nix packages, but you still need it, then you would also not want to like hard fork the repository in your local GitLab or something or I don't know, Git sub-modules are also very often a bad idea. Instead, you could just say you use one of the available fetchers, like for example packages fetch URL, then download the package from wherever.

1:15 Maybe it's not even available as a Git repository, but it's an FTP download or whatnot. It's all possible, right? And then we define the output hash here, and that means that before we can build this package,

The full transcript comes with the lesson.

About this lesson

Real projects depend on sources you don't host: upstream tarballs, GitHub repos, internal Git servers. This lesson shows how Nix downloads them reproducibly, and answers a question every newcomer asks: why do you start with a wrong hash on purpose?

In this video

  • The fake hash workflow: how practitioners add a new download in under a minute
  • Why bumping a version sometimes changes nothing at all, and the caching detail behind it
  • Fixed output derivations: the one case where a sandbox may use the network, and why that is still safe
  • A tour of the fetchers: fetchurl, fetchzip, fetchpatch, fetchgit with submodules and authentication, fetchFromGitHub, and when companies write their own
  • Trust on first use or verifying up front, plus the prefetch tools for large downloads

After this lesson

You can wire any external source into a derivation, keep it reproducible, and update it without stumbling over the stale hash trap.

Links: