Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions dev/_bootstrap-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,36 @@ let
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
};

bootstrap-all = import ./.. (
args
// {
bootstrap = true;
modules = { outputs = _: { }; };
}
);

bootstrap-selected = import ./.. (
args
// {
bootstrap = [
"flake-file"
"nixpkgs"
];
modules = { outputs = _: { }; };
}
);

bootstrap-override = import ./.. (
args
// {
bootstrap = true;
modules = {
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
outputs = _: { };
};
}
);

flake-parts-follows = bootstrap {
inputs.nixpkgs-lib.url = "github:vic/empty-flake";
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
Expand Down Expand Up @@ -84,6 +114,49 @@ let
'';
};

test-bootstrap-all-inputs = pkgs.writeShellApplication {
name = "test-bootstrap-all-inputs";
runtimeInputs = [
(bootstrap-all.flake-file.apps.write-inputs pkgs)
];
text = ''
write-inputs
grep github:vic/import-tree ${outdir}/inputs.nix
grep github:vic/flake-file ${outdir}/inputs.nix
grep github:hercules-ci/flake-parts ${outdir}/inputs.nix
grep nixpkgs-unstable ${outdir}/inputs.nix
'';
};

test-bootstrap-selected-inputs = pkgs.writeShellApplication {
name = "test-bootstrap-selected-inputs";
runtimeInputs = [
(bootstrap-selected.flake-file.apps.write-inputs pkgs)
];
text = ''
write-inputs
grep github:vic/flake-file ${outdir}/inputs.nix
grep nixpkgs-unstable ${outdir}/inputs.nix
if grep github:vic/import-tree ${outdir}/inputs.nix; then
exit 1
fi
if grep github:hercules-ci/flake-parts ${outdir}/inputs.nix; then
exit 1
fi
'';
};

test-bootstrap-input-override = pkgs.writeShellApplication {
name = "test-bootstrap-input-override";
runtimeInputs = [
(bootstrap-override.flake-file.apps.write-inputs pkgs)
];
text = ''
write-inputs
grep github:nixos/nixpkgs/nixos-unstable ${outdir}/inputs.nix
'';
};

test-npins = pkgs.writeShellApplication {
name = "test-npins";
runtimeInputs = [
Expand Down Expand Up @@ -246,6 +319,9 @@ pkgs.mkShell {
buildInputs = [
test-inputs
test-flake
test-bootstrap-all-inputs
test-bootstrap-selected-inputs
test-bootstrap-input-override
test-unflake
test-npins
test-npins-schemes
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/reference/bootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The Nix file or directory containing your flake-file module definitions. All `.n

### `bootstrap`

Include predefined inputs from the built-in `bootstrap.nix`. When set to `true`, all bootstrap inputs are included. When set to a list, only the named inputs are included.
Include predefined inputs from `modules/bootstrap/inputs.nix`. When set to `true`, all bootstrap inputs are included. When set to a list, only the named inputs are included. These defaults are imported before your modules, so your modules can override them.

- **Type:** `true` | list of input names
- **Default:** `[]` (none)
Expand Down
15 changes: 15 additions & 0 deletions modules/bootstrap/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
pkgs ? import <nixpkgs> { },
modules ? [ ],
bootstrap ? [ ],
outdir ? ".",
inputs ? null,
outputs ? null,
Expand All @@ -20,13 +21,27 @@ let

tree = (import import-tree) modules;

bootstrapModule =
if bootstrap == true then
./inputs.nix
else if builtins.isList bootstrap then
let
allInputs = (import ./inputs.nix { inherit lib; }).flake-file.inputs;
in
{ flake-file.inputs = lib.filterAttrs (name: _: builtins.elem name bootstrap) allInputs; }
else if bootstrap == false then
{ }
else
throw "flake-file bootstrap must be true, false, or a list of input names";

attrsOpt = lib.mkOption {
default = { };
type = lib.types.submodule { freeformType = lib.types.lazyAttrsOf lib.types.unspecified; };
};

module = {
imports = [
bootstrapModule
tree
./../default.nix
./../options
Expand Down
Loading