Skip to content

Build-time flake inputs #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: detsys-main
Choose a base branch
from
Open

Conversation

edolstra
Copy link
Collaborator

@edolstra edolstra commented May 1, 2025

Motivation

This PR does two things:

  • It adds a new builtin derivation builder named builtin:fetch-tree, which is similar to builtins.fetchTree but works at build time rather than eval time.

  • It allows flake inputs to be fetched at build time. Example:

    inputs.repo1 = {
      type = "github";
      owner = "DeterminateSystems";
      repo = "blabla";
      flake = false; # <-- currently required
      buildTime = true;
    };

    call-flake.nix maps this to a builtin:fetch-tree derivation. Thus you can pass it to other derivations, and it will be fetched at build time rather than eval time. (It will still be fetched at eval time to create/update locks.)

    Inputs like this can be passed to derivations as usual, e.g.

  outputs = { self, nixpkgs, repo1 }: {
    packages.x86_64-linux.default =
      with import nixpkgs { system = "x86_64-linux"; };
      stdenv.mkDerivation {
        ...
        src = repo1;
      };
  };

Note that trying to access them at evaluation time (e.g. import repo1) will trigger import-from-derivation behaviour, i.e. it will cause a build during evaluation.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Copy link

github-actions bot commented May 1, 2025

@github-actions github-actions bot temporarily deployed to pull request May 1, 2025 17:56 Inactive
@lucperkins

This comment was marked as resolved.

@edolstra edolstra force-pushed the build-time-fetch-tree branch from 88d5913 to d146d3b Compare May 9, 2025 14:35
@github-actions github-actions bot temporarily deployed to pull request May 9, 2025 14:46 Inactive
@edolstra edolstra force-pushed the build-time-fetch-tree branch from d146d3b to 36a25f9 Compare May 12, 2025 11:07
@github-actions github-actions bot temporarily deployed to pull request May 12, 2025 11:19 Inactive
edolstra added 9 commits May 13, 2025 10:31
This builtin builder is similar to `builtins.fetchTree` but works at build time.
This is needed for builtin:fetch-tree to get access to it.
This only works for non-flake inputs. Example:

  inputs.repo1 = {
    type = "github";
    owner = "DeterminateSystems";
    repo = "blabla";
    flake = false;
    buildTime = true;
  };

`call-flake.nix` maps this to a builtin:fetch-tree derivation. Thus
you can pass it to other derivations, and it will be fetched at build
time rather than eval time. (It will still be fetched at eval time to
create/update locks.) Importing from such an input triggers IFD.
@edolstra edolstra force-pushed the build-time-fetch-tree branch from 36a25f9 to febe4de Compare May 13, 2025 08:31
@github-actions github-actions bot temporarily deployed to pull request May 13, 2025 08:44 Inactive
@edolstra edolstra changed the title WIP: Build-time flake inputs Build-time flake inputs May 14, 2025
@github-actions github-actions bot temporarily deployed to pull request May 14, 2025 14:03 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 14, 2025 15:32 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants