1
Fork 0

Add a diff option to copy-nixos-config.

This commit is contained in:
Bauke 2023-02-12 12:55:30 +01:00
parent e7dec0492b
commit a62d8b4164
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 13 additions and 1 deletions

View File

@ -2,6 +2,6 @@
deno run \ deno run \
--allow-read \ --allow-read \
--allow-run="hostname,sudo" \ --allow-run="delta,hostname,sudo" \
"$BAUKE_DIR/scripts/copy-nixos-config.ts" \ "$BAUKE_DIR/scripts/copy-nixos-config.ts" \
"$@" "$@"

View File

@ -10,6 +10,7 @@ async function main(): Promise<void> {
.option("--hostname", "The machine's configuration to copy.", { .option("--hostname", "The machine's configuration to copy.", {
default: (await runAndReturnStdout({ cmd: ["hostname"] })).trim(), default: (await runAndReturnStdout({ cmd: ["hostname"] })).trim(),
}) })
.option("--diff", 'Output diffs between local and "/etc/nixos/" files.')
.parse(Deno.args); .parse(Deno.args);
const sourceDir = new URL(`../nix/${options.hostname}/`, import.meta.url); const sourceDir = new URL(`../nix/${options.hostname}/`, import.meta.url);
@ -17,6 +18,17 @@ async function main(): Promise<void> {
.filter((entry) => entry.name.endsWith(".nix")) .filter((entry) => entry.name.endsWith(".nix"))
.map((entry) => sourceDir.pathname + entry.name); .map((entry) => sourceDir.pathname + entry.name);
if (options.diff) {
for (const file of files) {
const filename = file.slice(file.lastIndexOf("/") + 1);
await Deno.run({
cmd: ["delta", `/etc/nixos/${filename}`, file],
}).status();
}
return;
}
await Deno.run({ await Deno.run({
cmd: [ cmd: [
"sudo", "sudo",