feat: Implemented madd client module
This commit is contained in:
parent
3eae747a0d
commit
d2f2065042
@ -40,7 +40,7 @@
|
||||
overlays.madd = final: prev: mkPackages final;
|
||||
overlays.default = overlays.madd;
|
||||
|
||||
nixosModules.madd = import ./nixos.nix;
|
||||
nixosModules.madd = import ./nixos.nix { overlay = overlays.madd; };
|
||||
nixosModules.default = nixosModules.madd;
|
||||
};
|
||||
}
|
||||
|
72
nixos.nix
72
nixos.nix
@ -1,12 +1,78 @@
|
||||
{ lib, config, ... }:
|
||||
{ overlay }:
|
||||
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
|
||||
with lib;
|
||||
{
|
||||
option.madd-client = {
|
||||
options.services.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.madd-server = {
|
||||
options.services.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 {
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user