ruby-nix icon indicating copy to clipboard operation
ruby-nix copied to clipboard

Unexpected gem version after pinning

Open swebra opened this issue 11 months ago • 6 comments

After pinning sass-embedded to v1.78.0 in my Gemfile, accordingly updating my Gemfile.lock and my gemset.nix, and entering my ruby-nix environment, I observe sass v1.80.5 being present despite there being no references to that version anywhere in the lock file or gemset.

The project in question is a jekyll blog using a local gem (hence why I ended up here), but I've been able to reproduce the behavior with this jekyll starter kit. It serves as a good example as the Jekyll dev server shows Sass color function deprecation warnings that were only introduced in v1.79.0 and import deprecation warnings that were only introduced in v1.80.0.

Reproduction:

  1. Clone or download and unzip v9.2.1 of hydejack-starter-kit
  2. Pin sass-embedded in the Gemfile:
    echo 'gem "sass-embedded", "~> 1.78.0"' >> Gemfile
    
  3. Create Gemfile.lock and gemset.nix, ignoring platform-specific gems:
    nix run nixpkgs#bundler -- config set --local force_ruby_platform true
    export BUNDLE_PATH=vendor/bundle
    nix run nixpkgs#bundler -- lock
    nix run github:inscapist/bundix -- lock
    
  4. Add the following flake.nix:
    {
      inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
        ruby-nix.url = "github:inscapist/ruby-nix";
      };
    
      outputs = {
        self,
        nixpkgs,
        ruby-nix,
      }: let
        system = "x86_64-linux";
        pkgs = nixpkgs.legacyPackages.${system};
        rubyNix = ruby-nix.lib pkgs;
    
        rubyNixEnv =
          (rubyNix {
            name = "example";
            ruby = pkgs.ruby;
            gemset = ./gemset.nix;
          })
          .env;
    
        bundixEnv = pkgs.bundlerEnv {
          name = "example";
          ruby = pkgs.ruby;
          gemdir = ./.;
        };
      in {
        devShells.${system} = {
          default = pkgs.mkShell {
            packages = [
              rubyNixEnv
            ];
          };
    
          bundix-example = pkgs.mkShell {
            packages = [
              bundixEnv
            ];
          };
    
          basic-example = pkgs.mkShell {
            packages = [
              pkgs.ruby
            ];
          };
        };
      };
    }
    
  5. After entering the default dev shell (nix develop) which uses ruby-nix, observe the sass bin version and the deprecation warning when running jekyll:
    sass --version # 1.80.5
    jekyll serve # Sass deprecation notices observed
    
  6. After entering the "bundix" dev shell (nix develop .#bundix-example) which uses the default bundlerEnv implementation, observe the sass bin version and the deprecation warning when running jekyll:
    sass --version # 1.80.5
    jekyll serve # Sass deprecation notices observed
    
  7. After entering the "basic" dev shell (nix develop .#basic-example) and doing a traditional bundle install, observe the sass version and the lack of deprecation warnings when running jekyll:
    export BUNDLE_PATH=vendor/bundle
    bundle install
    
    bundle exec sass --version # 1.78.0
    bundle exec jekyll serve # No sass deprecation notices observed
    

I'm unsure how to further diagnose from here so apologies if this issue better belongs in the inscapist/bundix repo or elsewhere. Let me know if I can do anything else to assist!

swebra avatar Jan 28 '25 02:01 swebra

I really appreciate the writeup here! I've been encountering a similar issue for a while but every time I started peeking into things, it somehow corrected itself. I suspect this might be related: I can change references (including the hash) in the gemset.nix and the develop shell starts instantly - no new downloads observed and gem versions remain the same. Perhaps it's some kind of caching issue.

LoganBarnett avatar Apr 09 '25 17:04 LoganBarnett

Interestingly, /nix/store/qmgngwsg7xi6rdkgv6p925nwkxs88ys2-ruby3.3-sass-embedded-1.78.0/lib/ruby/gems/3.3.0/gems/sass-embedded-1.78.0/ext/sass/cli.rb contains this:

# frozen_string_literal: true

module Sass
  module CLI
    COMMAND = [
      File.absolute_path('/nix/store/k4l60jsfc8qb2rr0pkfmavdshlxjlqsj-dart-sass-1.80.5/bin/sass', __dir__).freeze
    ].freeze
  end

  private_constant :CLI
end

emptyflask avatar Apr 09 '25 17:04 emptyflask

Some nix behavior is fixed here https://github.com/sass-contrib/sass-embedded-host-ruby/issues/116#issuecomment-2417547868 but using sass-embedded v1.79.6, the sass version is unaffected:

# frozen_string_literal: true

require_relative '../../lib/sass/elf'

module Sass
  module CLI
    INTERPRETER = '/nix/store/maxa3xhmxggrc5v2vc0c3pjb79hjlkp9-glibc-2.40-66/lib/ld-linux-x86-64.so.2'

    INTERPRETER_SUFFIX = '/ld-linux-x86-64.so.2'

    COMMAND = [
      *(ELF::INTERPRETER if ELF::INTERPRETER != INTERPRETER && ELF::INTERPRETER&.end_with?(INTERPRETER_SUFFIX)),
      File.absolute_path('/nix/store/k4l60jsfc8qb2rr0pkfmavdshlxjlqsj-dart-sass-1.80.5/bin/sass', __dir__).freeze
    ].freeze
  end

  private_constant :CLI
end

emptyflask avatar Apr 09 '25 17:04 emptyflask

@emptyflask this is a great observation. Thanks! Indeed, when I check the actual gem version installed, I see it's the intended gem version:

$ gem list | grep sass-embedded
sass-embedded (1.78.0)

So it sounds like it's not my issue of mis-cached or mis-versioned gems. I'll have to keep digging and file a different ticket. That said, it sounds like issue here is resolved via the sass-embedded fix and thus we can close this?

LoganBarnett avatar Apr 09 '25 19:04 LoganBarnett

I changed the nixpkgs version in the flake inputs to 24.05, and the sass version changed to 1.77.2, so it's definitely coming from there. Even though I'm not exactly sure how that's happening, it does make sense, since otherwise it seems unlikely that dart-sass would be built successfully. If you need a specific version, maybe you could use an overlay?

emptyflask avatar Apr 09 '25 19:04 emptyflask

Actually my issue is due to some direnv caching issues. @inscapist gave me a solution in https://github.com/inscapist/ruby-nix/issues/31#issuecomment-2330800192 but I'm only just now trying it out. And it works! So yeah definitely a different issue. I'm not even using this sass gem - I've just been on the lookout for anything resembling my issue. I promise I'm not trying to hijack threads 😅

LoganBarnett avatar Apr 09 '25 21:04 LoganBarnett