set hostname before dhcp client runs

module-based-network
Daniel Barlow 2023-03-08 22:11:59 +00:00
parent 2318c54037
commit 91c0147919
4 changed files with 30 additions and 5 deletions

View File

@ -22,6 +22,7 @@ let
{ _module.args = { inherit pkgs; lib = pkgs.lib; }; } { _module.args = { inherit pkgs; lib = pkgs.lib; }; }
./modules/hardware.nix ./modules/hardware.nix
./modules/base.nix ./modules/base.nix
./modules/hostname.nix
device.module device.module
liminix-config liminix-config
./modules/s6 ./modules/s6

View File

@ -38,6 +38,8 @@ in rec {
./modules/flashable.nix ./modules/flashable.nix
]; ];
hostname = "extneder";
kernel = { kernel = {
config = { config = {
@ -90,7 +92,10 @@ in rec {
type = "bridge"; type = "bridge";
device = "int"; device = "int";
}; };
services.dhcpc = (udhcpc services.int {}) // {device = "int";};
services.dhcpc = (udhcpc services.int {
dependencies = [ config.services.hostname ];
}) // { device = "int"; };
services.bridge = let services.bridge = let
primary = services.int; primary = services.int;
@ -154,7 +159,7 @@ in rec {
name = "default"; name = "default";
contents = contents =
let links = config.hardware.networkInterfaces; let links = config.hardware.networkInterfaces;
in with services; [ in with config.services; [
links.lo links.eth links.wlan links.lo links.eth links.wlan
int int
bridge bridge

19
modules/hostname.nix Normal file
View File

@ -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";
};
};
}

View File

@ -7,7 +7,7 @@
let let
inherit (liminix.services) longrun; inherit (liminix.services) longrun;
in in
interface: { ... } @ args: interface: { dependencies ? [] } @ args:
let let
name = "${interface.device}.udhcp"; name = "${interface.device}.udhcp";
script = writeAshScript "udhcp-notify" { script = writeAshScript "udhcp-notify" {
@ -43,9 +43,9 @@ let
''; '';
in longrun { in longrun {
inherit name; 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; notification-fd = 10;
dependencies = [ interface ]; dependencies = [ interface ] ++ dependencies;
} }
# lease=86400 # lease=86400