trunk icon indicating copy to clipboard operation
trunk copied to clipboard

trunk v0.14.0 does not work with SASS under NixOS

Open flosse opened this issue 3 years ago • 20 comments

The sass call seems to cause a problem:

Oct 12 16:43:51.204 ERROR ❌ error
error from HTML pipeline

Caused by:
    0: error from asset pipeline
    1: error spawning sass call
    2: No such file or directory (os error 2)
Error: error from HTML pipeline

flosse avatar Oct 12 '21 14:10 flosse

@flosse as a work around try patching binary like this:

patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" ~/.cache/trunk/sass-1.37.5/sass

Worked for me.

andoriyu avatar Oct 19 '21 04:10 andoriyu

Would be nice if one can specify path to all binaries in config.

andoriyu avatar Oct 19 '21 04:10 andoriyu

@andoriyu Thanks for your help. Actually I had to call nix-shell -p binutils first because $NIX_CC is not set in my zsh.

flosse avatar Nov 02 '21 10:11 flosse

... ok, it seems that it still does not work for me :disappointed:

error from HTML pipeline

Caused by:
    0: error from asset pipeline
    1: sass call returned a bad status

flosse avatar Nov 02 '21 10:11 flosse

... ok, it seems that it still does not work for me 😞

error from HTML pipeline

Caused by:
    0: error from asset pipeline
    1: sass call returned a bad status

Yeah, I kept running into issues after an issue, so I switched to web-pack.

andoriyu avatar Nov 02 '21 17:11 andoriyu

I am running into the same issue on Ubuntu (aarch64).

dvjn avatar Nov 05 '21 08:11 dvjn

