From b0d35f9a99c53f0d7e7088045a9acbeaf68e3340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 7 Feb 2026 12:48:29 +0100 Subject: [PATCH] create-host: fix flake.nix indentation patterns The regex patterns expected 6 spaces of indentation but flake.nix uses 8 spaces for host entries. Also updated generated entry template to match current flake.nix style (using commonModules ++). Co-Authored-By: Claude Opus 4.5 --- scripts/create-host/manipulators.py | 33 ++++++++++++----------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/scripts/create-host/manipulators.py b/scripts/create-host/manipulators.py index b9c4f6e..b3eafaa 100644 --- a/scripts/create-host/manipulators.py +++ b/scripts/create-host/manipulators.py @@ -22,12 +22,12 @@ def remove_from_flake_nix(hostname: str, repo_root: Path) -> bool: content = flake_path.read_text() # Check if hostname exists - hostname_pattern = rf"^ {re.escape(hostname)} = nixpkgs\.lib\.nixosSystem" + hostname_pattern = rf"^ {re.escape(hostname)} = nixpkgs\.lib\.nixosSystem" if not re.search(hostname_pattern, content, re.MULTILINE): return False # Match the entire block from "hostname = " to "};" - replace_pattern = rf"^ {re.escape(hostname)} = nixpkgs\.lib\.nixosSystem \{{.*?^ \}};\n" + replace_pattern = rf"^ {re.escape(hostname)} = nixpkgs\.lib\.nixosSystem \{{.*?^ \}};\n" new_content, count = re.subn(replace_pattern, "", content, flags=re.MULTILINE | re.DOTALL) if count == 0: @@ -115,7 +115,7 @@ def check_entries_exist(hostname: str, repo_root: Path) -> Tuple[bool, bool, boo # Check flake.nix flake_path = repo_root / "flake.nix" flake_content = flake_path.read_text() - flake_pattern = rf"^ {re.escape(hostname)} = nixpkgs\.lib\.nixosSystem" + flake_pattern = rf"^ {re.escape(hostname)} = nixpkgs\.lib\.nixosSystem" flake_exists = bool(re.search(flake_pattern, flake_content, re.MULTILINE)) # Check terraform/vms.tf @@ -147,32 +147,25 @@ def update_flake_nix(config: HostConfig, repo_root: Path, force: bool = False) - content = flake_path.read_text() # Create new entry - new_entry = f""" {config.hostname} = nixpkgs.lib.nixosSystem {{ - inherit system; - specialArgs = {{ - inherit inputs self sops-nix; + new_entry = f""" {config.hostname} = nixpkgs.lib.nixosSystem {{ + inherit system; + specialArgs = {{ + inherit inputs self sops-nix; + }}; + modules = commonModules ++ [ + ./hosts/{config.hostname} + ]; }}; - modules = [ - ( - {{ config, pkgs, ... }}: - {{ - nixpkgs.overlays = commonOverlays; - }} - ) - ./hosts/{config.hostname} - sops-nix.nixosModules.sops - ]; - }}; """ # Check if hostname already exists - hostname_pattern = rf"^ {re.escape(config.hostname)} = nixpkgs\.lib\.nixosSystem" + hostname_pattern = rf"^ {re.escape(config.hostname)} = nixpkgs\.lib\.nixosSystem" existing_match = re.search(hostname_pattern, content, re.MULTILINE) if existing_match and force: # Replace existing entry # Match the entire block from "hostname = " to "};" - replace_pattern = rf"^ {re.escape(config.hostname)} = nixpkgs\.lib\.nixosSystem \{{.*?^ \}};\n" + replace_pattern = rf"^ {re.escape(config.hostname)} = nixpkgs\.lib\.nixosSystem \{{.*?^ \}};\n" new_content, count = re.subn(replace_pattern, new_entry, content, flags=re.MULTILINE | re.DOTALL) if count == 0: