fix: hostname at early boot
All checks were successful
build liminix / build_zyxel-nwa50ax_mips (pull_request) Successful in 20s
build liminix / build_vm_qemu_mips (pull_request) Successful in 20s
build liminix / test_shell_customization (pull_request) Successful in 22s
build liminix / test_hostapd (pull_request) Successful in 22s

This commit is contained in:
catvayor 2024-09-27 16:18:13 +02:00
parent 89d2d34ad7
commit 7eff028b02
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
3 changed files with 18 additions and 7 deletions

View file

@ -1,7 +1,6 @@
{ lib, pkgs, config, ...}: { lib, pkgs, config, ...}:
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
inherit (pkgs.liminix.services) oneshot;
in { in {
options = { options = {
hostname = mkOption { hostname = mkOption {
@ -12,12 +11,21 @@ in {
default = "liminix"; default = "liminix";
type = types.nonEmptyStr; type = types.nonEmptyStr;
}; };
}; hostname-script = mkOption {
config = { description = ''
services.hostname = oneshot { Script that outputs the system hostname on stdin.
name = "hostname-${builtins.substring 0 12 (builtins.hashString "sha256" config.hostname)}"; '';
up = "echo ${config.hostname} > /proc/sys/kernel/hostname"; default = pkgs.writeScript "hostname-gen" ''
down = "true"; #!/bin/sh
echo ${config.hostname}
'';
defaultText = ''
pkgs.writeScript "hostname-gen" '''
#!/bin/sh
echo ''${config.hostname}
'''
'';
type = types.package;
}; };
}; };
} }

View file

@ -30,6 +30,8 @@ let
installPhase = '' installPhase = ''
mkdir $out mkdir $out
cp -r $src $out/scripts cp -r $src $out/scripts
substituteInPlace $out/scripts/rc.init \
--replace-fail 'config.hostname' "${config.hostname-script}"
chmod -R +w $out chmod -R +w $out
''; '';
}; };

View file

@ -36,6 +36,7 @@ fi
### (replace /run/service with your scandir) ### (replace /run/service with your scandir)
s6-rc-init -d -c /etc/s6-rc/compiled /run/service s6-rc-init -d -c /etc/s6-rc/compiled /run/service
config.hostname > /proc/sys/kernel/hostname
### 2. Starting the wanted set of services ### 2. Starting the wanted set of services
### This is also called every time you change runlevels with telinit. ### This is also called every time you change runlevels with telinit.