diff --git a/README.md b/README.md index b568b4b..2a30f12 100644 --- a/README.md +++ b/README.md @@ -55,5 +55,5 @@ This means ```shell mv flake.nix flake-file.nix -nix-shell https://github.com/vic/flake-file/archive/main.zip -A flake-file.sh --run bootstrap +nix-shell https://github.com/vic/flake-file/archive/main.zip -A bootstrap --run bootstrap ``` diff --git a/dev/_bootstrap-tests.nix b/dev/_bootstrap-tests.nix index e2d6670..aedaf3e 100644 --- a/dev/_bootstrap-tests.nix +++ b/dev/_bootstrap-tests.nix @@ -19,6 +19,16 @@ let outputs = _: { }; }; + broken-app = bootstrap { + inputs.empty.url = "github:vic/empty-flake"; + outputs = _: { }; + flake-file.apps.write-broken = + pkgs: + pkgs.runCommand "write-broken" { } '' + exit 1 + ''; + }; + all-inputs-schemes = bootstrap { inputs.simple.url = "github:vic/empty-flake"; inputs.withBranch.url = "github:vic/empty-flake/main"; @@ -48,6 +58,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 +124,75 @@ let ''; }; + test-flake-public = pkgs.writeShellApplication { + name = "test-flake-public"; + runtimeInputs = [ + pkgs.nix + (empty.flake-file.apps.write-flake pkgs) + ]; + text = '' + write-flake + cat ${outdir}/flake.nix + grep github:vic/empty-flake ${outdir}/flake.nix + ''; + }; + + test-flake-public-ignores-broken-app = pkgs.writeShellApplication { + name = "test-flake-public-ignores-broken-app"; + runtimeInputs = [ + pkgs.nix + (broken-app.flake-file.apps.write-flake pkgs) + ]; + text = '' + write-flake + cat ${outdir}/flake.nix + grep github:vic/empty-flake ${outdir}/flake.nix + ''; + }; + + 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 +355,11 @@ pkgs.mkShell { buildInputs = [ test-inputs test-flake + test-flake-public + test-flake-public-ignores-broken-app + 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/index.mdx b/docs/src/content/docs/index.mdx index 53eb547..71c2c0d 100644 --- a/docs/src/content/docs/index.mdx +++ b/docs/src/content/docs/index.mdx @@ -47,7 +47,7 @@ Ever wanted to interpolate a string just to discover inputs are **NOT REAL** Nix ```shell mv flake.nix flake-file.nix -nix-shell https://github.com/vic/flake-file/archive/main.tar.gz -A flake-file.sh --run bootstrap +nix-shell https://github.com/vic/flake-file/archive/main.tar.gz -A bootstrap --run bootstrap ``` ### Features diff --git a/docs/src/content/docs/reference/bootstrap.mdx b/docs/src/content/docs/reference/bootstrap.mdx index d025aa3..1a98820 100644 --- a/docs/src/content/docs/reference/bootstrap.mdx +++ b/docs/src/content/docs/reference/bootstrap.mdx @@ -9,12 +9,17 @@ The bootstrap command lets you generate `flake.nix`, `unflake.nix`, `.tack/`, or ```shell nix-shell https://github.com/vic/flake-file/archive/refs/heads/main.zip \ - -A flake-file.sh --run [--arg ]... + -A --run [--arg ]... ``` ## Apps -The `flake-file.sh` shell provides these commands: +Each app is available as a standalone top-level target. Use the matching +`-A ` target when running one command so unrelated backends are not +realized. Use `-A flake-file.sh` only when you want an aggregate shell with all +commands. + +The bootstrap entrypoint provides these commands: | App | Description | | --- | --- | @@ -46,7 +51,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/docs/src/content/docs/tutorials/bootstrap.mdx b/docs/src/content/docs/tutorials/bootstrap.mdx index ef953ec..38b3c5c 100644 --- a/docs/src/content/docs/tutorials/bootstrap.mdx +++ b/docs/src/content/docs/tutorials/bootstrap.mdx @@ -23,12 +23,12 @@ echo '{ inputs.flake-file.url = "github:vic/flake-file"; }' > flake-file.nix # Generate flake.nix or unflake.nix or npins from flake-file.nix nix-shell https://github.com/vic/flake-file/archive/refs/heads/main.zip \ - -A flake-file.sh --run write-flake --arg modules ./flake-file.nix + -A write-flake --run write-flake --arg modules ./flake-file.nix ``` > See also: all [bootstrap command args](/reference/bootstrap) -Replace `write-flake` with `write-inputs`, `write-unflake`, `write-tack`, or `write-npins` to target a different backend. +Replace `write-flake` in both `-A write-flake` and `--run write-flake` with `write-inputs`, `write-unflake`, `write-tack`, or `write-npins` to target a different backend. ## Using a modules directory @@ -37,7 +37,7 @@ Replace `write-flake` with `write-inputs`, `write-unflake`, `write-tack`, or `wr ```shell "./modules" nix-shell https://github.com/vic/flake-file/archive/refs/heads/main.zip \ - -A flake-file.sh --run write-flake --arg modules ./modules + -A write-flake --run write-flake --arg modules ./modules ``` This is useful when you already have module files and just need the initial `flake.nix` to be generated before Nix can evaluate the flake itself. diff --git a/docs/src/content/docs/tutorials/migrate-flake-parts.mdx b/docs/src/content/docs/tutorials/migrate-flake-parts.mdx index f61d298..27883a0 100644 --- a/docs/src/content/docs/tutorials/migrate-flake-parts.mdx +++ b/docs/src/content/docs/tutorials/migrate-flake-parts.mdx @@ -65,7 +65,7 @@ And now, lets replace `flake.nix` using bootstrapping magic step: ```shell "./modules" "flake-parts" nix-shell https://github.com/vic/flake-file/archive/main.tar.gz \ - -A flake-file.sh --run write-flake \ + -A write-flake --run write-flake \ --arg modules ./modules --argstr outputs flake-parts ``` diff --git a/docs/src/content/docs/tutorials/migrate-no-flakes.mdx b/docs/src/content/docs/tutorials/migrate-no-flakes.mdx index 6c9aad1..8dd62fa 100644 --- a/docs/src/content/docs/tutorials/migrate-no-flakes.mdx +++ b/docs/src/content/docs/tutorials/migrate-no-flakes.mdx @@ -54,7 +54,7 @@ And now, lets generate `./npins` from `./flake-file.nix`. ```shell "./flake-file.nix" "write-npins" nix-shell https://github.com/vic/flake-file/archive/main.tar.gz \ - -A flake-file.sh --run write-npins --arg modules ./flake-file.nix + -A write-npins --run write-npins --arg modules ./flake-file.nix ``` > See also: all [bootstrap command args](/reference/bootstrap) @@ -118,7 +118,7 @@ To update npins from inputs at ./modules do: ```shell "./modules" "write-npins" nix-shell https://github.com/vic/flake-file/archive/main.tar.gz \ - -A flake-file.sh --run write-npins --arg modules ./modules + -A write-npins --run write-npins --arg modules ./modules ``` ### `(A)` flake-like inputs diff --git a/docs/src/content/docs/tutorials/migrate-traditional-flake.mdx b/docs/src/content/docs/tutorials/migrate-traditional-flake.mdx index e5c51cd..ae9f132 100644 --- a/docs/src/content/docs/tutorials/migrate-traditional-flake.mdx +++ b/docs/src/content/docs/tutorials/migrate-traditional-flake.mdx @@ -13,7 +13,7 @@ You can use [`templates/minimal`](https://github.com/vic/flake-file/tree/main/te ```shell mv flake.nix flake-file.nix -nix-shell https://github.com/vic/flake-file/archive/main.tar.gz -A flake-file.sh --run bootstrap +nix-shell https://github.com/vic/flake-file/archive/main.tar.gz -A bootstrap --run bootstrap ``` ## The new `flake.nix` (static Nix) @@ -64,7 +64,7 @@ When your input changes, run it again to propagate your input changes into the **static** `flake.nix`. ```shell -nix-shell https://github.com/vic/flake-file/archive/main.zip -A flake-file.sh --run bootstrap +nix-shell https://github.com/vic/flake-file/archive/main.zip -A bootstrap --run bootstrap ```