fix: linux-devshell from root

This commit is contained in:
2026-05-01 22:56:03 +00:00
parent d64314d68b
commit 61861ff170
2 changed files with 32 additions and 14 deletions

View File

@@ -39,7 +39,15 @@ install_nix() {
exit 1 exit 1
fi 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" NIX_CONF_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}/nix"
mkdir -p "$NIX_CONF_DIR" mkdir -p "$NIX_CONF_DIR"

View File

@@ -52,7 +52,7 @@
mkdir -p "$out" 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 ]; nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused pkgs.zstd pkgs.git ];
buildInputs = [ pkgs.dash pkgs.proot ]; buildInputs = [ pkgs.dash pkgs.proot ];
@@ -62,7 +62,7 @@
${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log} ${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log}
export HECTIC_LOG=trace export HECTIC_LOG=trace
log notice "test case: ''${WHITE}arch integration" log notice "test case: ''${WHITE}arch ${name}"
ARCH_DIR="$(mktemp -d)" ARCH_DIR="$(mktemp -d)"
trap 'rm -rf "$ARCH_DIR"' EXIT 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" add .
git -C "$ARCH_DIR/root/test-repo" commit -m "init" git -C "$ARCH_DIR/root/test-repo" commit -m "init"
log info "Running linux-devshell in Arch via proot..." log info "Running linux-devshell as ${name} in Arch via proot..."
proot -b /dev -r "$ARCH_DIR" -w /root/test-repo /bin/sh -c ' ${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 PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export TMPDIR=/tmp export TMPDIR=/tmp
mkdir -p /nix /build /tmp mkdir -p /nix /build /tmp
/root/test-repo/script/linux-devshell 2>&1 /root/test-repo/script/linux-devshell 2>&1
' | tee /tmp/proot-output || true ' | 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 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 cat /tmp/proot-output
exit 1 exit 1
fi 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 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 cat /tmp/proot-output
exit 1 exit 1
fi 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 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 cat /tmp/proot-output
exit 1 exit 1
fi 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" mkdir -p "$out"
''; '';
in in
(lib.mapAttrs (name: drv: mkTest name drv) testDrvs) // { (lib.mapAttrs (name: drv: mkTest name drv) testDrvs) // {
arch-integration = archTest; arch-integration-root = mkArchTest "root" true;
arch-integration-user = mkArchTest "user" false;
} }