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: