Generate flake.nix from module options. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/
dendrix.oeiuwq.com/Dendritic.html
dendritic
nix
inputs
1{ lib, config, ... }:
2let
3 inherit (config) flake-file;
4 apps = flake-file.apps;
5
6 candidates = [
7 {
8 file = "flake.lock";
9 app = "write-flake";
10 }
11 {
12 file = "npins/sources.json";
13 app = "write-npins";
14 }
15 {
16 file = flake-file.nixlock.lockFileName;
17 app = "write-nixlock";
18 }
19 {
20 file = "unflake.nix";
21 app = "write-unflake";
22 }
23 ];
24
25 available = builtins.filter (d: apps ? ${d.app}) candidates;
26
27 dispatch = lib.concatMapStringsSep "\n" (
28 d: ''[ -e ${lib.escapeShellArg "${flake-file.intoPath}/${d.file}"} ] && exec ${d.app} "$@"''
29 ) available;
30
31 write-lock =
32 pkgs:
33 pkgs.writeShellApplication {
34 name = "write-lock";
35 runtimeInputs = map (d: apps.${d.app} pkgs) available;
36 text = dispatch;
37 };
38in
39{
40 config.flake-file.apps = { inherit write-lock; };
41}