Fetching a github repo from a flake

hi there,
i’m trying out writing a package to get familiar with nix flakes, but i seem to not find similar examples somehow.

i’m writing a flake.nix as follows:

  description = "HachiMaruPop is a cute font that was popular among young Japanese girls in the 1970s and 1980s";
  inputs = {
    nixpkgs.url = github:NixOS/nixpkgs/nixos-22.11;
    flake-utils.url = github:numtide/flake-utils;
  outputs = { self, nixpkgs, flake-utils }:
    with flake-utils.lib; eachSystem allSystems (system:
      pkgs = nixpkgs.legacyPackages.${system};
    in rec {
      packages = {
        hachimarupop = pkgs.stdenvNoCC.mkDerivation rec {
          name = "hachimarupop";
          src = fetchGithub {
            owner = "noriokanisawa";
            repo = "HachiMaruPop";
            rev = "67d96c274032f5a2e1d33c1ec53498fde9110079";
            sha256 = "sha256-XoGuzcnzYQUzeQakTRvZKo7X8k5N9luhYkf+VWQ83XI=";
          dontBuild = true;
          installPhase = ''
            runHook preInstall
            install -Dm644 fonts/ttf/*.ttf -t $out/share/fonts/opentype
            runHook postInstall
      defaultPackage = packages.hachimarupop;

however, a nix flake check here fails stating undefined variable 'fetchGithub', understandably.
i thought one might imports this thru e.g. pkgs.lib.fetchGithub or the like, but these seem to fail as well.
what am i missing here?

1 Like

Use pkgs.fetchFromGithub (or GitHub?). The global scope only contains a small handful of things (notably builtins), most things need to be accessed from the nixpkgs scope. “Fetchers” and other “builders” are at the root level, whereas helper functions for programming in nix are in pkgs.lib.

1 Like

that did it. thank you! :slight_smile:


I personally moved these things to the flake inputs. I don’t think there’s anything wrong with the fetchFromGithub approach, but I was faced with updating like 15 versions and then switched to flake inputs.

Alternatively, there’s GitHub - berberman/nvfetcher: Generate nix sources expr for the latest version of packages - I prefer it since it’s a bit more flexible than flake inputs when you want to grab only stable tags and such.

I wonder which is better practice - is nix smart enough to clean up .git directories and such from non-flake inputs when used in derivations? Use fetchFromGithub-alike content hashing so that artifact hashes changing doesn’t break things? The fetchers do quite a lot of work to fix silly websites, I’m not sure flake inputs are flexible enough for that.

1 Like