|
2 | 2 | pkgs ? import <nixpkgs> { }, |
3 | 3 | modules ? [ ], |
4 | 4 | outdir ? ".", |
5 | | - bootstrap ? [ ], |
| 5 | + inputs ? null, |
6 | 6 | outputs ? null, |
| 7 | + do-not-edit ? null, |
7 | 8 | import-tree ? ( |
8 | 9 | pkgs.fetchFromGitHub { |
9 | 10 | owner = "vic"; |
|
24 | 25 | type = lib.types.submodule { freeformType = lib.types.lazyAttrsOf lib.types.unspecified; }; |
25 | 26 | }; |
26 | 27 |
|
27 | | - bootstrapInputs = |
28 | | - let |
29 | | - ins = import ./inputs.nix { inherit lib; }; |
30 | | - take = name: { flake-file.inputs.${name} = ins.flake-file.inputs.${name}; }; |
31 | | - names = |
32 | | - if bootstrap == true then lib.attrNames ins.flake-file.inputs else lib.flatten [ bootstrap ]; |
33 | | - in |
34 | | - map take names; |
35 | | - |
36 | 28 | module = { |
37 | 29 | imports = [ |
38 | 30 | tree |
|
45 | 37 | ./../write-flake.nix |
46 | 38 | ./../write-lock.nix |
47 | 39 | ./../flake-options.nix |
48 | | - { imports = bootstrapInputs; } |
49 | | - (if outputs == null then { } else { flake-file.outputs = outputs; }) |
| 40 | + (lib.optionalAttrs (inputs != null) { flake-file.inputs = inputs; }) |
| 41 | + (lib.optionalAttrs (outputs != null) { flake-file.outputs = strOrFile outputs; }) |
| 42 | + (lib.optionalAttrs (do-not-edit != null) { flake-file.do-not-edit = strOrFile do-not-edit; }) |
| 43 | + |
| 44 | + bootstrap-app |
50 | 45 | ]; |
51 | 46 | config.flake-file.intoPath = outdir; |
52 | 47 | options = { |
|
56 | 51 | }; |
57 | 52 | }; |
58 | 53 |
|
59 | | - evaled = lib.evalModules { |
60 | | - modules = [ module ]; |
61 | | - specialArgs.inputs.self.outPath = ""; |
| 54 | + strOrFile = str: if builtins.isPath str then builtins.readFile str else str; |
| 55 | + |
| 56 | + bootstrap-app = { |
| 57 | + flake-file.apps.bootstrap = |
| 58 | + pkgs: |
| 59 | + let |
| 60 | + inputs = ''{ flake-file.url = "github:vic/flake-file"; }''; |
| 61 | + notice = pkgs.writeText "notice" '' |
| 62 | + # DO-NOT-EDIT. Generated by github:vic/flake-file from flake-file.nix. Regen with: |
| 63 | + # nix-shell https://github.com/vic/flake-file/archive/main.zip -A flake-file.sh --run bootstrap |
| 64 | + ''; |
| 65 | + in |
| 66 | + pkgs.writeShellApplication { |
| 67 | + name = "bootstrap"; |
| 68 | + text = '' |
| 69 | + if ! test -f flake-file.nix; then |
| 70 | + cp flake.nix flake-file.nix |
| 71 | + fi |
| 72 | + nix-shell ${../..} -A flake-file.sh --run write-flake \ |
| 73 | + --arg modules ./flake-file.nix \ |
| 74 | + --arg do-not-edit ${notice} \ |
| 75 | + --argstr outputs flake-module \ |
| 76 | + --arg inputs '${inputs}' |
| 77 | + ''; |
| 78 | + }; |
62 | 79 | }; |
63 | 80 |
|
| 81 | + evaled = lib.evalModules { modules = [ module ]; }; |
| 82 | + |
64 | 83 | in |
65 | 84 | evaled.config |
0 commit comments