Open endgame opened 4 years ago
I have the same issue. It's trying to download from a url that doesn't exist (missing _x86_64-linux
suffix).
This is the correct path:
https://rubygems.org/downloads/sorbet-static-0.5.5713-x86_64-linux.gem
It's trying to fetch this:
https://rubygems.org/downloads/sorbet-static-0.5.5713.gem
In the meantime, for those who would like to use Sorbet with Nix and Linux, the following works:
let
# Import Nixpkgs however you like, be it <nixpkgs> or with Niv
pkgs = ...;
rubyGems = pkgs.bundlerEnv {
name = "gems-for-my-project";
ruby = pkgs.ruby_3_1;
gemdir = ./path/to/gemfile/directory;
gemConfig = pkgs.defaultGemConfig // {
# Poor man's solution: `sorbet-static` has a specific version per system, and Bundix currently does not support that.
# Additionally, the `sorbet` executable needs ELF patching.
# If the Sorbet version ever changes (after re-running `bundle update` then `bundix`) then the SHA256 must be updated accordingly.
# The simplest way to do so is to leave it empty and look at the error message to get the right hash.
# See https://nixos.org/manual/nixpkgs/stable/#developing-with-ruby
# See https://github.com/nix-community/bundix/issues/71
sorbet-static = attrs:
# Bundix picks the Darwin version by default, so we only need to patch on Linux
if pkgs.stdenv.isLinux then {
# Append the OS-specific version suffix
version = attrs.version + "-x86_64-linux";
# Update the SHA256 accordingly
source = attrs.source // { sha256 = "sha256-nuvwK1pQSJ4EsYdkT42q5NsG4QlZZuYT9Zxzz6839rk="; };
# Post-fix the gem by fixing the interpreter with the correct Nix one (default interpreter is `/lib64/ld-linux-x86-64.so.2` which usually does not exist on Nix machines)
nativeBuildInputs = with pkgs; [ autoPatchelfHook ];
} else attrs;
};
};
in
pkgs.mkShell {
buildInputs = [
# Bundler must be before `rubyGems` because the `bundle` executable provided by `rubyGems` does not allow updating the `Gemfile.lock` files
bundler
rubyGems.wrappedRuby
rubyGems
bundix
];
}
The SHA256 part is not ideal, but otherwise it seems to work just fine.
srb
correctly typecheckssrb
commands (e.g. srb rbi update
) worksrb
can now be used as LSP, providing type information, auto fixes, etc., directly from your favorite IDEAlso, I think the code above can be easily adapted to other gems than Sorbet with a similar architecture-specific issue.
I hope this is helpful to someone!
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
Thanks @sir4ur0n this helped me a lot to figure out how to use autoPatchelfHook on the sorbet gem. I vendored a forked version of bundix @jdelStrother's patches to generate separate gemsets as well as support ruby 3, and this is my current thing that is so far working great for linux and arm mac sorbet
let
overlays = [
(self: super: {
ruby = pkgs.ruby_3_1;
})
];
pkgs = import nixpkgs { inherit overlays system; };
bundlerPlatform = if pkgs.ruby.system == utils.system.aarch64-darwin then "arm64-darwin" else pkgs.ruby.system;
rubyEnv = pkgs.bundlerEnv {
name = "ruby-env";
inherit (pkgs) ruby;
gemdir = ./.;
gemset = .nix/gemset + ".${bundlerPlatform}.nix";
gemConfig = pkgs.defaultGemConfig // {
sorbet-static = attrs:
if pkgs.stdenv.isLinux then {
nativeBuildInputs = with pkgs; [ autoPatchelfHook ];
} else attrs;
};
};
I am trying to bundix the sorbet typechecker.
Gemfile
:default.nix
(I usecallPackage
on this):Because of #70 , I am trying to generate
gemset.nix
usingbundle update && bundix
. Here is what happens:First, bundler correctly downloads the gem that matches my arch (
x86_64-linux
):Then bundix downloads a Darwin gem when constructing
gemset.nix
?Attempting to build this fails:
Note that it's trying to download a gem file with no architecture. If you visit the gem page for
sorbet-static
, you'll see a download link that includes the arch. This seems to be getting lost somewhere. Not sure if that is abundlerApp
bug in nix code, or a problem with the generatedgemset.nix
. But I'm pretty sure that bundix looking at the Darwin gem when constructinggemset.nix
is wrong.