add service fir dhcp v4 client
This commit is contained in:
parent
31f0213b6f
commit
00c8ea66ea
3 changed files with 65 additions and 7 deletions
|
@ -20,6 +20,14 @@ in {
|
||||||
description = "network interface address";
|
description = "network interface address";
|
||||||
type = liminix.lib.types.serviceDefn;
|
type = liminix.lib.types.serviceDefn;
|
||||||
};
|
};
|
||||||
|
dhcp = {
|
||||||
|
client = mkOption {
|
||||||
|
# this needs to move to its own service as it has
|
||||||
|
# busybox config
|
||||||
|
description = "DHCP v4 client";
|
||||||
|
type = liminix.lib.types.serviceDefn;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
|
@ -49,6 +57,12 @@ in {
|
||||||
type = types.ints.between 0 128;
|
type = types.ints.between 0 128;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
dhcp.client = liminix.callService ./dhcpc.nix {
|
||||||
|
interface = mkOption {
|
||||||
|
type = liminix.lib.types.service;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
46
modules/network/dhcpc.nix
Normal file
46
modules/network/dhcpc.nix
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
liminix
|
||||||
|
, writeAshScript
|
||||||
|
, serviceFns
|
||||||
|
, lib
|
||||||
|
} :
|
||||||
|
{ interface }:
|
||||||
|
let
|
||||||
|
inherit (liminix.services) longrun;
|
||||||
|
name = "${interface.name}.dhcpc";
|
||||||
|
script = writeAshScript "dhcp-notify" { } ''
|
||||||
|
. ${serviceFns}
|
||||||
|
exec 2>&1
|
||||||
|
action=$1
|
||||||
|
|
||||||
|
set_address() {
|
||||||
|
ip address replace $ip/$mask dev $interface
|
||||||
|
(in_outputs ${name}
|
||||||
|
for i in lease mask ip router siaddr dns serverid subnet opt53 interface ; do
|
||||||
|
printenv $i > $i
|
||||||
|
done)
|
||||||
|
}
|
||||||
|
case $action in
|
||||||
|
deconfig)
|
||||||
|
ip address flush $interface
|
||||||
|
ip link set up dev $interface
|
||||||
|
;;
|
||||||
|
bound)
|
||||||
|
# this doesn't actually replace, it adds a new address.
|
||||||
|
set_address
|
||||||
|
echo >/proc/self/fd/10
|
||||||
|
;;
|
||||||
|
renew)
|
||||||
|
set_address
|
||||||
|
;;
|
||||||
|
nak)
|
||||||
|
echo "received NAK on $interface"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
'';
|
||||||
|
in longrun {
|
||||||
|
inherit name;
|
||||||
|
run = "/bin/udhcpc -f -i $(output ${interface} ifname) -x hostname:$(cat /proc/sys/kernel/hostname) -s ${script}";
|
||||||
|
notification-fd = 10;
|
||||||
|
dependencies = [ interface ];
|
||||||
|
}
|
|
@ -1,23 +1,21 @@
|
||||||
{ config, pkgs, ... } :
|
{ config, pkgs, ... } :
|
||||||
let
|
let
|
||||||
inherit (pkgs.liminix.networking) interface address udhcpc odhcpc route;
|
inherit (pkgs.liminix.networking) interface address route;
|
||||||
inherit (pkgs.liminix.services) oneshot longrun bundle target;
|
inherit (pkgs.liminix.services) oneshot longrun bundle target;
|
||||||
inherit (pkgs) writeText;
|
inherit (pkgs) writeText;
|
||||||
|
svc = config.system.service;
|
||||||
in rec {
|
in rec {
|
||||||
imports = [
|
imports = [
|
||||||
./modules/tftpboot.nix
|
./modules/tftpboot.nix
|
||||||
./modules/wlan.nix
|
./modules/wlan.nix
|
||||||
|
./modules/network
|
||||||
./modules/ntp
|
./modules/ntp
|
||||||
];
|
];
|
||||||
services.loopback = config.hardware.networkInterfaces.lo;
|
services.loopback = config.hardware.networkInterfaces.lo;
|
||||||
|
|
||||||
services.dhcpv4 =
|
services.dhcpv4 =
|
||||||
let iface = interface { type = "hardware"; device = "eth1"; };
|
let iface = svc.network.link.build { ifname = "eth1"; };
|
||||||
in udhcpc iface {};
|
in svc.network.dhcp.client.build { interface = iface; };
|
||||||
|
|
||||||
services.dhcpv6 =
|
|
||||||
let iface = interface { type = "hardware"; device = "eth1"; };
|
|
||||||
in odhcpc iface { uid = "e7"; };
|
|
||||||
|
|
||||||
services.defaultroute4 = route {
|
services.defaultroute4 = route {
|
||||||
name = "defautlrote";
|
name = "defautlrote";
|
||||||
|
|
Loading…
Reference in a new issue