clan-community lib
import-flake.nix
Import a remote flake without builtins.getFlake. Only fetches the source tree
and reuses local inputs where possible, avoiding redundant downloads.
Problem
Using builtins.getFlake on a remote flake fetches all of its inputs
(including its own nixpkgs), even when you already have the same inputs locally.
Solution
import-flake.nix uses builtins.fetchTree to get just the source, reads the
remote flake.lock, and:
- Auto-passes matching local flake inputs (e.g., your nixpkgs, flake-parts)
- Fetches from the remote lock only inputs you don't provide
- Resolves
followscorrectly, so transitive dependencies use your local inputs too
Usage in services
Services declare their external flake dependency via the clan-community.inputs
flake-parts option:
# services/myservice/flake-module.nix
{ config, ... }:
{
config = {
clan-community.inputs.myservice.src = {
type = "github";
owner = "someone";
repo = "myservice";
rev = "abc123...";
};
clan.modules.myservice = import ./default.nix {
inherit (config.clan-community) inputs;
};
};
}
Then in the service module, access the resolved flake:
# services/myservice/default.nix
{ inputs }:
{
_class = "clan.service";
# ...
roles.default.perInstance = { ... }: {
nixosModule = { ... }: {
imports = [ inputs.myservice.outputs.nixosModules.default ];
};
};
}
Overriding from a consumer flake
Users importing clan-community can override the source or specific inputs:
# Override the revision
clan-community.inputs.myservice.src = {
type = "github";
owner = "someone";
repo = "myservice";
rev = "def456...";
};
# Override a specific input of the remote flake
clan-community.inputs.myservice.inputs.some-dep = my-some-dep;
Option reference
clan-community.inputs.<name>.src
Type: attrset (passed to builtins.fetchTree)
The flake source to fetch. Typically { type = "github"; owner; repo; rev; }.
clan-community.inputs.<name>.inputs
Type: attrset of raw values
Default: {}
Override specific inputs of the remote flake. These take precedence over auto-matched local inputs.
clan-community.inputs.<name>.outputs
Type: raw (read-only)
The resolved flake outputs. Equivalent to what builtins.getFlake would return,
but using your local inputs where names match.