diff --git a/.bauke/bin/copy-nixos-config b/.bauke/bin/copy-nixos-config new file mode 100755 index 0000000..ea25847 --- /dev/null +++ b/.bauke/bin/copy-nixos-config @@ -0,0 +1,7 @@ +#!/usr/bin/env zsh + +deno run \ + --allow-read \ + --allow-run="hostname,sudo" \ + "$BAUKE_DIR/scripts/copy-nixos-config.ts" \ + "$@" diff --git a/.bauke/scripts/copy-nixos-config.ts b/.bauke/scripts/copy-nixos-config.ts new file mode 100644 index 0000000..ee903ed --- /dev/null +++ b/.bauke/scripts/copy-nixos-config.ts @@ -0,0 +1,34 @@ +import { Command } from "https://deno.land/x/cliffy@v0.25.5/command/mod.ts"; +import { runAndReturnStdout } from "./utilities.ts"; + +async function main(): Promise { + const { options } = await new Command() + .name("copy-nixos-config") + .description( + 'Copy NixOS configuration from "$BAUKE_DIR/nix//" to "/etc/nixos/"', + ) + .option("--hostname", "The machine's configuration to copy.", { + default: (await runAndReturnStdout({ cmd: ["hostname"] })).trim(), + }) + .parse(Deno.args); + + const sourceDir = new URL(`../nix/${options.hostname}/`, import.meta.url); + const files = Array.from(Deno.readDirSync(sourceDir)) + .filter((entry) => entry.name.endsWith(".nix")) + .map((entry) => sourceDir.pathname + entry.name); + + await Deno.run({ + cmd: [ + "sudo", + "cp", + "--preserve=timestamps", + "--verbose", + ...files, + "/etc/nixos/", + ], + }).status(); +} + +if (import.meta.main) { + void main(); +}