Skip to content

Comments

builtins.getFlake: Support path values#338

Merged
edolstra merged 1 commit intomainfrom
getflake-path
Feb 6, 2026
Merged

builtins.getFlake: Support path values#338
edolstra merged 1 commit intomainfrom
getflake-path

Conversation

@edolstra
Copy link
Collaborator

@edolstra edolstra commented Feb 6, 2026

Motivation

This allows doing

builtins.getFlake ./..

instead of the hacky

builtins.getFlake (builtins.flakeRefToString { type = "path"; path = self.sourceInfo.outPath; narHash = self.narHash; });

Depends on #337.

Issue #302.

Context

Summary by CodeRabbit

  • New Features

    • New ways to lock a flake using a directory or explicit flake input, giving more flexible lock workflows.
  • Refactor

    • Optimized flake resolution to handle path-based and string-based inputs with shared preparatory logic, preserving behavior.
  • Tests

    • Added functional coverage for the new path-based flake resolution alongside the legacy method.

@edolstra edolstra changed the title Getflake path builtins.getFlake: Support path values Feb 6, 2026
@github-actions
Copy link

github-actions bot commented Feb 6, 2026

@github-actions github-actions bot temporarily deployed to pull request February 6, 2026 15:04 Inactive
@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Refactors builtins.getFlake to branch on argument type (path vs non-path) with shared LockFlags preparation, and adds two new lockFlake overloads (FlakeRef and SourcePath) that delegate to a primary overload accepting an explicit Flake.

Changes

Cohort / File(s) Summary
Flake resolution (primops)
src/libflake/flake-primops.cc
getFlake now prepares LockFlags once, branches on argument type: path branch realises the SourcePath and calls flake path-based logic; non-path branch forces the value and performs string-based FlakeRef parsing and validation using the shared LockFlags.
Locking API / core flake logic
src/libflake/flake.cc, src/libflake/include/nix/flake/flake.hh
Introduces primary lockFlake overload that accepts an explicit Flake parameter and two delegating overloads: one taking FlakeRef and one taking SourcePath (flakeDir). Delegating overloads compute or read the Flake and call the primary overload.
Tests
tests/functional/flakes/get-flake.sh
Adds a path-based getFlake test (builtins.getFlake ./..) alongside existing string-based test and exposes both outputs to verify both access patterns evaluate the same value.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Make path inputs lazy #312 — touches lockFlake/getFlake interactions and lock-file cache semantics overlapping this PR's API and flow changes.
  • builtins.getFlake fixes #337 — modifies builtins.getFlake and related tests; closely related to the path vs string branching work.

Suggested labels

flake-regression-test

Suggested reviewers

  • cole-h

Poem

🐰 Hopping through paths and strings so neat,
LockFlags pooled once — what a rhythmic beat.
Overloads align and small changes wink,
A flake finds its home with a happy blink.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'builtins.getFlake: Support path values' clearly and concisely summarizes the main feature addition: enabling path values to be passed to the builtins.getFlake function.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch getflake-path

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/libflake/flake.cc`:
- Around line 959-962: The overload of lockFlake that constructs a fakeRef via
parseFlakeRef("flake:dummy") causes topRef.input.getSourcePath() to be null and
prevents writing lockfiles for local flakes; change the overload (the function
that currently creates fakeRef and calls readFlake) to detect when flakeDir is a
local/rootFS path and construct a path-based FlakeRef whose input.sourcePath is
flakeDir (instead of parseFlakeRef("flake:dummy")), or alternatively ensure
callers pass writeLockFile=false or an explicit outputLockFilePath; update the
call site that uses fakeRef, readFlake, and lockFlake to use the new path-based
FlakeRef so writeLockFile logic can find a valid topRef.input.getSourcePath().
🧹 Nitpick comments (1)
src/libexpr/primops.cc (1)

2371-2374: Avoid double symlink resolution in __narHash.

realisePath already defaults to full symlink resolution, so resolving again adds extra I/O. Consider passing path directly to fetchToStore2.

♻️ Proposed tweak
-            auto hash =
-                fetchToStore2(state.fetchSettings, *state.store, path.resolveSymlinks(), FetchMode::DryRun).second;
+            auto hash =
+                fetchToStore2(state.fetchSettings, *state.store, path, FetchMode::DryRun).second;

@github-actions github-actions bot temporarily deployed to pull request February 6, 2026 15:29 Inactive
@github-actions github-actions bot temporarily deployed to pull request February 6, 2026 16:03 Inactive
Copy link
Member

@cole-h cole-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM.

This allows doing `builtins.getFlake ./subflake` instead of ugly hacks.
@edolstra edolstra enabled auto-merge February 6, 2026 17:19
@github-actions github-actions bot temporarily deployed to pull request February 6, 2026 17:27 Inactive
@edolstra edolstra added this pull request to the merge queue Feb 6, 2026
Merged via the queue into main with commit c9f71f3 Feb 6, 2026
28 checks passed
@edolstra edolstra deleted the getflake-path branch February 6, 2026 18:15
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