Skip to content

Conversation

sandydoo
Copy link
Member

@sandydoo sandydoo commented Aug 8, 2025

This unlocks the container restriction on macOS. You will need an <arch>-linux builder already set up in your nix.conf to build the container.

The underlying flake now exports configurations for all 4 systems.

Fixes #430

@sandydoo sandydoo added enhancement New feature or request macos Affects systems running macOS containers Related to running containers with devenv labels Aug 8, 2025
Copy link
Contributor

github-actions bot commented Aug 8, 2025

🔍 Suggested Reviewers

Based on git blame analysis of the changed lines, the following contributors have significant experience with the modified code:

Please consider reviewing this PR as you have authored significant portions of the code being modified. Your expertise would be valuable! 🙏

This comment was automatically generated by git-blame-auto-reviewer

Last updated: 2025-09-12T11:52:13.720Z

Copy link
Contributor

claude bot commented Aug 8, 2025

Claude finished @sandydoo's task —— View job


PR Review: devenv containers on macOS

I've analyzed the code changes in this PR. Here are the key issues and improvements to consider:

🔧 Code Quality & Architecture Issues

  1. Hard-coded architecture mapping (devenv.rs:479-487)

    let target_system = if host_os == "macos" {
        match host_arch {
            "aarch64" => "aarch64-linux",
            "x86_64" => "x86_64-linux",
            _ => bail!("Unsupported container architecture for macOS: {host_arch}"),
        }
    } else {
        &self.global_options.system
    };
    • This hard-coded mapping is fragile and doesn't handle future architectures
    • Consider using a configuration-driven approach or helper function
    • The error message could be more helpful by listing supported architectures
  2. Inconsistent error handling

    • Line 483: Uses bail! macro for architecture errors
    • Consider providing guidance on how to add cross-platform builder support

⚠️ Potential Bugs

  1. Missing validation in flake template

    • The new perSystem structure generates configurations for all systems but doesn't validate if required builders exist
    • Consider adding runtime checks for cross-platform builds on macOS
  2. Unsafe environment variable usage (build.rs:4,8)

    std::env::var("CARGO_CFG_TARGET_ARCH").unwrap()
    std::env::var("CARGO_CFG_TARGET_OS").unwrap()
    • Using .unwrap() on environment variables that should always exist in build context
    • While these are guaranteed by Cargo, consider more descriptive error messages

🚀 Performance Considerations

  1. Redundant system evaluation

    • The flake template now generates all 4 system configurations even when only one is needed
    • For container builds, this increases evaluation time unnecessarily
    • Consider lazy evaluation or system-specific builds
  2. Memory usage in flake template

    • Lines 161-176: All system configurations are kept in memory simultaneously
    • For large projects, this could increase memory consumption significantly

🔒 Security Concerns

  1. Cross-compilation trust boundary
    • Building Linux containers on macOS requires remote builders, expanding attack surface
    • No validation that the remote builder is configured securely
    • Consider documenting security best practices for cross-platform builds

📋 Test Coverage Issues

  1. Limited test coverage for new functionality

    • New test only validates basic build output parsing
    • Missing tests for:
      • Cross-architecture container builds
      • Error handling for missing builders
      • macOS-specific code paths
    • Consider adding integration tests for the container build flow
  2. Test configuration lacks macOS scenarios

    • tests/outputs/.test.sh doesn't test macOS-specific behavior
    • No tests for architecture detection and mapping logic

💡 Suggested Improvements

  1. Architecture mapping helper

    fn map_host_to_container_arch(host_os: &str, host_arch: &str) -> Result<&str> {
        match (host_os, host_arch) {
            ("macos", "aarch64") => Ok("aarch64-linux"),
            ("macos", "x86_64") => Ok("x86_64-linux"), 
            ("macos", arch) => bail!("Unsupported macOS architecture '{}'. Supported: aarch64, x86_64", arch),
            _ => Ok(host_arch), // Use system default for non-macOS
        }
    }
  2. Builder validation

    • Add checks to verify required builders are configured before attempting cross-platform builds
    • Provide helpful error messages with setup instructions
  3. Documentation

    • The PR description mentions needing <arch>-linux builder setup but this isn't validated at runtime
    • Consider adding runtime checks and helpful error messages

Todo Summary

  • Analyze the main Nix template changes in flake.tmpl.nix
  • Review the new build.rs file
  • Check devenv.rs modifications
  • Examine test configuration changes
  • Look for potential issues and improvements
  • Provide comprehensive feedback

The core functionality looks solid, but the implementation could be more robust with better error handling, validation, and test coverage for the cross-platform scenarios.


Copy link

cloudflare-workers-and-pages bot commented Aug 8, 2025

Deploying devenv with  Cloudflare Pages  Cloudflare Pages

Latest commit: ede4c48
Status:🚫  Build failed.

View logs

@domenkozar
Copy link
Member

Nice :) Let's merge, needs some rebasing :)

@domenkozar domenkozar added this to the 1.9 milestone Aug 12, 2025
@sandydoo sandydoo force-pushed the container-test branch 5 times, most recently from ea1660e to a8086db Compare August 15, 2025 14:11
@sandydoo
Copy link
Member Author

After the TUI work, I think we should always pass commands through CacheCommand. Not for caching, but to get access to the parsed logs and capture the errors. This would let us detect the missing builder error and suggest ways to set one up.

@domenkozar
Copy link
Member

@sandydoo let's merge this?

We were recursing into a derivation that had a recursive loop in it.

Honestly, we should probably just build outputs (the attr) vs this.
@domenkozar domenkozar marked this pull request as ready for review September 14, 2025 12:23
@domenkozar domenkozar merged commit 8190bca into main Sep 14, 2025
265 of 278 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Related to running containers with devenv enhancement New feature or request macos Affects systems running macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow shipping containers from macOS
2 participants