diff --git a/examples/initrd/default.nix b/examples/initrd/default.nix index 6ad85185..7e9ccc43 100644 --- a/examples/initrd/default.nix +++ b/examples/initrd/default.nix @@ -25,6 +25,8 @@ nglib.makeSystem { }; users.users.root.hashedPassword = "$5$Ws9piKbYzt9S6p1R$X4L6xn5UNQnufJUc/K5sKRE.0GuMR.8vp2BwIiglVYB"; # toor + networking.hostName = "initrd"; + services.getty."ttyS0" = { port = "ttyS0"; baudrate = "115200,38400,9600"; diff --git a/modules/list.nix b/modules/list.nix index 395df3a4..9f78e376 100644 --- a/modules/list.nix +++ b/modules/list.nix @@ -18,6 +18,7 @@ ./misc/iana.nix + ./networking.nix ./environment.nix ./users.nix ./ids.nix diff --git a/modules/networking.nix b/modules/networking.nix new file mode 100644 index 00000000..740835da --- /dev/null +++ b/modules/networking.nix @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2023 Richard Brežák and NixNG contributors +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +{ nglib, lib, config, ... }: +{ + options.networking = { + hostName = lib.mkOption { + default = null; + type = lib.types.nullOr (lib.types.strMatching + "^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$"); + description = '' + The hostname of the system. Notice that in many container engines + the hostname cannot be altered. + ''; + }; + }; + + config.system.activation.hostname = nglib.dag.dagEntryAnywhere (lib.optionalString (config.networking.hostName != null) '' + echo "${config.networking.hostName}" > /proc/sys/kernel/hostname + ''); +} diff --git a/modules/system/oci-image.nix b/modules/system/oci-image.nix index 2bdd5375..deeb96ad 100644 --- a/modules/system/oci-image.nix +++ b/modules/system/oci-image.nix @@ -37,8 +37,8 @@ with lib; config = { system.build.ociImage = let - config = { - name = cfg.name; + cfg = { + inherit (config.system) name; tag = "latest"; maxLayers = 125; @@ -46,14 +46,14 @@ with lib; StopSignal = "SIGCONT"; Entrypoint = [ - "${configFinal.system.build.toplevel}/init" + "${config.system.build.toplevel}/init" ]; }; }; in with pkgs; { - build = dockerTools.buildLayeredImage config; - stream = dockerTools.streamLayeredImage config; + build = dockerTools.buildLayeredImage cfg; + stream = dockerTools.streamLayeredImage cfg; }; }; }