Generate flake.nix from module options. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic nix inputs
at main 84 lines 2.3 kB view raw
1{ 2 pkgs ? import <nixpkgs> { }, 3 modules ? [ ], 4 outdir ? ".", 5 inputs ? null, 6 outputs ? null, 7 do-not-edit ? null, 8 import-tree ? ( 9 pkgs.fetchFromGitHub { 10 owner = "vic"; 11 repo = "import-tree"; 12 rev = "c968d3b54d12cf5d9c13f16f7c545a06c9d1fde6"; 13 hash = "sha256-oYO4poyw0Sb/db2PigqugMlDwsvwLg6CSpFrMUWxA3Q="; 14 } 15 ), 16 ... 17}: 18let 19 inherit (pkgs) lib; 20 21 tree = (import import-tree) modules; 22 23 attrsOpt = lib.mkOption { 24 default = { }; 25 type = lib.types.submodule { freeformType = lib.types.lazyAttrsOf lib.types.unspecified; }; 26 }; 27 28 module = { 29 imports = [ 30 tree 31 ./../default.nix 32 ./../options 33 ./../npins 34 ./../unflake 35 ./../nixlock 36 ./../write-inputs.nix 37 ./../write-flake.nix 38 ./../write-lock.nix 39 ./../flake-options.nix 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 45 ]; 46 config.flake-file.intoPath = outdir; 47 options = { 48 lib = attrsOpt; 49 templates = attrsOpt; 50 flakeModules = attrsOpt; 51 }; 52 }; 53 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 }; 79 }; 80 81 evaled = lib.evalModules { modules = [ module ]; }; 82 83in 84evaled.config