From 91c014791929bd6047107beb5bfae1fafa83a7a7 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 8 Mar 2023 22:11:59 +0000 Subject: [PATCH] set hostname before dhcp client runs --- default.nix | 1 + extneder.nix | 9 +++++++-- modules/hostname.nix | 19 +++++++++++++++++++ pkgs/liminix-tools/networking/udhcpc.nix | 6 +++--- 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 modules/hostname.nix diff --git a/default.nix b/default.nix index 987a951..0f96a55 100644 --- a/default.nix +++ b/default.nix @@ -22,6 +22,7 @@ let { _module.args = { inherit pkgs; lib = pkgs.lib; }; } ./modules/hardware.nix ./modules/base.nix + ./modules/hostname.nix device.module liminix-config ./modules/s6 diff --git a/extneder.nix b/extneder.nix index 6f2139d..da49598 100644 --- a/extneder.nix +++ b/extneder.nix @@ -38,6 +38,8 @@ in rec { ./modules/flashable.nix ]; + hostname = "extneder"; + kernel = { config = { @@ -90,7 +92,10 @@ in rec { type = "bridge"; device = "int"; }; - services.dhcpc = (udhcpc services.int {}) // {device = "int";}; + + services.dhcpc = (udhcpc services.int { + dependencies = [ config.services.hostname ]; + }) // { device = "int"; }; services.bridge = let primary = services.int; @@ -154,7 +159,7 @@ in rec { name = "default"; contents = let links = config.hardware.networkInterfaces; - in with services; [ + in with config.services; [ links.lo links.eth links.wlan int bridge diff --git a/modules/hostname.nix b/modules/hostname.nix new file mode 100644 index 0000000..a2c17ea --- /dev/null +++ b/modules/hostname.nix @@ -0,0 +1,19 @@ +{ lib, pkgs, config, ...}: +let + inherit (lib) mkOption types; + inherit (pkgs.liminix.services) oneshot; +in { + options = { + hostname = mkOption { + default = "liminix"; + type = types.nonEmptyStr; + }; + }; + config = { + services.hostname = oneshot { + name = "hostname"; + up = "echo ${config.hostname} > /proc/sys/kernel/hostname"; + down = "true"; + }; + }; +} diff --git a/pkgs/liminix-tools/networking/udhcpc.nix b/pkgs/liminix-tools/networking/udhcpc.nix index 482260e..ee9ed47 100644 --- a/pkgs/liminix-tools/networking/udhcpc.nix +++ b/pkgs/liminix-tools/networking/udhcpc.nix @@ -7,7 +7,7 @@ let inherit (liminix.services) longrun; in -interface: { ... } @ args: +interface: { dependencies ? [] } @ args: let name = "${interface.device}.udhcp"; script = writeAshScript "udhcp-notify" { @@ -43,9 +43,9 @@ let ''; in longrun { inherit name; - run = "${busybox}/bin/udhcpc -f -i ${interface.device} -s ${script}"; + run = "${busybox}/bin/udhcpc -f -i ${interface.device} -x hostname:$(cat /proc/sys/kernel/hostname) -s ${script}"; notification-fd = 10; - dependencies = [ interface ]; + dependencies = [ interface ] ++ dependencies; } # lease=86400