Add a diff option to copy-nixos-config.
This commit is contained in:
		
							parent
							
								
									e7dec0492b
								
							
						
					
					
						commit
						a62d8b4164
					
				| 
						 | 
				
			
			@ -2,6 +2,6 @@
 | 
			
		|||
 | 
			
		||||
deno run \
 | 
			
		||||
  --allow-read \
 | 
			
		||||
  --allow-run="hostname,sudo" \
 | 
			
		||||
  --allow-run="delta,hostname,sudo" \
 | 
			
		||||
  "$BAUKE_DIR/scripts/copy-nixos-config.ts" \
 | 
			
		||||
  "$@"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@ async function main(): Promise<void> {
 | 
			
		|||
    .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<void> {
 | 
			
		|||
    .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",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in New Issue