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

jaspr build does not work inside nix #282

Open
RossComputerGuy opened this issue Aug 23, 2024 · 20 comments
Open

jaspr build does not work inside nix #282

RossComputerGuy opened this issue Aug 23, 2024 · 20 comments

Comments

@RossComputerGuy
Copy link

Description

nomics-web-client> Running phase: configurePhase
nomics-web-client> no configure script, doing nothing
nomics-web-client> Executing dartConfigHook
nomics-web-client> Setting up SDK
nomics-web-client> Installing dependencies
nomics-web-client> Finished dartConfigHook
nomics-web-client> Running phase: buildPhase
nomics-web-client> PathNotFoundException: Creation failed, path = '/homeless-shelter/.dart-cli-completion' (OS Error: No such file or directory, errno = 2)
nomics-web-client> [CLI] Building jaspr for static rendering mode.
nomics-web-client> ⠙ [CLI] Building web assets...... (0ms)Bad state: Unable to start build daemon.

Steps To Reproduce

  1. Use jaspr_cli to set up a basic site
  2. Add jaspr_cli to dev dependencies
  3. Use yq . pubspec.lock > pubspec.lock.json
  4. Add the default.nix below and nix-build.
{ pkgs ? import <nixpkgs> }:
pkgs.buildDartApplication {
  pname = "web";
  version = "0.0.0";

  src = ./.;

  buildPhase = ''
    runHook preBuild

    packageRunCustom jaspr_cli jaspr bin -- build

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    cp -r build/jaspr $out

    runHook postInstall
  '';

  sdkSourceBuilders = {
    # https://github.com/dart-lang/pub/blob/e1fbda73d1ac597474b82882ee0bf6ecea5df108/lib/src/sdk/dart.dart#L80
    "dart" = name: pkgs.runCommand "dart-sdk-${name}" { passthru.packageRoot = "."; } ''
      for path in '${pkgs.dart}/pkg/${name}'; do
        if [ -d "$path" ]; then
          ln -s "$path" "$out"
          break
        fi
      done

      if [ ! -e "$out" ]; then
        echo 1>&2 'The Dart SDK does not contain the requested package: ${name}!'
        exit 1
      fi
    '';
  };

  pubspecLock = pkgs.lib.importJSON ./pubspec.lock.json;
}

Expected Behavior

Jaspr should build

Additional Context

Requires an overlay for nix to support Dart 3.5.1

@RossComputerGuy
Copy link
Author

Issue seems to be with dart pub get being called from a sandbox, jaspr should have a switch to be able to disable dart pub get.

@schultek
Copy link
Owner

I have never used nix, nor do I even know what it is. So sadly its out of my knowledge to help you with this.

@schultek
Copy link
Owner

schultek commented Aug 23, 2024

This error:

PathNotFoundException: Creation failed, path = '/homeless-shelter/.dart-cli-completion' (OS Error: No such file or directory, errno = 2)

looks like its coming from https://pub.dev/packages/cli_completion

@RossComputerGuy
Copy link
Author

The CLI completion error doesn't prevent building, I added verbose logging and got a socket error. For whatever reason, jaspr is fetching from pub.dev inside a networkless sandbox.

@schultek
Copy link
Owner

The cli is checking for updates everytime a command is run. But this is try/catched so any exception shouldn't crash the cli.

The build command itself is effectively only doing dart compile and build_runner build. It may spin up its own local http server but without any network requests.

Can you post the full error you get from running in verbose mode?

@RossComputerGuy
Copy link
Author

nomics-web-client> PathNotFoundException: Creation failed, path = '/homeless-shelter/.dart-cli-completion' (OS Error: No such file or directory, errno = 2)
nomics-web-client> [CLI] Building jaspr for static rendering mode.
nomics-web-client> [CLI] Building web assets...
nomics-web-client> [BUILDER] [ERROR] Got socket error trying to find package lints at https://pub.dev.
nomics-web-client> Bad state: Unable to start build daemon

@schultek
Copy link
Owner

Weird this is coming from the builder.

Can you try running 'dart run build_runner build' instead of 'jaspr build'?

@RossComputerGuy
Copy link
Author

