summaryrefslogtreecommitdiff
path: root/nixos/helpers.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/helpers.nix')
-rw-r--r--nixos/helpers.nix30
1 files changed, 17 insertions, 13 deletions
diff --git a/nixos/helpers.nix b/nixos/helpers.nix
index c6d1ff8..f8f1384 100644
--- a/nixos/helpers.nix
+++ b/nixos/helpers.nix
@@ -1,8 +1,5 @@
-{ config, ... }:
+{ config, lib, pkgs, ... }:
-let
- nixpkgs = import <nixpkgs> {};
-in
{
mkNginxConfig = name: ''
access_log /var/log/nginx/${name}.access.log json;
@@ -63,8 +60,19 @@ in
'}';
'';
+ writeAlloyConfig = cfg:
+ let
+ alloy-nix-config = "${pkgs.callPackage <top/shared/alloy-nix-config> {}}/bin/alloy-nix-config";
+ in
+ pkgs.runCommand "generated-config" {} ''
+ ${alloy-nix-config} ${pkgs.writeText "input.json" (builtins.toJSON cfg)} $out
+ # FUTURE: run alloy validate
+ '';
+
+ alloyConfigRef = s: { "$ref" = s; };
+
joinWgNamespace = ns: cfg:
- nixpkgs.lib.attrsets.recursiveUpdate cfg {
+ lib.attrsets.recursiveUpdate cfg {
bindsTo = ["netns@${ns}.service"];
after = ["wireguard-wg-${ns}.service"];
unitConfig.JoinsNamespaceOf = "netns@${ns}.service";
@@ -81,13 +89,9 @@ in
TimeoutStopSec = 300;
};
wantedBy = ["multi-user.target"];
- script =
- let
- pkgs = nixpkgs.pkgs;
- in
- ''
- ${pkgs.iproute2}/bin/ip netns exec ${ns} ${pkgs.iproute2}/bin/ip link set dev lo up
- ${pkgs.socat}/bin/socat tcp-listen:${toString port},fork,reuseaddr exec:'${pkgs.iproute2}/bin/ip netns exec ${ns} ${pkgs.socat}/bin/socat STDIO "tcp-connect:localhost:${toString port}"',nofork
- '';
+ script = ''
+ ${pkgs.iproute2}/bin/ip netns exec ${ns} ${pkgs.iproute2}/bin/ip link set dev lo up
+ ${pkgs.socat}/bin/socat tcp-listen:${toString port},fork,reuseaddr exec:'${pkgs.iproute2}/bin/ip netns exec ${ns} ${pkgs.socat}/bin/socat STDIO "tcp-connect:localhost:${toString port}"',nofork
+ '';
};
}