scripts: fix create-host flake.nix insertion point
Fix bug where new hosts were added outside of nixosConfigurations block instead of inside it. Issues fixed: 1. Pattern was looking for "packages =" but actual text is "packages = forAllSystems" 2. Replacement was putting new entry AFTER closing brace instead of BEFORE 3. testvm01 was at top-level flake output instead of in nixosConfigurations Changes: - Update pattern to match "packages = forAllSystems" - Put new entry BEFORE the closing brace of nixosConfigurations - Move testvm01 to correct location inside nixosConfigurations block Result: nix flake show now correctly shows testvm01 as NixOS configuration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -334,7 +334,6 @@
|
|||||||
sops-nix.nixosModules.sops
|
sops-nix.nixosModules.sops
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
|
||||||
testvm01 = nixpkgs.lib.nixosSystem {
|
testvm01 = nixpkgs.lib.nixosSystem {
|
||||||
inherit system;
|
inherit system;
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
@@ -351,6 +350,7 @@
|
|||||||
sops-nix.nixosModules.sops
|
sops-nix.nixosModules.sops
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
};
|
||||||
packages = forAllSystems (
|
packages = forAllSystems (
|
||||||
{ pkgs }:
|
{ pkgs }:
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,17 +50,17 @@ def update_flake_nix(config: HostConfig, repo_root: Path, force: bool = False) -
|
|||||||
if count == 0:
|
if count == 0:
|
||||||
raise ValueError(f"Could not find existing entry for {config.hostname} in flake.nix")
|
raise ValueError(f"Could not find existing entry for {config.hostname} in flake.nix")
|
||||||
else:
|
else:
|
||||||
# Insert new entry before closing brace
|
# Insert new entry before closing brace of nixosConfigurations
|
||||||
# Pattern: " };\n packages ="
|
# Pattern: " };\n packages = forAllSystems"
|
||||||
pattern = r"( \};)\n( packages =)"
|
pattern = r"( \};)\n( packages = forAllSystems)"
|
||||||
replacement = rf"\g<1>\n{new_entry}\g<2>"
|
replacement = rf"{new_entry}\g<1>\n\g<2>"
|
||||||
|
|
||||||
new_content, count = re.subn(pattern, replacement, content)
|
new_content, count = re.subn(pattern, replacement, content)
|
||||||
|
|
||||||
if count == 0:
|
if count == 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Could not find insertion point in flake.nix. "
|
"Could not find insertion point in flake.nix. "
|
||||||
"Looking for pattern: ' };\\n packages ='"
|
"Looking for pattern: ' };\\n packages = forAllSystems'"
|
||||||
)
|
)
|
||||||
|
|
||||||
flake_path.write_text(new_content)
|
flake_path.write_text(new_content)
|
||||||
|
|||||||
@@ -7,16 +7,15 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../template/hardware-configuration.nix
|
../template2/hardware-configuration.nix
|
||||||
|
|
||||||
../../system
|
../../system
|
||||||
../../common/vm
|
../../common/vm
|
||||||
];
|
];
|
||||||
|
|
||||||
nixpkgs.config.allowUnfree = true;
|
nixpkgs.config.allowUnfree = true;
|
||||||
# Use the systemd-boot EFI boot loader.
|
|
||||||
boot.loader.grub.enable = true;
|
boot.loader.grub.enable = true;
|
||||||
boot.loader.grub.device = "/dev/sda";
|
boot.loader.grub.device = "/dev/vda";
|
||||||
|
|
||||||
networking.hostName = "{{ hostname }}";
|
networking.hostName = "{{ hostname }}";
|
||||||
networking.domain = "{{ domain }}";
|
networking.domain = "{{ domain }}";
|
||||||
|
|||||||
Reference in New Issue
Block a user