From a62d8b41643c5f292df8711f3fc5f86782cbea0e Mon Sep 17 00:00:00 2001 From: Bauke Date: Sun, 12 Feb 2023 12:55:30 +0100 Subject: [PATCH] Add a diff option to copy-nixos-config. --- .bauke/bin/copy-nixos-config | 2 +- .bauke/scripts/copy-nixos-config.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.bauke/bin/copy-nixos-config b/.bauke/bin/copy-nixos-config index ea25847..79588d6 100755 --- a/.bauke/bin/copy-nixos-config +++ b/.bauke/bin/copy-nixos-config @@ -2,6 +2,6 @@ deno run \ --allow-read \ - --allow-run="hostname,sudo" \ + --allow-run="delta,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 index ee903ed..6392172 100644 --- a/.bauke/scripts/copy-nixos-config.ts +++ b/.bauke/scripts/copy-nixos-config.ts @@ -10,6 +10,7 @@ async function main(): Promise { .option("--hostname", "The machine's configuration to copy.", { default: (await runAndReturnStdout({ cmd: ["hostname"] })).trim(), }) + .option("--diff", 'Output diffs between local and "/etc/nixos/" files.') .parse(Deno.args); const sourceDir = new URL(`../nix/${options.hostname}/`, import.meta.url); @@ -17,6 +18,17 @@ async function main(): Promise { .filter((entry) => entry.name.endsWith(".nix")) .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({ cmd: [ "sudo",