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

Fails to build Nix Flake #1448

Closed
jaredramirez opened this issue Jan 6, 2022 · 10 comments
Closed

Fails to build Nix Flake #1448

jaredramirez opened this issue Jan 6, 2022 · 10 comments
Labels
A-packaging Area: Packaging and bundling C-bug Category: This is a bug

Comments

@jaredramirez
Copy link
Contributor

jaredramirez commented Jan 6, 2022

Reproduction steps

After cloning the repo on commit 77677039795811505d8205f4efa082fc598492fc and running nix build, I get the following output:

warning: Git tree '/Users/jaredramirez/dev/github/helix-editor/helix' is dirty
error: builder for '/nix/store/brpckzx3p0sj8p8ysp0bbay0fbvgkxs2-rust_helix-syntax-0.6.0.drv' failed with exit code 101;
       last 10 log lines:
       > unpacking source archive /nix/store/xspcc6fs70kc4xf5dnh90v6f8h6js2mn-source
       > source root is source
       > patching sources
       > configuring
       > Running cd .
       > Building build.rs (helix-syntax)
       > Running rustc --crate-name build_script_build build.rs --crate-type bin -C opt-level=3 -C codegen-units=8 --edition 2021 --cfg feature="default" --out-dir target/build/helix-syntax --emit=dep-info,link -L dependency=target/buildDeps --extern anyhow=/nix/store/w4ilp4rbjib96qqjyijzvv0jhmpniiqf-rust_anyhow-1.0.52-lib/lib/libanyhow-c29ecfa825.rlib --extern cc=/nix/store/gyki61902vvxhsd63qfh112vf325294a-rust_cc-1.0.72-lib/lib/libcc-8e4eb187e2.rlib --extern threadpool=/nix/store/h2wmprb7hxwn14d7rib6nm10y14yksna-rust_threadpool-1.8.1-lib/lib/libthreadpool-8b83498b1b.rlib --cap-lints allow --color always
       > thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', build.rs:156:10
       > stack backtrace:
       > note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
       For full logs, run 'nix log /nix/store/brpckzx3p0sj8p8ysp0bbay0fbvgkxs2-rust_helix-syntax-0.6.0.drv'.
error: 1 dependencies of derivation '/nix/store/ci83cn593sxby2iml26d29kg09wnwl21-rust_helix-term-0.6.0-test.drv' failed to build
error: 1 dependencies of derivation '/nix/store/pdc0ks6mas3bm3nvylnzhqv5g8bnn48z-rust_helix-term-0.6.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/8zr99v48rlvxizv8b84bzs9iyssbql97-rust_helix-term-0.6.0-linked.drv' failed to build
error: 1 dependencies of derivation '/nix/store/5vniw2hzg19hr3y4mi88q9nb896nkd4r-helix-0.6.0.drv' failed to build

Running nix log /nix/store/brpckzx3p0sj8p8ysp0bbay0fbvgkxs2-rust_helix-syntax-0.6.0.drv results in:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/xspcc6fs70kc4xf5dnh90v6f8h6js2mn-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
Running cd .
Building build.rs (helix-syntax)
Running rustc --crate-name build_script_build build.rs --crate-type bin -C opt-level=3 -C codegen-units=8 --edition 2021 --cfg feature="default" --out-dir target/build/helix-syntax --emit=dep-
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', build.rs:156:10
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Environment

  • Platform: MacOS 11.6 Big Sur, Intel
  • Helix version: commit 77677039795811505d8205f4efa082fc598492fc
  • Nix: nix (Nix) 2.6.0pre20211217_6e6e998
@jaredramirez jaredramirez added the C-bug Category: This is a bug label Jan 6, 2022
@happysalada
Copy link
Contributor

happysalada commented Jan 6, 2022

The flake is currently broken.
nix added support for downloading submodules then removed it. At the moment, submodules are not being downloaded and that is the origin of the error you see. Some work is being done to enable submodules in a sane way with flakes but it won't be before a bit.
If you are interested in contributing, the fix would be basically be to revert the change made https://github.com/helix-editor/helix/pull/762/files
I'm a little short on time, otherwise I would do it myself.

@jaredramirez
Copy link
Contributor Author

Got it, thanks for the help.

Maybe naively, I added back those lines and it seems to fix the helix-syntax crate. I'm now hitting:

warning: Git tree '/Users/jaredramirez/dev/github/jaredramirez/helix' is dirty
error: builder for '/nix/store/v0xq7nfy5x521qjgmbqa8c3lr85k4wii-rust_helix-view-0.6.0.drv' failed with exit code 1;
       last 10 log lines:
       > error: couldn't read src/../../base16_theme.toml: No such file or directory (os error 2)
       >   --> src/theme.rs:19:22
       >    |
       > 19 |     toml::from_slice(include_bytes!("../../base16_theme.toml"))
       >    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >    |
       >    = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
       >
       > error: aborting due to previous error
       >
       For full logs, run 'nix log /nix/store/v0xq7nfy5x521qjgmbqa8c3lr85k4wii-rust_helix-view-0.6.0.drv'.
