From eec7a6e985424200678afe090922c89457f5e4b8 Mon Sep 17 00:00:00 2001 From: catvayor Date: Fri, 27 Sep 2024 10:17:34 +0200 Subject: [PATCH 1/3] fix PS1 --- modules/base.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/base.nix b/modules/base.nix index 0d507a7..5107e1e 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -4,7 +4,7 @@ { lib, pkgs, config, ...}: let - inherit (lib) mkEnableOption mkOption types isDerivation hasAttr concatStringsSep; + inherit (lib) mkEnableOption mkOption types isDerivation hasAttr concatStringsSep mapAttrsToList; inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.liminix.networking) address interface; inherit (pkgs.liminix.services) bundle; @@ -205,7 +205,7 @@ in { (pkgs.writeScript ".profile" '' PATH=${lib.makeBinPath config.defaultProfile.packages}:/bin export PATH - ${concatStringsSep "\n" (map exportVar config.defaultProfile.environmentVariables)} + ${concatStringsSep "\n" (mapAttrsToList exportVar config.defaultProfile.environmentVariables)} ''); in dir { inherit profile; From 89d2d34ad77646ec7f405863907067b19cc41168 Mon Sep 17 00:00:00 2001 From: catvayor Date: Fri, 27 Sep 2024 10:35:53 +0200 Subject: [PATCH 2/3] feat(ci): prompt checking --- .forgejo/workflows/build.yaml | 10 ++++++++++ tests/ci.nix | 1 + tests/custom-shell/check-prompt.expect | 7 +++++++ tests/custom-shell/configuration.nix | 13 +++++++++++++ tests/custom-shell/test.nix | 21 +++++++++++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 tests/custom-shell/check-prompt.expect create mode 100644 tests/custom-shell/configuration.nix create mode 100644 tests/custom-shell/test.nix diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 3a29607..71964a9 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -38,3 +38,13 @@ jobs: run: | # Enter the shell nix-build ci.nix -A wlan + + test_shell_customization: + runs-on: nix + steps: + - uses: actions/checkout@v3 + + - name: Build VM QEMU MIPS + run: | + # Enter the shell + nix-build ci.nix -A custom-shell diff --git a/tests/ci.nix b/tests/ci.nix index 4fbd953..1334885 100644 --- a/tests/ci.nix +++ b/tests/ci.nix @@ -10,4 +10,5 @@ tftpboot = import ./tftpboot/test.nix; updown = import ./updown/test.nix; inout = import ./inout/test.nix; + custom-shell = import ./custom-shell/test.nix; } diff --git a/tests/custom-shell/check-prompt.expect b/tests/custom-shell/check-prompt.expect new file mode 100644 index 0000000..4cc7656 --- /dev/null +++ b/tests/custom-shell/check-prompt.expect @@ -0,0 +1,7 @@ +set timeout 60 + +spawn socat unix-connect:vm/console - +expect { + "root@liminix blah blah > " { exit 0 } + timeout { exit 1 } +} diff --git a/tests/custom-shell/configuration.nix b/tests/custom-shell/configuration.nix new file mode 100644 index 0000000..b908137 --- /dev/null +++ b/tests/custom-shell/configuration.nix @@ -0,0 +1,13 @@ +{ config, pkgs, lib, ... } : +let + inherit (pkgs.liminix.networking) interface address hostapd route dnsmasq; + inherit (pkgs.liminix.services) oneshot longrun bundle target; +in rec { + imports = [ + ../../modules/network + ]; + + defaultProfile.prompt = "$(whoami)@$(hostname) blah blah > "; + + defaultProfile.packages = with pkgs; [ ]; +} diff --git a/tests/custom-shell/test.nix b/tests/custom-shell/test.nix new file mode 100644 index 0000000..e5273e1 --- /dev/null +++ b/tests/custom-shell/test.nix @@ -0,0 +1,21 @@ +{ + liminix +, nixpkgs +}: +let img = (import liminix { + inherit nixpkgs; + device = import "${liminix}/devices/qemu/"; + liminix-config = ./configuration.nix; + }).outputs.default; + pkgs = import nixpkgs { overlays = [(import ../../overlay.nix)]; }; +in pkgs.runCommand "check" { + nativeBuildInputs = with pkgs; [ + expect socat + ] ; +} '' +. ${../test-helpers.sh} + +mkdir vm +${img}/run.sh --background ./vm +expect ${./check-prompt.expect} |tee output && mv output $out +'' From 7eff028b022ec6e5ae210305196b86b999a03452 Mon Sep 17 00:00:00 2001 From: catvayor Date: Fri, 27 Sep 2024 16:18:13 +0200 Subject: [PATCH 3/3] fix: hostname at early boot --- modules/hostname.nix | 22 +++++++++++++++------- modules/s6/default.nix | 2 ++ modules/s6/scripts/rc.init | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) 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.