diff --git a/dev/_bootstrap-tests.nix b/dev/_bootstrap-tests.nix index e2d6670..3c3eb92 100644 --- a/dev/_bootstrap-tests.nix +++ b/dev/_bootstrap-tests.nix @@ -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"; @@ -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 = [ @@ -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 diff --git a/docs/src/content/docs/reference/bootstrap.mdx b/docs/src/content/docs/reference/bootstrap.mdx index d025aa3..5ec243f 100644 --- a/docs/src/content/docs/reference/bootstrap.mdx +++ b/docs/src/content/docs/reference/bootstrap.mdx @@ -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) diff --git a/modules/bootstrap/default.nix b/modules/bootstrap/default.nix index 4d8698e..2a8197e 100644 --- a/modules/bootstrap/default.nix +++ b/modules/bootstrap/default.nix @@ -1,6 +1,7 @@ { pkgs ? import { }, modules ? [ ], + bootstrap ? [ ], outdir ? ".", inputs ? null, outputs ? null, @@ -20,6 +21,19 @@ 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; }; @@ -27,6 +41,7 @@ let module = { imports = [ + bootstrapModule tree ./../default.nix ./../options