import-tree icon indicating copy to clipboard operation
import-tree copied to clipboard

Create API for adding to scope

Open theutz opened this issue 6 months ago • 2 comments

Extend the import-tree API so that users can easily add variable values that are automagically imported into every scope.

POC from @sini

inputs@{
  import-tree,
  flake-parts,
  den,
  ...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
  imports = [
    den.flakeModule
    # Load all modules with scopedImport so <aspect> syntax works
    # without per-file __findFile headers.
    (
      { den, ... }:
      {
        imports = [
          (import-tree.map (
            path:
            builtins.scopedImport {
              inherit builtins den;
              __findFile = den.lib.__findFile;
              __nixPath = [ ];
            } path
          ) ./modules)
        ];
      }
    )
  ];
}

Allows you to use den's <angle bracket> syntax without importing __findFile on each scope. Also allows you to reference den without importing it explicitly.

theutz avatar May 14 '26 07:05 theutz

And then maybe some convenience functions around that? I don't know if a builder pattern like this is even possible with nix...

import-tree.withDen.withAngleBrackets.withPipe ./modules

theutz avatar May 14 '26 07:05 theutz

Yep that is possible, but will be done at Den side. import-tree already provides addAPI and builder-pattern chains.

Fixed in #31

vic avatar May 14 '26 08:05 vic