about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--common/default.nix39
-rw-r--r--flake.nix3
-rwxr-xr-xupdate_common_files.sh18
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