Generate flake.nix from module options. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic nix inputs

bootstrap can now take a target directory (#69)

authored by oeiuwq.com and committed by

GitHub ec2ff9d5 6cecf9de

+43 -2
+1 -1
.github/workflows/flake-check.yaml
··· 30 30 - uses: DeterminateSystems/magic-nix-cache-action@main 31 31 - uses: actions/checkout@v4 32 32 - run: mkdir bootstrap 33 - - run: cd bootstrap && nix-shell ../default.nix -A flake-file.sh --run write-${{matrix.bootstrap}} --arg modules ../modules/bootstrap.nix 33 + - run: nix-shell ./default.nix -A flake-file.sh --run write-${{matrix.bootstrap}} --arg modules ./modules/bootstrap.nix --argstr outdir bootstrap 34 34 - run: cat bootstrap/inputs.nix 35 35 if: ${{ matrix.bootstrap == 'inputs' }} 36 36 - run: cat bootstrap/flake.nix
+5
default.nix
··· 1 1 { 2 2 pkgs ? import <nixpkgs> { }, 3 3 modules ? [ ], 4 + outdir ? ".", 5 + bootstrap ? true, 4 6 import-tree ? ( 5 7 pkgs.fetchFromGitHub { 6 8 owner = "vic"; ··· 30 32 ./modules/unflake.nix 31 33 ./modules/write-inputs.nix 32 34 ./modules/write-flake.nix 35 + ./modules/flake-options.nix 36 + (if bootstrap then ./modules/bootstrap.nix else { }) 33 37 ]; 38 + config.flake-file.intoPath = outdir; 34 39 options = { 35 40 lib = attrsOpt; 36 41 templates = attrsOpt;
+3 -1
modules/bootstrap.nix
··· 1 1 { 2 2 flake-file.inputs = { 3 - impor-tree.url = "github:vic/import-tree"; 3 + import-tree.url = "github:vic/import-tree"; 4 4 flake-file.url = "github:vic/flake-file"; 5 + flake-parts.url = "github:hercules-ci/flake-parts"; 6 + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 5 7 }; 6 8 }
+3
modules/default.nix
··· 8 8 import-tree 9 9 npins 10 10 unflake 11 + flake-options 11 12 ; 12 13 }; 14 + 15 + flake-options = ./flake-options.nix; 13 16 14 17 base.imports = [ 15 18 ./options
+18
modules/flake-options.nix
··· 1 + { lib, ... }: 2 + let 3 + 4 + # TODO: Extensible flake output schema! 5 + outputsType = lib.types.submodule { 6 + freeformType = lib.types.lazyAttrsOf lib.types.unspecified; 7 + }; 8 + 9 + in 10 + { 11 + imports = [ 12 + (lib.mkAliasOptionModule [ "inputs" ] [ "flake-file" "inputs" ]) 13 + ]; 14 + 15 + options.outputs = lib.mkOption { 16 + type = lib.type.functionTo outputsType; 17 + }; 18 + }
+1
modules/npins.nix
··· 137 137 pkgs.jq 138 138 ]; 139 139 text = '' 140 + cd ${flake-file.intoPath} 140 141 npins init --bare 2>/dev/null || true 141 142 ${addCommands} 142 143 wanted="${pinNames}"
+1
modules/unflake.nix
··· 7 7 pkgs.writeShellApplication { 8 8 name = "write-unflake"; 9 9 text = '' 10 + cd ${flake-file.intoPath} 10 11 nix-shell "${flake-file.unflake.url}" -A unflake-shell --run "unflake -i ${flake-file.inputsFile pkgs} $*" 11 12 ''; 12 13 };
+1
modules/write-flake.nix
··· 86 86 pkgs.writeShellApplication { 87 87 name = "write-flake"; 88 88 text = '' 89 + cd ${config.flake-file.intoPath} 89 90 cp ${formatted pkgs} flake.nix 90 91 ${hooks} 91 92 '';
+10
modules/write-inputs.nix
··· 27 27 pkgs.writeShellApplication { 28 28 name = "write-inputs"; 29 29 text = '' 30 + cd ${flake-file.intoPath} 30 31 cp ${inputsFile pkgs} "''${1:-inputs.nix}" 31 32 ${lib.getExe pkgs.nixfmt} "''${1:-inputs.nix}" 32 33 ''; ··· 54 55 description = "Attrs of (pkgs -> app) to include in shell"; 55 56 }; 56 57 58 + intoPath = lib.mkOption { 59 + internal = true; 60 + visible = false; 61 + type = lib.types.str; 62 + default = "."; 63 + }; 64 + 57 65 inputsFile = lib.mkOption { 58 66 type = lib.types.raw; 59 67 readOnly = true; 60 68 internal = true; 69 + visible = false; 61 70 default = inputsFile; 62 71 }; 63 72 ··· 65 74 type = lib.types.raw; 66 75 readOnly = true; 67 76 internal = true; 77 + visible = false; 68 78 default = shell flake-file.pkgs; 69 79 }; 70 80 };