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, ...}:
let
inherit (lib) mkOption types;
inherit (pkgs.liminix.services) oneshot;
in {
options = {
hostname = mkOption {
@ -12,12 +11,21 @@ in {
default = "liminix";
type = types.nonEmptyStr;
};
};
config = {
services.hostname = oneshot {
name = "hostname-${builtins.substring 0 12 (builtins.hashString "sha256" config.hostname)}";
up = "echo ${config.hostname} > /proc/sys/kernel/hostname";
down = "true";
hostname-script = mkOption {
description = ''
Script that outputs the system hostname on stdin.
'';
default = pkgs.writeScript "hostname-gen" ''
#!/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 = ''
mkdir $out
cp -r $src $out/scripts
substituteInPlace $out/scripts/rc.init \
--replace-fail 'config.hostname' "${config.hostname-script}"
chmod -R +w $out
'';
};

View file

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