Same issue here: I use this ̀shell.nix`:

{ pkgs ? import <nixpkgs> {} }:
  let
  moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
  pkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
  channel = pkgs.rustChannelOf {
     date = "2021-11-01";
     channel = "nightly";
  };
  rust = (channel.rust.override {
    targets = [ "wasm32-unknown-unknown" ];
    extensions = ["rust-src" "rust-analysis"];
  });
in
  with pkgs;
  stdenv.mkDerivation {
    name = "rust-env";
    buildInputs = [
      rust
      trunk
    ];
}

And when I try to run any example of examples/yew, it doesn't work. I get:

    Finished dev [unoptimized + debuginfo] target(s) in 36.35s
Nov 13 19:15:43.174  INFO fetching cargo artifacts
Nov 13 19:15:43.223  INFO processing WASM
Nov 13 19:15:43.245  INFO calling wasm-bindgen
Nov 13 19:15:43.246 ERROR ❌ error
error from HTML pipeline

Caused by:
    0: failed to spawn assets finalization
    1: error spawning wasm-bindgen call
    2: No such file or directory (os error 2)
Error: error from HTML pipeline

Caused by:
    0: failed to spawn assets finalization
    1: error spawning wasm-bindgen call
    2: No such file or directory (os error 2)

Any fix for nix users ?

rambip avatar Nov 13 '21 18:11 rambip

Hello folks! Sorry that you are all running into issues on this front. There appear to be multiple issues at play here.

@rambip it appears as though you are having issues with wasm-bindgen, no sass. Are you on Trunk 0.14? Because that error you are seeing looks like something folks would run into before Trunk was doing automatic downloads of such tools. As an additional workaround, just ensure that you've installed wasm-bindgen-cli on your system, and that error should go away.

For everyone else seeing the sass issues on NixOS / aarch64, this is quite likely an issue with dart-sass not having pre-compiled binaries for your target architecture. We need to gather more info, so please share your OS & architecture.

The way to work around this is to simply install and or build dart-sass yourself. If it is already on your host machine, it is present on your path, and matches the version of sass you have specified in your Trunk.toml (example here), then Trunk will not attempt to install a different version.

thedodd avatar Nov 16 '21 18:11 thedodd

Overall, it seems that we might need to take a step back and determine which platforms we can reasonably support. We definitely can not support every possible OS/architecture combination because our optional dependencies like sass may not be attempting to do so.

So, we might have to go back to the drawing board on this and once again try to use a native Rust implementation of SASS, which would definitely bypass this issue. However, that has drawbacks with such implementations typically not being the most up-to-date.

thedodd avatar Nov 16 '21 18:11 thedodd

We could use dart-sass transpiled to Javascript. That way, we cover all the platforms covered by nodejs without sacrificing sass compatibility or supporting the latest features.

https://sass-lang.com/documentation/js-api

daniel-g-gagnon avatar Dec 06 '21 19:12 daniel-g-gagnon

I have had the same issues as above: the os error 2 and then the bad status issue after using patchelf. But, I fixed it by manually downloading dart-sass the Nix way. This is because we take advantage of Trunk checking for a system installed version.

Disclaimers: I have no experience whatsoever with dart so I cannot be of help on why it works being installed this way. Also, I can't speak to this being the "correct" way to install dart packages on nix. Furthermore, I cannot speak to this being a good way to install dart packages (but it does seem safe by a preliminary reading of the nix-dart source code). I did this in half an hour as I just wanted a quick and dirty way to get up and running. It could probably be improved with IFD for steps 2-4 but as I said, quick and dirty. Now with all those disclaimers, onto how to do it yourself :)

  1. To start you need nix flakes enabled because we will use https://github.com/tadfisher/nix-dart.
  2. Checkout the https://github.com/sass/dart-sass repository on your specified version. Call dart pub get (can temporarily get dart by running nix shell nixpkgs#dart). This will generate the lock file needed by nix-dart.
  3. Call nix run github:tadfisher/nix-dart#pub2nix-lock in the same dart sass folder.
  4. Copy the generated pub2nix.lock into the folder where you have your .nix file.
  5. Write the necessary nix functions (see here: https://github.com/jordanisaacs/linkclub/blob/fd358be5d2821651363935923007fe0dc6e428ea/flake.nix#L99). You are gonna want to add nix-dart as a flake input. Note: I am using numtide's flake-utils so just replace ${system} with your intended system if not using it.
  6. In your Trunk.toml file specify the sass version you are using:
[tools]
sass = "1.45.2"

It's pretty easy if you have experience with nix flakes and packaging, but otherwise understanding what is happening will definitely be a challenge.

If you want to skip steps 1-4 and want to use version "1.45.2" here is the generated lock file I created: https://github.com/jordanisaacs/linkclub/blob/main/pub2nix.lock which you can just download and use.

jordanisaacs avatar Jan 04 '22 05:01 jordanisaacs

In terms of an easy improvement that trunk could provide for NixOS users, a config option letting us specify a path to the binary would be fantastic. This is because then we aren't required to have sass in our system paths and can instead point trunk straight to the binary in the nix store.

jordanisaacs avatar Jan 04 '22 05:01 jordanisaacs

Alright, I have it working.

Caveat, I use flakes, so I have no idea how to make it work without. My public flake has the latest dart-sass and I will try to keep it up to date as much as I can.

Here is tools section that works now:

[tools]
sass = "1.49.0"
wasm_bindgen = "0.2.78"

sass is dart-sass from my overlay wasm_bindgen is wasm-bindgen-cli from nix channels.

So much better than my previews webpack setup.

andoriyu avatar Jan 31 '22 01:01 andoriyu

In terms of an easy improvement that trunk could provide for NixOS users, a config option letting us specify a path to the binary would be fantastic. This is because then we aren't required to have sass in our system paths and can instead point trunk straight to the binary in the nix store.

Are there any chances that the next release will support that feature? @thedodd Would you accept a PR that implements it?

flosse avatar Mar 04 '22 02:03 flosse

@andoriyu I installed dart-sass with your flake but unfortunately it does not work:

$ sass index.sass
Loading failed: Expected little-endian ELF object.
VM initialization failed: Invalid vm isolate snapshot seen
sass --version                                                                                                                                                                                                                                                                                                                                  :(
Dart SDK version: 2.15.1 (stable) (Tue Dec 14 13:32:21 2021 +0100) on "linux_x64"

flosse avatar Mar 04 '22 19:03 flosse

@jordanisaacs I tried to follow your instructions but I was not able to get dart-sass working :( I even tried to run your original flake:

git clone https://github.com/jordanisaacs/linkclub
cd linkclub/
nix profile install .#devShell.x86_64-linux                                                                                            :(
error: builder for '/nix/store/cli7ncq6fphsg8xp5n1ijbzw8ay3fhcy-nix-shell.drv' failed with exit code 1;
       last 4 log lines:
       > nobuildPhase
       >
       > This derivation is not meant to be built, aborting
       >
       For full logs, run 'nix log /nix/store/cli7ncq6fphsg8xp5n1ijbzw8ay3fhcy-nix-shell.drv'.

It would be cool to have somewhere a working example :pray:

flosse avatar Mar 04 '22 20:03 flosse

FYI: I now was able somehow to make it work. If you're enabled flake support you can install dart-sass with the following command:

nix profile install github:flosse/flake#dart-sass

flosse avatar Mar 05 '22 12:03 flosse

@flosse Just so people reading this thread understand, I am pretty sure it was failing for you because you can't install a pkgs.mkShell derivation. It's a little blurry to me but a devShell is not a buildable package so it isn't installed into the nix store. In my flake the dart sass is a dependency of the shell so it is built when running the shell, but it isn't installable through nix profile install

jordanisaacs avatar Mar 10 '22 08:03 jordanisaacs

@flosse Just so people reading this thread understand, I am pretty sure it was failing for you because you can't install a pkgs.mkShell derivation. It's a little blurry to me but a devShell is not a buildable package so it isn't installed into the nix store. In my flake the dart sass is a dependency of the shell so it is built when running the shell, but it isn't installable through nix profile install

Correct.

@flosse you have to make your own flake and use my flake as an input, so you can pull dart-sass out of my overlay. I don't like writing nix files, so I only cover my (flake per-project) use case. There are some templates (trunk template is missing) you can use as starting point.

andoriyu avatar Mar 13 '22 00:03 andoriyu

For everyone else seeing the sass issues on NixOS / aarch64, this is quite likely an issue with dart-sass not having pre-compiled binaries for your target architecture. We need to gather more info, so please share your OS & architecture.

The way to work around this is to simply install and or build dart-sass yourself. If it is already on your host machine, it is present on your path, and matches the version of sass you have specified in your Trunk.toml (example here), then Trunk will not attempt to install a different version.

For clarity and reference, the issue with NixOS isn't that it's a different architecture, but that its interpreter is not in the usual location:

tlater ~/Documents/Projects/editor-color-scheme $ ldd ~/.cache/trunk/sass-1.37.5/sass
        linux-vdso.so.1 (0x00007ffffa3f0000)
        libdl.so.2 => /nix/store/rir9pf0kz1mb84x5bd3yr0fx415yy423-glibc-2.33-123/lib/libdl.so.2 (0x00007fdfadea5000)
        libpthread.so.0 => /nix/store/rir9pf0kz1mb84x5bd3yr0fx415yy423-glibc-2.33-123/lib/libpthread.so.0 (0x00007fdfade85000)
        libm.so.6 => /nix/store/rir9pf0kz1mb84x5bd3yr0fx415yy423-glibc-2.33-123/lib/libm.so.6 (0x00007fdfadd44000)
        libc.so.6 => /nix/store/rir9pf0kz1mb84x5bd3yr0fx415yy423-glibc-2.33-123/lib/libc.so.6 (0x00007fdfadb6f000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/rir9pf0kz1mb84x5bd3yr0fx415yy423-glibc-2.33-123/lib64/ld-linux-x86-64.so.2 (0x00007fdfae52e000)

ldd can find the correct location, but when executing the binary it will try to use /lib64/ld-linux-x86-64.so.2 (since that's what its interpreter is set to, i.e. the string after the initial #! in the executable). That path exists on pretty much all other 64-bit linux distributions, but NixOS instead links to the path listed by ldd for reproducibility and to enable having multiple glibc on the same system.

This is very much a NixOS-specific issue, and I wouldn't expect you to handle this. What's less NixOS-specific is that I did not expect sass to be an actual executable, much less that trunk would magically download it.

I think an explicit mention of this automagic download behavior in the docs, especially if you point out that the magic download can be prevented by simply having a binary named sass on $PATH, would sufficiently help NixOS users, as well as users of other architectures and people who need to use trunk in air-gapped build environments. We're used to having to manage dependency resolution ourselves, it's untracked dependencies downloaded at runtime that are a problem :)

TLATER avatar Mar 27 '22 02:03 TLATER

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 03 '23 00:11 github-actions[bot]

still relevant

fee1-dead avatar Nov 08 '23 14:11 fee1-dead

from what I know, this should work with trunk-ng. There's an --offline argument, which won't download any tools, but expect those to be present.

ctron avatar Nov 29 '23 13:11 ctron

This was merged back into trunk and is released with trunk 0.18.0

ctron avatar Dec 13 '23 10:12 ctron