web> Running phase: buildPhase
web> [INFO] Generating build script completed, took 205ms
web> [INFO] Precompiling build script... completed, took 2.8s
web> [INFO] Building new asset graph completed, took 1.7s
web> [INFO] Found 1 declared outputs which already exist on disk. This is likely because the`.dart_tool/build` folder was deleted, or you are submitting generated files to your source repository.
web> Delete these files?
web> 1 - Delete
web> 2 - Cancel build
web> 3 - List conflicts
web>
web>
web> You have hit a bug in build_runner
web> Please file an issue with reproduction steps at https://github.com/dart-lang/build/issues
web>
web>
web> Null check operator used on a null value
web> package:build_runner_core/src/environment/io_environment.dart 67:41           IOEnvironment.prompt
web> package:build_runner_core/src/environment/overridable_environment.dart 63:16  OverrideableEnvironment.prompt
web> package:build_runner_core/src/generate/build_definition.dart 546:41           _Loader._initialBuildCleanup
web> package:build_runner_core/src/generate/build_definition.dart 283:17           _Loader.prepareWorkspace.<fn>
web> package:build_runner_core/src/logging/logging.dart 25:30                      logTimedAsync
web> package:build_runner_core/src/generate/build_definition.dart 280:13           _Loader.prepareWorkspace
web> package:build_runner_core/src/generate/build_impl.dart 114:27                 BuildImpl.create
web> package:build_runner_core/src/generate/build_runner.dart 34:26                BuildRunner.create
web> package:build_runner/src/generate/build.dart 109:17                           build
web> package:build_runner/src/entrypoint/build.dart 35:18                          BuildCommand._run
web> package:args/command_runner.dart 212:13                                       CommandRunner.runCommand
web> package:build_runner/src/entrypoint/run.dart 26:18                            run
web> .dart_tool/build/entrypoint/build.dart 210:16                                 main

@schultek
Copy link
Owner

Run with --delete-conflicting-outputs

@RossComputerGuy
Copy link
Author

Yeah, that worked.

@schultek
Copy link
Owner

schultek commented Sep 14, 2024

@RossComputerGuy Can I close this? Are you still having an error with the latest version?

@RossComputerGuy
Copy link
Author

Yes, it is still an issue. Using build_runner doesn't produce any output files.

@schultek
Copy link
Owner

Then I need more info. Please provide (from inside your pipeline)

  • output of jaspr doctor
  • full output of jaspr build --verbose

@RossComputerGuy
Copy link
Author

Here's the output of both those commands.

web> PathNotFoundException: Creation failed, path = '/homeless-shelter/.dart-cli-completion' (OS Error: No such file or directory, errno = 2)
web> [✓] Jaspr CLI (Version 0.15.0)
web>   • Dart Version 3.5.1 (stable) (Tue Aug 13 21:02:17 2024 +0000) on "linux_arm64" at dart
web>   • Running on linux Linux 6.9.9-asahi #1-NixOS SMP PREEMPT_DYNAMIC Tue Jan  1 00:00:00 UTC 1980 - Locale en_US
web>   • Analytics: Disabled
web>
web> [✓] Current Project
web>   • Dependencies on core packages:
web>     • jaspr: ^0.15.0
web>     • jaspr_builder: ^0.15.0 (dev)
web>     • jaspr_router: ^0.5.1
web>   • Rendering mode: static
web>   • Uses jaspr compilers: false
web>   • Uses flutter embedding: false
web>
web> PathNotFoundException: Creation failed, path = '/homeless-shelter/.dart-cli-completion' (OS Error: No such file or directory, errno = 2)
web> [CLI] Building jaspr for static rendering mode.
web> [CLI] Building web assets...
web> [BUILDER] [ERROR] Got socket error trying to find package lints at https://pub.dev.
web> Bad state: Unable to start build daemon.

@RossComputerGuy
Copy link
Author

.dart_tool/package_config.json exists with lints in it.

@AdamJel
Copy link

AdamJel commented Sep 16, 2024

A side note regarding the pub.dev call in networkless env: based on my experience from other projects, I would make "working in air-gapped system" a hard requirement (e.g. as part of Pana analysis). Packages way to often rely on some kind of network requests even though it is not a necessity for a given task. For anybody working with such systems, these represents obstacles. So, when e.g. designing CLI and its internal workings, it is nice to include options to suppress any http calls 🙏🏻

@RossComputerGuy
Copy link
Author

@AdamJel Agreed, Nix only allows networking inside a derivation if you provide the output hash. This would mean that Jaspr would have to be capable of always producing the same exact output in order to get it working in its current state. This also means updating that hash with every single change which is kinda unreasonable. So yeah, being able to disable the networking is a hard requirement.

@schultek
Copy link
Owner

This is nothing that jaspr build does deliberately.
It uses dart run ... internally, and this tries to do pub get if it detects that dependencies need resolving.

You can try running dart pub get --offline before the build command.

Not sure if that works if you are in a sandbox though. You need somehow to move all packages into the sandbox as well if you don't want to do any network requests.

@RossComputerGuy
Copy link
Author

It uses dart run ... internally, and this tries to do pub get if it detects that dependencies need resolving.

Except it'll fetch by default unless you specify a packages JSON file.

You can try running dart pub get --offline before the build command.

Already tried that and it didn't help.

@schultek
Copy link
Owner

Ah looks like this is a dart bug: dart-lang/pub#4390

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

No branches or pull requests

3 participants