Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(arx): add experimental macos support via fakedir #107

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

cassandracomar
Copy link

@cassandracomar cassandracomar commented Aug 8, 2024

fixes #17

see fakedir for limitations and caveats.

I've tested the nix bundle interface and am able to produce a working executable arx. I need to find a machine that doesn't have the /nix/store paths already loaded to do a final validation. I tested using ruby and I'm able to run basic ruby scripts. I'm going to continue testing with a more complicated application that makes use of native extensions next.

basic flake for testing:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
    flake-utils.url = "github:numtide/flake-utils";
    nix-bundle.url = "github:cassandracomar/nix-bundle";
    bundlers = {
      url = "github:nixos/bundlers";
      inputs.nix-bundle.follows = "nix-bundle";
    };
  };

  outputs = {
    nixpkgs,
    flake-utils,
    nix-bundle,
    bundlers,
    ...
  }:
    flake-utils.lib.eachDefaultSystem (
      system: let
        pkgs = import nixpkgs {
          inherit system;
        };
      in {
        defaultBundler = bundlers.defaultBundler.${system};
      }
    );
}

use this flake as your bundler:

nix bundle --bundler path:/path/to/flake nixpkgs#app

once this PR merges and we're able to update the nix-bundle reference in nixos/bundlers, nix bundle should work out of the box on macos, with the caveat that fakedir has to be able to intercept the syscalls in use by your application.

@cassandracomar cassandracomar changed the title feat(arx): add macos support via fakedir feat(arx): add experimental macos support via fakedir Aug 8, 2024
thread argv0 through the arx call stack so we can select the binary in
the target's bin path based on it.

this also fixes an issue with fakedir where running `Dir.pwd` within
ruby would cause a segfault due to a null ptr dereference.
@cassandracomar
Copy link
Author

cassandracomar commented Aug 11, 2024

I added a patch to fix a null pointer dereference when ruby calls getcwd() (it passes a null destination buffer to getcwd(), which I'm not sure is totally sensible). I'll upstream the patch when I figure out what to do about the fact that this patch technically leaks the buffer.

I've also made it possible to run multiple executables within the same target package (in the same /bin directory). it uses argv0 to decide which binary to execute so symlink the bottle to the other binaries you want to reach and use symlinkJoin to produce a composite package with all the tools you need in one place.

lastly, because arx changes PWD and because fakedir can't set up a chroot with paths bind mounted into the right places, I added a way to restore PWD context, so bottled tools work just like a natively installed tool -- there's now a TMPX_RESTORE_PWD env var set by the tmpx script before calling the startup script that you can use to reset the PWD context after saving the TMPX unpack dir.

the null buffer issue has been resolved upstreamed with a PR. also, fix
an issue with symlinks/shebangs not being rewritten for the initial
program executed by the startup script -- we need to avoid that call to
execvp happening in the process environment that existed prior to the
injection of the fakedir libraries. to do that, run a new shell where
the exported env vars are set and avoid that shell just execing by first
testing if the fakedir library is present and loaded, then running the
specified executable.
Cassandra Comar added 4 commits August 13, 2024 15:32
running into errors with a deficient sh that lacks `exec -a` when
running in GitHub actions. switching to bash as a) it's available
everywhere except windows and b) ensures we can still pass the bin name
through as $0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support macOS
1 participant