From 61861ff170854d817f221762c01a38bee17fedbd Mon Sep 17 00:00:00 2001 From: yukkop Date: Fri, 1 May 2026 22:56:03 +0000 Subject: [PATCH] fix: linux-devshell from root --- package/linux-devshell/linux-devshell.sh | 10 ++++++- test/package/linux-devshell/default.nix | 36 +++++++++++++++--------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/package/linux-devshell/linux-devshell.sh b/package/linux-devshell/linux-devshell.sh index 224b133..95e43d5 100644 --- a/package/linux-devshell/linux-devshell.sh +++ b/package/linux-devshell/linux-devshell.sh @@ -39,7 +39,15 @@ install_nix() { exit 1 fi - sh "$NIX_INSTALL" --no-daemon || true + if [ "$(id -u)" -eq 0 ] && ! [ -d /nix ]; then + log_info "Running as root, creating /nix manually..." + mkdir -p /nix + fi + + if ! sh "$NIX_INSTALL" --no-daemon; then + log_error "Nix installer failed." + exit 1 + fi NIX_CONF_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}/nix" mkdir -p "$NIX_CONF_DIR" diff --git a/test/package/linux-devshell/default.nix b/test/package/linux-devshell/default.nix index 79553d0..df27be8 100644 --- a/test/package/linux-devshell/default.nix +++ b/test/package/linux-devshell/default.nix @@ -52,7 +52,7 @@ mkdir -p "$out" ''; - archTest = pkgs.runCommand "linux-devshell-test-arch-integration" + mkArchTest = name: root: pkgs.runCommand "linux-devshell-test-arch-${name}" { nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused pkgs.zstd pkgs.git ]; buildInputs = [ pkgs.dash pkgs.proot ]; @@ -62,7 +62,7 @@ ${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log} export HECTIC_LOG=trace - log notice "test case: ''${WHITE}arch integration" + log notice "test case: ''${WHITE}arch ${name}" ARCH_DIR="$(mktemp -d)" trap 'rm -rf "$ARCH_DIR"' EXIT @@ -99,42 +99,52 @@ git -C "$ARCH_DIR/root/test-repo" add . git -C "$ARCH_DIR/root/test-repo" commit -m "init" - log info "Running linux-devshell in Arch via proot..." - proot -b /dev -r "$ARCH_DIR" -w /root/test-repo /bin/sh -c ' + log info "Running linux-devshell as ${name} in Arch via proot..." + ${lib.optionalString root "proot -b /dev -0 -r \"$ARCH_DIR\" -w /root/test-repo /bin/sh -c '"} + ${lib.optionalString (!root) "proot -b /dev -r \"$ARCH_DIR\" -w /root/test-repo /bin/sh -c '"} export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" export TMPDIR=/tmp mkdir -p /nix /build /tmp /root/test-repo/script/linux-devshell 2>&1 ' | tee /tmp/proot-output || true - log info "Checking script behavior in Arch environment..." + log info "Checking ${name} behavior..." if ! grep -q "Nix not found" /tmp/proot-output; then - log error "Script did not detect missing Nix" + log error "Script did not detect missing Nix as ${name}" cat /tmp/proot-output exit 1 fi - log success "Script correctly detects missing Nix" + log success "Script detects missing Nix as ${name}" if ! grep -q "Installing via nixos.org" /tmp/proot-output; then - log error "Script did not attempt Nix installation" + log error "Script did not attempt Nix installation as ${name}" cat /tmp/proot-output exit 1 fi - log success "Script attempts Nix installation" + log success "Script attempts Nix installation as ${name}" + + if grep -q "installing Nix as root is not supported" /tmp/proot-output; then + log success "Script handles root install warning" + fi + + if grep -q "Patched nix.conf" /tmp/proot-output; then + log success "Script patches nix.conf for ${name} install" + fi if ! grep -q "Failed to download Nix installer" /tmp/proot-output; then - log error "Script did not handle download failure (no network in sandbox)" + log error "Script did not handle download failure as ${name}" cat /tmp/proot-output exit 1 fi - log success "Script handles network failure gracefully" + log success "Script handles network failure as ${name}" - log success "Script runs correctly in Arch Linux environment" + log success "Script runs correctly in Arch Linux as ${name}" mkdir -p "$out" ''; in (lib.mapAttrs (name: drv: mkTest name drv) testDrvs) // { - arch-integration = archTest; + arch-integration-root = mkArchTest "root" true; + arch-integration-user = mkArchTest "user" false; }