diff --git a/modules/hostname.nix b/modules/hostname.nix index 5f18b04..e05b724 100644 --- a/modules/hostname.nix +++ b/modules/hostname.nix @@ -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; }; }; } diff --git a/modules/s6/default.nix b/modules/s6/default.nix index cd05de7..e1ce9c8 100644 --- a/modules/s6/default.nix +++ b/modules/s6/default.nix @@ -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 ''; }; diff --git a/modules/s6/scripts/rc.init b/modules/s6/scripts/rc.init index c098ffb..3888e50 100755 --- a/modules/s6/scripts/rc.init +++ b/modules/s6/scripts/rc.init @@ -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.