{ description = "Hello World flake templates for various languages and build systems"; outputs = { self, ... }: with builtins; let concatMapAttrs = func: attr: foldl' (x: y: x // y) {} (map func attr); # Template Aliases # Used to pick default template for each language aliases = { bash = "bash_script_nixpkgs"; fish = "fish_script_nixpkgs"; c = "c_make_nixpkgs"; python = "python_pyproject_nixpkgs_basic"; rust = "rust_cargo-nightly_crane+fenix"; }; # Get all subdirectories of the given path # Returns [str] subdirs = dir: let subd = readDir dir; in filter (d: subd.${d} == "directory") (attrNames subd); # Get all proper recursive subdirectories with flakes in them # Returns [[str]] (list of subdirectory sequences, for processing) flakeSubdirs = dir: concatMap (subd: if pathExists /${dir}/${subd}/flake.nix then [ [ subd ] ] else map (l: [ subd ] ++ l) (flakeSubdirs /${dir}/${subd})) (subdirs dir); generateDesc = subds: "${head subds} template - ${concatStringsSep ", " (tail subds)}"; in { templates = concatMapAttrs (subds: { ${concatStringsSep "_" subds} = { description = generateDesc subds; path = filterSource (p: _: !(elem (baseNameOf p) [ "flake.lock" "Cargo.lock" ])) (foldl' (dir: subd: /${dir}/${subd}) ./. subds); }; }) (flakeSubdirs ./.) // mapAttrs (from: to: self.templates.${to} // { description = generateDesc (filter (p: p != []) (split "_" to)); }) aliases; }; }