diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-04-02 13:15:35 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-04-02 13:24:34 +0200 |
commit | 7a366a44cf7f0aa2cb3471b9b03a83acba157707 (patch) | |
tree | 459d6fb8d965111414fb187415aad0d16dc64792 | |
parent | chore(version): v0.5.0 (diff) | |
download | flake-templates-7a366a44cf7f0aa2cb3471b9b03a83acba157707.tar.gz flake-templates-7a366a44cf7f0aa2cb3471b9b03a83acba157707.zip |
build(update_common_files): Allow to specify which file to move where
-rw-r--r-- | common/default.nix | 39 | ||||
-rw-r--r-- | flake.nix | 3 | ||||
-rwxr-xr-x | update_common_files.sh | 18 |
3 files changed, 55 insertions, 5 deletions
diff --git a/common/default.nix b/common/default.nix new file mode 100644 index 0000000..473d4f8 --- /dev/null +++ b/common/default.nix @@ -0,0 +1,39 @@ +# This file specifies which files in the `./common` directory should be copied to which +# template in `./templates` +let + programmingLanguages = [ + "awk" + "c" + "rust" + "shell" + ]; + allLanguages = + programmingLanguages + ++ [ + "latex" + ]; + mkName = name: "./${name}"; + + mkBase = name: langs: { + "${mkName name}" = langs; + }; + + mkLang = name: lang: let + realLang = + if builtins.elem lang allLanguages + then lang + else builtins.throw "${lang} is not a recognized language!"; + in + mkBase name [realLang]; + mkProgramming = name: + mkBase name programmingLanguages; + mkAll = name: + mkBase name allLanguages; + +in + {} + // (mkAll ".licensure.yml") + // (mkAll "init") + // (mkAll "scripts/renew_copyright_header.sh") + // (mkAll "shell_line_editor.sh") + // (mkAll "treefmt.nix") diff --git a/flake.nix b/flake.nix index ba19638..381c846 100644 --- a/flake.nix +++ b/flake.nix @@ -38,6 +38,9 @@ devShells.default = pkgs.mkShell { packages = with pkgs; [ cocogitto + + # needed for the `update_common_files` script + jq ]; }; diff --git a/update_common_files.sh b/update_common_files.sh index 3b7dddd..c9c06c0 100755 --- a/update_common_files.sh +++ b/update_common_files.sh @@ -5,14 +5,22 @@ ROOT="$(git rev-parse --show-toplevel)" # This results in fd returning relative paths cd "$ROOT/common" || echo "BUG, no root dir!" -fd . "." --type file --hidden | while read -r file; do +file_spec="$(nix eval --file "$ROOT/common/default.nix" --json)" + +echo "$file_spec" | jq --raw-output 'keys | join("\n")' | while read -r file; do [ -n "$first_run_done" ] && echo echo "Instantiating '$file'..." - fd . "../templates" --type directory --max-depth 1 | while read -r template; do - echo " done in '$template'." - rm "$template$file" - cp "$file" "$template$file" + + echo "$file_spec" | jq --raw-output ".[\"$file\"] | join(\"\n\")" | while read -r language; do + template="$ROOT/templates/$language"; + echo " done for '$language'." + + mkdir --parents "$(dirname "$template/$file")" + rm "$template/$file" + cp "$file" "$template/$file" done + + first_run_done=yes done |