Compare commits

..

No commits in common. "d2f2065042bd165e3bb0ab3378ebec8fcb7e8960" and "cecccf25743ac736cffc0006db3f65d4192a82aa" have entirely different histories.

3 changed files with 4 additions and 85 deletions

View File

@ -40,7 +40,7 @@
overlays.madd = final: prev: mkPackages final;
overlays.default = overlays.madd;
nixosModules.madd = import ./nixos.nix { overlay = overlays.madd; };
nixosModules.madd = import ./nixos.nix;
nixosModules.default = nixosModules.madd;
};
}

View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
interface="${MADD_INTERFACE:-"eth0"}"
interface="wlp0s20f3"
client_script="${MADD_CLIENT_SCRIPT:-"./client.sh"}"
ip -4 monitor address label dev "$interface" | while read event; do
if [[ $event == \[ADDR\]* ]]; then
ipv4=$(ip -4 addr show dev "$interface" | grep -Po 'inet \K[\d.]+')
if [ -n "$ipv4" ]; then
export MADD_IP="$ipv4"
$client_script
fi
fi
done

View File

@ -1,78 +1,12 @@
{ overlay }:
{
lib,
pkgs,
config,
...
}:
{ lib, config, ... }:
with lib;
{
options.services.madd-client = {
option.madd-client = {
enable = mkEnableOption "MADD client";
endpoint = mkOption {
type = types.str;
description = "Endpoint for MADD client to connect to.";
};
interface = mkOption {
type = types.str;
default = "eth0";
description = "Network interface to use for MADD client.";
};
priv-key-file = mkOption {
type = types.str;
default = "/etc/ssh/ssh_host_ed25519_key";
description = "Path to the private SSH key file identifying this machine.";
};
pub-key-file = mkOption {
type = types.str;
default = "${config.services.madd-client.priv_key_file}.pub";
description = "Path to the public SSH key file identifying this machine.";
};
hostname = mkOption {
type = types.str;
default = config.networking.hostName;
description = "Hostname to use for MADD client.";
};
};
options.services.madd-server = {
options.madd-server = {
enable = mkEnableOption "MADD server";
};
config = {
nixpkgs.overlays = [ overlay ];
}
// (
let
cfg = config.services.madd-client;
in
optionalAttrs config.madd-client.enable {
systemd.services.madd-client = {
description = "MADD Client Service";
wantedBy = [ "multi-user.target" ];
before = [ "network-pre.target" ];
requires = [ "network-pre.target" ];
script = ''
${pkgs.iproute2}/bin/ip -4 monitor address label dev "${cfg.interface}" | while read -r event; do
if [[ $event == \[ADDR\]* ]]; then
ipv4=$(${pkgs.iproute2}/bin/ip -4 addr show dev "${cfg.interface}" | grep -Po 'inet \K[\d.]+')
if [ -n "$ipv4" ]; then
export MADD_ENDPOINT="${cfg.endpoint}"
export MADD_PRIV_KEY="${cfg.priv-key-file}"
export MADD_PUB_KEY="${cfg.pub-key-file}"
export MADD_HOSTNAME="${cfg.hostname}"
export MADD_IP="$ipv4"
${pkgs.madd-client}/bin/madd-client
fi
done
'';
};
}
)
// (optionalAttrs config.madd-server.enable {
});
}