Skip to content

refactor: drop nixpkgs lib dependency (pure builtins tree reader)#36

Open
sini wants to merge 1 commit into
mainfrom
refactor/drop-nixpkgs-lib
Open

refactor: drop nixpkgs lib dependency (pure builtins tree reader)#36
sini wants to merge 1 commit into
mainfrom
refactor/drop-nixpkgs-lib

Conversation

@sini

@sini sini commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Removes the nixpkgs lib dependency from the tree reader. The library core is now pure builtinsimport-tree stays a zero-dependency flake (no new inputs).

The seven lib helpers previously used were handled two ways:

  • lib.pipe — restructured away, not vendored. Both pipe chains became plain let-bindings. The makeRelative chain (which built a list of isFileRelative partial applications and fold-applied over it) collapses into a direct builtins.foldl' (acc: root: isFileRelative root acc) over the root dirs — a genuine simplification.
  • Genuine primitives vendored inline, each with a provenance comment naming its nixpkgs origin: flatten, hasPrefix, removePrefix, hasSuffix, hasInfix, listFilesRecursive. hasInfix is a literal substring scan (no regex-escaping surface); behavior-identical for its sole internal use.

Every vendored util was cross-checked against nixpkgs.lib over sampled and adversarial inputs (regex-meta chars, newlines, empty/oversized infixes) — no divergences. listFilesRecursive output is byte-identical (order + set).

Behavior change

The withLib / lib-threading machinery existed only to obtain those helpers, so it dissolves (no lib == null throw, no leafs = lib: threading, no module = { lib, ... }: delay trick). As a result, .leafs, .files and .pipeTo now work everywhere with zero setup — no withLib call needed, including outside module evaluation.

withLib is retained as a silent no-op so existing it.withLib pkgs.lib callers keep working; it is removed from the docs. The emitted module stays a lambda, so the tree read remains deferred to module-eval (constructing it ./dir does not walk the filesystem).

Tests & docs

  • 34/34 tests pass; treefmt clean; just ci green.
  • The old "fails if no lib has been set" test (which asserted the now-removed throw) is replaced with tests that the reader works without withLib and that withLib remains a working no-op.
  • All withLib references removed from docs; combinator-guide examples reworked to lib-free demo operations.

The tree reader used seven nixpkgs lib helpers. Restructure the two
`lib.pipe` chains into plain let-bindings (the `makeRelative` function-list
fold collapses into a direct `builtins.foldl'` over the roots) and vendor the
genuine primitives inline: `flatten`, `hasPrefix`, `removePrefix`, `hasSuffix`,
`hasInfix`, and `listFilesRecursive`. Each carries a provenance comment naming
its nixpkgs origin; all are behavior-identical (verified against nixpkgs over
sampled and adversarial inputs, incl. regex-meta chars and newlines).

The whole `withLib`/lib-threading machinery existed only to obtain those
helpers, so it dissolves: no more `lib == null` throw, no `leafs = lib:`
threading, no `module = { lib, ... }:` delay trick. Consequence: `.leafs`,
`.files` and `.pipeTo` now work everywhere with zero setup, including outside
module evaluation.

`withLib` is retained as a silent no-op so existing `it.withLib pkgs.lib`
callers keep working, and is removed from the docs. The library keeps its
zero-dependency flake (no new inputs).

34/34 tests pass; treefmt clean.
@sini sini requested a review from vic July 2, 2026 22:05
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.

1 participant