error: 1 dependencies of derivation '/nix/store/a330gs1wanx95p6ir7xaggsmpx1jza2g-rust_helix-term-0.6.0-test.drv' failed to build
error: 1 dependencies of derivation '/nix/store/wnpivddjvnadvpsmlg7zq5n343vpx7r8-rust_helix-term-0.6.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/5nsjpdrl5mfjrscxl1yq0gdivkbl30y5-rust_helix-term-0.6.0-linked.drv' failed to build
error: 1 dependencies of derivation '/nix/store/vjnp3gzj3n0ahdi1bqs7hlqb3cjglczv-helix-0.6.0.drv' failed to build

I've tried moving base16_theme.toml into helix-view and updating the path in theme.rs, but no luck. Any idea why I'd be hitting this error?

@happysalada
Copy link
Contributor

It looks like nix is trying to read the path src/../../base16_theme.toml which doesn't exist.
Replacing with the absolute path (/base16_theme.toml) should fix compilation, however that is probably not going to play well with cargo. Not sure what is the solution here.

@jaredramirez
Copy link
Contributor Author

jaredramirez commented Jan 6, 2022

This actually seems especially weird. Here's the snippit from theme.rs:

pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
    toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme")
});
pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
    toml::from_slice(include_bytes!("../../base16_theme.toml"))
        .expect("Failed to parse base 16 default theme")
});

If I comment out BASE16_DEFAULT_THEME and all its usages, then it compiles. It's odd that it'd find "../../theme.toml" but not "../../base16_theme.toml

@jaredramirez
Copy link
Contributor Author

jaredramirez commented Jan 6, 2022

Figured it out, needed to add base16_theme.toml in flake.nix:

      overrides = {
        crateOverrides = common: _: {
          helix-term = prev: {
            preConfigure = "ln -s ${common.root}/{languages.toml,theme.toml,base16_theme.toml} ..";
            buildInputs = (prev.buildInputs or [ ]) ++ [ common.cCompiler.cc.lib ];
          };
          # link languages and theme toml files since helix-view expects them
          helix-view = _: { preConfigure = "ln -s ${common.root}/{languages.toml,theme.toml,base16_theme.toml} .."; };
          ...
      }

Will PR later today

@jaredramirez
Copy link
Contributor Author

jaredramirez commented Jan 6, 2022

Okay I think last thing. It's compiling and I can run hx just fine, but it looks seems like runtime is not being found properly. No language tree-sitters are working (no syntax highlighting) and no themes other that default and base16_theme are available.

If I run ls /nix/store/<HASH>-rust_helix-syntax-0.6.0/runtime/grammars/ I can see the compiled tree-sitters.

In flake.nix, the relevant lines are:

            runtimeDir = pkgs.runCommand "helix-runtime" { } ''
              mkdir -p $out
              ln -s ${common.root}/runtime/* $out
              ln -sf ${helixSyntax}/runtime/grammars $out
            '';

          lib.optionalAttrs (common.memberName == "helix-term") {
            nativeBuildInputs = [ pkgs.makeWrapper ];
            postFixup = ''
              if [ -f "$out/bin/hx" ]; then
                wrapProgram "$out/bin/hx" --set HELIX_RUNTIME "${runtimeDir}"
              fi
            '';
          };

These seem right? Maybe I'm not running the wrapped version of hx? In my testing, I'm running ./result/bin/hx file. Do I have to do something different to run the wrapped version? When I run tree result/, I get:

result/
└── bin
    └── hx -> /nix/store/<HASH>-rust_helix-term-0.6.0-linked/bin/hx

So there are no other binaries I could try

@happysalada
Copy link
Contributor

the binary should be the wrapped version.
if you run with the -v flag, there should be things in the logs. (you can increase verbosity by adding v up to 3 times, i.e. -vvv).

@jaredramirez
Copy link
Contributor Author

Here's what I've got:

Command: ./result/bin/hx -vvv theme.toml
Screenshot:
Screen Shot 2022-01-06 at 1 14 59 PM
Logs:

2022-01-06T13:14:12.483 helix_view::editor [ERROR] Failed to initialize the LSP for `source.toml` { LSP not defined }
2022-01-06T13:14:12.484 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE | WRITABLE
2022-01-06T13:14:12.484 mio::poll [TRACE] registering event source with poller: token=Token(2), interests=READABLE | WRITABLE
2022-01-06T13:14:12.484 mio::poll [TRACE] registering event source with poller: token=Token(0), interests=READABLE
2022-01-06T13:14:12.484 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE
2022-01-06T13:14:14.289 mio::poll [TRACE] deregistering event source from poller
2022-01-06T13:14:14.289 mio::poll [TRACE] deregistering event source from poller

Not sure what I'm looking for, but nothing is jumping out at me.

@happysalada
Copy link
Contributor

The error it shows is normal since there is no lsp for toml file (IIRC).
There seems to be nothing in the logs.
If you want to make sure the wrapped version is being run, you could try to run hx with something like
HELIX_RUNTIME=/nix/store/<HASH>-rust_helix-syntax-0.6.0/runtime hx theme.toml
if it still fails after that, then it's probably not because you're not running the wrapped binary.

@jaredramirez
Copy link
Contributor Author

Ahhh figured it out! It looks like nix-cargo-integration removed the mainBuild option in favor of overrides.crateOverrides.your-crate-name (see yusdacra/nix-cargo-integration#51). So it wasn't building the wrapped version! Now it's all working perfectly. Thank you for your help @happysalada!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-packaging Area: Packaging and bundling C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

3 participants