From c041f2e88d5428de20d2dc2dde7797bfc96f0230 Mon Sep 17 00:00:00 2001 From: yukkop Date: Fri, 1 May 2026 23:11:23 +0000 Subject: [PATCH] fix: linux-devshell for ubuntu --- package/linux-devshell/linux-devshell.sh | 8 +- test/package/linux-devshell/default.nix | 99 ++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/package/linux-devshell/linux-devshell.sh b/package/linux-devshell/linux-devshell.sh index 95e43d5..724b789 100644 --- a/package/linux-devshell/linux-devshell.sh +++ b/package/linux-devshell/linux-devshell.sh @@ -27,7 +27,13 @@ install_nix() { log_info "Nix not found. Installing via nixos.org/nix/install --no-daemon..." if ! command -v curl >/dev/null 2>&1; then - log_error "curl is required. Install it with: sudo pacman -S curl" + if command -v apt >/dev/null 2>&1; then + log_error "curl is required. Install it with: sudo apt update && sudo apt install -y curl" + elif command -v pacman >/dev/null 2>&1; then + log_error "curl is required. Install it with: sudo pacman -S curl" + else + log_error "curl is required. Install it with your system package manager." + fi exit 1 fi diff --git a/test/package/linux-devshell/default.nix b/test/package/linux-devshell/default.nix index df27be8..104fb53 100644 --- a/test/package/linux-devshell/default.nix +++ b/test/package/linux-devshell/default.nix @@ -35,6 +35,11 @@ hash = "sha256-1YnwGo2li1yIzm6W6yYYwuZeY16Ddsrz1LRTY6/A3Ww="; }; + ubuntuBootstrap = pkgs.fetchurl { + url = "https://cdimage.ubuntu.com/ubuntu-base/releases/24.04/release/ubuntu-base-24.04.3-base-amd64.tar.gz"; + hash = "sha256-a8LN45MK0Iizu0b6RSeeltJbw4EPIJhQ7L5HInEYdPk="; + }; + mkTest = testName: testDrv: pkgs.runCommand "linux-devshell-test-${testName}" { nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused ]; @@ -141,10 +146,104 @@ log success "Script runs correctly in Arch Linux as ${name}" + mkdir -p "$out" + ''; + + mkUbuntuTest = name: root: pkgs.runCommand "linux-devshell-test-ubuntu-${name}" + { + nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused pkgs.gnutar pkgs.gzip pkgs.git ]; + buildInputs = [ pkgs.dash pkgs.proot ]; + linuxDevShellStandalone = linuxDevShellStandalone; + ubuntuBootstrap = ubuntuBootstrap; + } '' + ${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log} + export HECTIC_LOG=trace + + log notice "test case: ''${WHITE}ubuntu ${name}" + + UBUNTU_DIR="$(mktemp -d)" + trap 'rm -rf "$UBUNTU_DIR"' EXIT + + log info "Extracting Ubuntu bootstrap..." + tar -xf "${ubuntuBootstrap}" -C "$UBUNTU_DIR" \ + --no-same-permissions --no-same-owner || true + + log info "Preparing Ubuntu environment..." + mkdir -p "$UBUNTU_DIR/root/test-repo/script" + cp "${linuxDevShellStandalone}" "$UBUNTU_DIR/root/test-repo/script/linux-devshell" + chmod +x "$UBUNTU_DIR/root/test-repo/script/linux-devshell" + + cat > "$UBUNTU_DIR/root/test-repo/flake.nix" <<'EOF' + { + description = "Test flake for linux-devshell"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + outputs = { self, nixpkgs }: { + devShells.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.mkShell { + shellHook = '''' + echo "=== Inside dev shell ===" + exit 0 + ''''; + }; + }; + } + EOF + + mkdir -p "$UBUNTU_DIR/root/test-repo/.git" + git init "$UBUNTU_DIR/root/test-repo" + git -C "$UBUNTU_DIR/root/test-repo" config user.email "test@example.com" + git -C "$UBUNTU_DIR/root/test-repo" config user.name "Test" + git -C "$UBUNTU_DIR/root/test-repo" add . + git -C "$UBUNTU_DIR/root/test-repo" commit -m "init" + + log info "Running linux-devshell as ${name} in Ubuntu via proot..." + ${lib.optionalString root "proot -b /dev -0 -r \"$UBUNTU_DIR\" -w /root/test-repo /bin/sh -c '"} + ${lib.optionalString (!root) "proot -b /dev -r \"$UBUNTU_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 ${name} behavior..." + + if ! grep -q "Nix not found" /tmp/proot-output; then + log error "Script did not detect missing Nix as ${name}" + cat /tmp/proot-output + exit 1 + fi + 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 as ${name}" + cat /tmp/proot-output + exit 1 + fi + 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 || grep -q "curl is required" /tmp/proot-output; then + log success "Script handles missing curl or network failure as ${name}" + else + log error "Script did not handle failure gracefully as ${name}" + cat /tmp/proot-output + exit 1 + fi + + log success "Script runs correctly in Ubuntu as ${name}" + mkdir -p "$out" ''; in (lib.mapAttrs (name: drv: mkTest name drv) testDrvs) // { arch-integration-root = mkArchTest "root" true; arch-integration-user = mkArchTest "user" false; + ubuntu-integration-root = mkUbuntuTest "root" true; + ubuntu-integration-user = mkUbuntuTest "user" false; }