feat(vault01/legal_scripting): migration of old model to the new one

This commit is contained in:
catvayor 2025-03-11 14:21:57 +01:00
parent b845a08bfb
commit b0dc76a60a
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
3 changed files with 23 additions and 11 deletions

View file

@ -14,6 +14,7 @@
let
inherit (lib)
catAttrs
concatStringsSep
getExe
mapAttrs'
nameValuePair
@ -465,5 +466,20 @@ in
};
};
environment.systemPackages = [
(pkgs.writeShellApplication {
name = "netuserctl";
runtimeInputs = [ pkgs.systemd ];
text = concatStringsSep "\n" (
map ({ interfaceName, ... }: ''networkctl "$1" ${interfaceName}'') userVlans
);
})
(pkgs.callPackage ./migrate-vlan-logging.nix {
postgresql = config.services.postgresql.package;
vlans-info = userVlans;
inherit (sql_files) kea_log-init;
})
];
boot.kernel.sysctl."net.ipv4.ip_forward" = true;
}

View file

@ -8,16 +8,13 @@
writeText,
vlans-info,
postgresql,
kea_log-init,
}:
let
inherit (lib) concatMapStringsSep;
sql-script = writeText "vlan-filling.sql" ''
DROP TABLE IF EXISTS vlan_prefixes;
CREATE TABLE vlan_prefixes (
vlan_id smallint PRIMARY KEY UNIQUE NOT NULL,
prefix inet NOT NULL
);
INSERT INTO vlan_prefixes VALUES
INSERT INTO kea_log (ip_addr, vlan_id, lease_start_sec, lease_end_sec) VALUES
${concatMapStringsSep ",\n " (
{
vlan,
@ -25,7 +22,7 @@ let
prefixLen,
...
}:
"(${toString vlan}, inet '${netIP}/${toString prefixLen}')"
"(inet '${netIP}/${toString prefixLen}', ${toString vlan}, 0, MIGRATION_TIMESTAMP)"
) vlans-info}
;
'';
@ -34,6 +31,9 @@ writeShellApplication {
name = "fill-vlan_prefixes";
runtimeInputs = [ postgresql ];
text = ''
psql -d ulogd -U ulogd -f ${sql-script}
TIMESTAMP="$(date +%s)"
psql -d ulogd -U ulogd -f ${kea_log-init}
sed "s/MIGRATION_TIMESTAMP/$TIMESTAMP/" ${sql-script} \
| psql -d ulogd -U ulogd
'';
}

View file

@ -58,10 +58,6 @@
'';
};
environment.defaultPackages = [
(pkgs.callPackage ./fill-vlan_prefixes.nix {
inherit (config.networking) vlans-info;
postgresql = config.services.postgresql.package;
})
(pkgs.callPackage ./nat-request-daddr.nix {
postgresql = config.services.postgresql.package;
})