2
0

prefer modules/dhcp4c over system.services.network.dhcp.client

This commit is contained in:
2025-11-03 23:51:52 +00:00
parent c5e0567511
commit bb2c36a0b4
3 changed files with 94 additions and 4 deletions
+47
View File
@@ -0,0 +1,47 @@
{
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 || true) > $i
done
touch state)
}
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 = "exec /bin/udhcpc -n -A 15 -f -i $(output ${interface} ifname) -x hostname:$(cat /proc/sys/kernel/hostname) -s ${script}";
dependencies = [ interface ];
}
+38
View File
@@ -0,0 +1,38 @@
## DHCP6 client module
## ===================
##
## This is for use if you have an IPv6-capable upstream that provides
## address information and/or prefix delegation using DHCP6. It
## provides a service to request address information in the form of a
## DHCP lease, and two dependent services that listen for updates
## to the DHCP address information and can be used to update
## addresses of network interfaces that you want to assign those
## prefixes to
{
lib,
pkgs,
config,
...
}:
let
inherit (lib) mkOption types;
inherit (pkgs) liminix;
in
{
options = {
system.service.dhcp4c = {
client = mkOption { type = liminix.lib.types.serviceDefn; };
};
};
config.system.service.dhcp4c = {
client = config.system.callService ./client.nix {
interface = mkOption {
type = liminix.lib.types.interface;
description = "interface to query for DHCP";
};
};
};
# this is already configured in modules/busybox.nix
config.programs.busybox.applets = [ "udhcpc" ];
}
+9 -4
View File
@@ -146,11 +146,16 @@ in
};
};
dhcp.client = config.system.callService ./dhcpc.nix {
interface = mkOption {
type = liminix.lib.types.service;
dhcp.client =
lib.warn ''
system.services.network.dhcp.client is deprecated and will
be removed in 2026. Use system.service.dhcp4c instead
''
config.system.callService ./dhcpc.nix {
interface = mkOption {
type = liminix.lib.types.service;
};
};
};
};
};