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

Broken flake.nix #27

Closed
gytis-ivaskevicius opened this issue Jun 1, 2021 · 14 comments · Fixed by #190
Closed

Broken flake.nix #27

gytis-ivaskevicius opened this issue Jun 1, 2021 · 14 comments · Fixed by #190

Comments

@gytis-ivaskevicius
Copy link

error: builder for '/nix/store/1cxlj18q2vjj09p2dyjk862ssvsp3xwr-rust-workspace-deps-unknown.drv' failed with exit code 101;
       last 10 log lines:
       >   failed to clone into: /build/dummy-src/.cargo-home/git/db/jsonrpc-22a65938f7d26b63
       >
       > Caused by:
       >   network failure seems to have happened
       >   if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
       >   https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
       >
       > Caused by:
       >   failed to resolve address for github.com: Name or service not known; class=Net (12)
       > [naersk] cargo returned with exit code 101, exiting
       For full logs, run 'nix log /nix/store/1cxlj18q2vjj09p2dyjk862ssvsp3xwr-rust-workspace-deps-unknown.drv'.
error: 1 dependencies of derivation '/nix/store/54mlyvashp47rlqysdr1b6b1vqskmv2p-rust-workspace-unknown.drv' failed to build

Consider using this instead: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#importing-a-cargolock-file

@archseer
Copy link
Member

archseer commented Jun 2, 2021

The jsonrpc folks tagged a new release, but did not push a new version to crates.io.

The other problem with building via flake:s submodules aren't visible during the build (NixOS/nix#4423), so all of the syntax definitions are missing and the build fails. The workaround seems to be to re-clone the repo via fetchGit

@gytis-ivaskevicius
Copy link
Author

@DieracDelta solved submodules issue somehow recently. May have used the same technique 🤔
As for jsonrpc - as I noted above workaround is to tell Nix to fetch it https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#importing-a-cargolock-file (have not tried it tho)

@itzmjauz
Copy link
Contributor

itzmjauz commented Jun 6, 2021

@DieracDelta solved submodules issue somehow recently. May have used the same technique
As for jsonrpc - as I noted above workaround is to tell Nix to fetch it https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#importing-a-cargolock-file (have not tried it tho)

So this is not really relevant for naersk, but it does work(at least for fetching dependencies) - naersk has the upside of providing some form of caching, while buildRustPackage does not. I'm trying to get a build working locally.

@itzmjauz
Copy link
Contributor

itzmjauz commented Jun 6, 2021

update: edited the snippet to include workarounds for the syntax builds; sadly this fails in checkPhase.
For some reason two tests are failing and I can't manage to reproduce this in a local nix-shell.
Something like this works by fetching the repo:

{
  description = "A port-modern text editor.";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils }:
    utils.lib.eachDefaultSystem (system:
      let pkgs = import nixpkgs { inherit system; };
      in {
        defaultPackage = with pkgs;
          rustPlatform.buildRustPackage {
            pname = "helix";
            version = "0.0.10";
            src = fetchgit {
              url = "https://github.com/helix-editor/helix"; # could probably pass a local git repo here
              fetchSubmodules = true;
              rev = "14830e75ff9316f8a5a428a06f3b3c8c4706d35a";
              sha256 = "sha256-6OQmkTR1c3TuIMiToWSoS8skCdNRZvXR5oWFBY/JpM8=";
            };

            cargoLock = {
              lockFile = ./Cargo.lock;

              outputHashes = {
                "jsonrpc-core-17.1.0" = "sha256-FsdoqN6GWtmDxt5fOeGcoGwywiHVO4+GJpMFzD88EAI=";
              };
            };
            nativeBuildInputs = [ ];
            buildInputs = [ cargo rustc ];
          };
        devShell = pkgs.callPackage ./shell.nix {};
      });
}

Depencies get correctly fetched but nix build is very nitpicky about the correct sha being used( the Cargo.lock has to be identical to the pinned upstream one ).

Then the build finishes correctly but fails while running tests:

   > failures:
   >     buffer::tests::index_of_panics_on_out_of_bounds
   >     buffer::tests::pos_of_panics_on_out_of_bounds

in helix-tui

@archseer
Copy link
Member

archseer commented Jun 7, 2021

We use crate.io deps now again: d5de918

I think the test failure could be from warnings? We fixed some warnings in buffer.rs today.

@itzmjauz
Copy link
Contributor

itzmjauz commented Jun 7, 2021

We use crate.io deps now again: d5de918

