liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit bb2c36a0b4a92cfbb3f8c3c4b97d89f60c626531
parent c5e05675112a15fed5f7d108c6d9c4caad2c2cfa
Author: Daniel Barlow <dan@telent.net>
Date:   Mon,  3 Nov 2025 23:51:52 +0000

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

Diffstat:
Amodules/dhcp4c/client.nix | 47+++++++++++++++++++++++++++++++++++++++++++++++
Amodules/dhcp4c/default.nix | 38++++++++++++++++++++++++++++++++++++++
Mmodules/network/default.nix | 13+++++++++----
3 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/modules/dhcp4c/client.nix b/modules/dhcp4c/client.nix @@ -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 ]; +} diff --git a/modules/dhcp4c/default.nix b/modules/dhcp4c/default.nix @@ -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" ]; +} diff --git a/modules/network/default.nix b/modules/network/default.nix @@ -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; + }; }; - }; }; };