stuff
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/result*
|
||||
/.generated
|
||||
.nixos-test-history
|
||||
|
10
flake.nix
10
flake.nix
@@ -455,6 +455,16 @@
|
||||
inherit pkgs lib inputs;
|
||||
inherit (plain) config;
|
||||
};
|
||||
generated = pkgs.linkFarm "generated" {
|
||||
nixpkgs = "${inputs.nixpkgs}";
|
||||
"liam-test/hints.py" = pkgs.writeText "hints.py" (import ./typesForTest.nix {
|
||||
name = "liam";
|
||||
inherit (pkgs-stable) lib;
|
||||
inherit self;
|
||||
inherit (inputs) nixpkgs;
|
||||
});
|
||||
"dns/python-env" = dns.passthru.python;
|
||||
};
|
||||
haproxy-auth-request = pkgs.callPackage ./packages/haproxy-auth-request.nix {
|
||||
inherit haproxy-lua-http;
|
||||
};
|
||||
|
3
mk-generated.sh
Executable file
3
mk-generated.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
repo="$(readlink -f "$(dirname "$0")")"
|
||||
nix build "$repo"#generated --out-link "$repo"/.generated "$@"
|
17
pyproject.toml
Normal file
17
pyproject.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
# this exists purely to wrangle the language servers into doing useful things for all the miscellaneous python scripts in this repo. This repo is not a python project
|
||||
|
||||
[tool.pyright]
|
||||
verboseOutput = true
|
||||
pythonPlatform = "Linux"
|
||||
pythonVersion = "3.12"
|
||||
|
||||
[[tool.pyright.executionEnvironments]]
|
||||
root = "tests/liam/testScript"
|
||||
extraPaths = [
|
||||
".generated/nixpkgs/nixos/lib",
|
||||
".generated/liam-test"
|
||||
]
|
||||
|
||||
[[tool.pyright.executionEnvironments]]
|
||||
root = "scripts/dns"
|
||||
extraPaths = [ ".generated/dns/python-env/lib/python3.12/site-packages" ]
|
@@ -11,10 +11,14 @@ let
|
||||
(builtins.toString ../../secrets/misc/cloudns.json)
|
||||
(builtins.toJSON config.vacu.dns)
|
||||
]) (builtins.readFile ./script.py);
|
||||
in
|
||||
pkgs.writers.writePython3Bin "dns-update" {
|
||||
libraries = with pkgs.python3Packages; [
|
||||
httpx
|
||||
dnspython
|
||||
];
|
||||
} pythonScript
|
||||
python = pkgs.python312.withPackages (_: libraries);
|
||||
in
|
||||
(pkgs.writers.writePython3Bin "dns-update" {
|
||||
inherit libraries;
|
||||
} pythonScript).overrideAttrs (old: {
|
||||
passthru = (old.passthru or {}) // { inherit libraries python; };
|
||||
})
|
||||
|
@@ -10,6 +10,7 @@ import argparse
|
||||
import httpx
|
||||
import dns.zone
|
||||
import dns.rdtypes
|
||||
from dns.name import Name
|
||||
|
||||
SOPS_BIN = "@sops@"
|
||||
DNS_SECRETS_FILE = "@dns_secrets_file@"
|
||||
@@ -47,20 +48,14 @@ def textify(z: dns.zone.Zone) -> str:
|
||||
|
||||
|
||||
def set_soa_serial(zone: dns.zone.Zone, serial: int):
|
||||
soa = zone.find_rdataset(zone.origin, "SOA")
|
||||
old_soa = soa[0]
|
||||
|
||||
new_soa = dns.rdtypes.ANY.SOA.SOA(
|
||||
old_soa.rdclass,
|
||||
old_soa.rdtype,
|
||||
old_soa.mname,
|
||||
old_soa.rname,
|
||||
serial,
|
||||
old_soa.refresh,
|
||||
old_soa.retry,
|
||||
old_soa.expire,
|
||||
old_soa.minimum,
|
||||
)
|
||||
origin = zone.origin
|
||||
if not isinstance(origin, Name):
|
||||
raise Exception(f"Bad zone origin {origin!r}")
|
||||
soa = zone.find_rdataset(origin, "SOA")
|
||||
thing = soa.processing_order()
|
||||
assert len(thing) == 1
|
||||
old_soa = thing[0]
|
||||
new_soa = old_soa.replace(serial=serial)
|
||||
|
||||
soa.clear()
|
||||
soa.add(new_soa)
|
||||
|
@@ -209,7 +209,7 @@ in
|
||||
|
||||
testScript =
|
||||
let
|
||||
rawFile = builtins.readFile ./testScript.py;
|
||||
rawFile = builtins.readFile ./testScript/main.py;
|
||||
data = {
|
||||
checkSieve = lib.getExe nodes.liam.vacu.checkSieve;
|
||||
acmeTest = pkgs.writeText "acme-test" "test";
|
||||
|
@@ -1,3 +1,8 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from hints import *
|
||||
|
||||
import json
|
||||
DATA_JSON = """
|
||||
@data@
|
39
typesForTest.nix
Normal file
39
typesForTest.nix
Normal file
@@ -0,0 +1,39 @@
|
||||
# A reimplementation of stuff in nixpkgs/nixos/lib/testing/driver.nix
|
||||
{
|
||||
name,
|
||||
lib,
|
||||
self,
|
||||
nixpkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
config = self.checks.x86_64-linux.${name}.config;
|
||||
|
||||
vlans = map (m: (
|
||||
m.virtualisation.vlans ++
|
||||
(lib.mapAttrsToList (_: v: v.vlan) m.virtualisation.interfaces))) (lib.attrValues config.nodes);
|
||||
|
||||
nodeHostNames =
|
||||
let
|
||||
nodesList = map (c: c.system.name) (lib.attrValues config.nodes);
|
||||
in
|
||||
nodesList ++ lib.optional (lib.length nodesList == 1 && !lib.elem "machine" nodesList) "machine";
|
||||
|
||||
pythonizeName = name:
|
||||
let
|
||||
head = lib.substring 0 1 name;
|
||||
tail = lib.substring 1 (-1) name;
|
||||
in
|
||||
(if builtins.match "[A-z_]" head == null then "_" else head) +
|
||||
lib.stringAsChars (c: if builtins.match "[A-z0-9_]" c == null then "_" else c) tail;
|
||||
|
||||
uniqueVlans = lib.unique (builtins.concatLists vlans);
|
||||
vlanNames = map (i: "vlan${toString i}: VLan;") uniqueVlans;
|
||||
pythonizedNames = map pythonizeName nodeHostNames;
|
||||
machineNames = map (name: "${name}: Machine;") pythonizedNames;
|
||||
in
|
||||
''
|
||||
${builtins.readFile "${nixpkgs}/nixos/lib/test-script-prepend.py"}
|
||||
${lib.concatLines machineNames}
|
||||
${lib.concatLines vlanNames}
|
||||
''
|
Reference in New Issue
Block a user