1
Fork 0

Add the copy-nixos-config script.

This commit is contained in:
Bauke 2023-02-07 11:21:46 +01:00
parent bbfd3a6682
commit 44cc77d0ab
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 41 additions and 0 deletions

7
.bauke/bin/copy-nixos-config Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env zsh
deno run \
--allow-read \
--allow-run="hostname,sudo" \
"$BAUKE_DIR/scripts/copy-nixos-config.ts" \
"$@"

View File

@ -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<void> {
const { options } = await new Command()
.name("copy-nixos-config")
.description(
'Copy NixOS configuration from "$BAUKE_DIR/nix/<hostname>/" 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();
}