I think the test failure could be from warnings? We fixed some warnings in buffer.rs today.

I think you are correct here.

the following builds correctly, It pulls all submodules into the scope of the build:

{
  description = "A post-modern text editor.";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    rust-overlay.url = "github:oxalica/rust-overlay";
    naersk.url = "github:nmattia/naersk";
  };

  outputs = inputs@{ self, nixpkgs, naersk, rust-overlay, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; overlays = [ rust-overlay.overlay ]; };
        rust = (pkgs.rustChannelOf {
          date = "2021-05-01";
          channel = "nightly";
        }).minimal; # cargo, rustc and rust-std
        naerskLib = naersk.lib."${system}".override {
          # naersk can't build with stable?!
          # inherit (pkgs.rust-bin.stable.latest) rustc cargo;
          rustc = rust;
          cargo = rust;
        };
      in rec {
        packages.helix = naerskLib.buildPackage {
          pname = "helix";
          root = ./.;
          src = pkgs.fetchgit {
            url = "https://github.com/helix-editor/helix"; # could probably pass a local git repo here
            fetchSubmodules = true;
            rev = "68affa3c598723a8b9451ef3dcceda83ae161e39";
            sha256 = "sha256-6RF1GmqDNqEeiPnFDErkNc0+gPTg3KJp8JfCD1FoUCI=";
          };
        };
        defaultPackage = packages.helix;
        devShell = pkgs.callPackage ./shell.nix {};
      });
}

This flake.nix build is based on the commit 68affa3;

It is probably unfeasible to have nix-flake build from the master branch since this can often result in a cargo.lock mismatch. Updating it manually is not difficult though. (change rev, build, replace sha, build)

@archseer
Copy link
Member

archseer commented Jun 7, 2021

I think you could use fetchGithub and fetch the latest tagged release for the time being? Then if/when the submodule support gets integrated we can switch to always building latest master.

Other than that, feel free to open a PR with these changes :)

@itzmjauz
Copy link
Contributor

itzmjauz commented Jun 7, 2021

I think you could use fetchGithub and fetch the latest tagged release for the time being? Then if/when the submodule support gets integrated we can switch to always building latest master.

Other than that, feel free to open a PR with these changes :)

Latest release sadly does not have d5de918 so the build will always fail.
I will wait for v0.0.11 and start a PR, meanwhile for the hell of it:
nix shell github:itzmjauz/helix/nix-flake --command hx (if you have nix flakes enabled )
gets you helix :)

@pickfire
Copy link
Contributor

pickfire commented Jun 8, 2021

I think we should add nix builds to CI to prevent regression.

@nrdxp
Copy link
Contributor

nrdxp commented Jun 8, 2021

we could add helix itself as a flake input to pull submodules:

    helix = {
      flake = false;
      url = "https://github.com/helix-editor/helix";
      type = "git";
      submodules = true;
    };

Doing this, I was able to build the package from the flake like so:

        packages.helix = naerskLib.buildPackage {
          pname = "helix";
          root = inputs.helix;
        };

@itzmjauz
Copy link
Contributor

itzmjauz commented Jun 8, 2021

we could add helix itself as a flake input to pull submodules:

    helix = {
      flake = false;
      url = "https://github.com/helix-editor/helix";
      type = "git";
      submodules = true;
    };

Doing this, I was able to build the package from the flake like so:

        packages.helix = naerskLib.buildPackage {
          pname = "helix";
          root = inputs.helix;
        };

Does this also work when using root = ./.; ? (since you'd want to be able to run nix build with local changes ) I will test when I have the time.

Edit:
I imagine using root = ./. , src = inputs.helix , should include local changes.

@nrdxp nrdxp mentioned this issue Jun 8, 2021
@nrdxp
Copy link
Contributor

nrdxp commented Jun 8, 2021

@itzmjauz I gave it a try, but it doesn't appear to take local changes into account.

@itzmjauz
Copy link
Contributor

itzmjauz commented Jun 8, 2021

@itzmjauz I gave it a try, but it doesn't appear to take local changes into account.

Yeah I'm seeing that too.. It might be building all helix modules ( helix-term helix-syntax etc) from upstream as well..

@nrdxp
Copy link
Contributor

nrdxp commented Jun 8, 2021

After reviewing naersk docs, root is only used to read Cargo.toml and Cargo.lock so I guess it's no surprise. Perhaps something like a symlinkJoin could help us merge the local repo with the remote? I'll see if I can get something like that to work.

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

Successfully merging a pull request may close this issue.

5 participants