elsa icon indicating copy to clipboard operation
elsa copied to clipboard

Feature request: Add nix build

Open 573 opened this issue 5 years ago • 7 comments

I would like to add a nix build to add elsa to nixpkgs. Currently the build is stuck

# default.nix; usage: nix-build --pure -E 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./. {}'
{ stdenv, fetchFromGitHub, buildGoModule, go-bindata, go-bindata-assetfs }:

buildGoModule rec {
  pname = "elsa";
  version = "master";
  revision = "0375d76d2c802b497cec44e5069920643287cc98";
  goPackagePath = "github.com/elsaland/elsa";

  nativeBuildInputs = [ go-bindata go-bindata-assetfs ];

  preBuild = ''
    # https://github.com/elsaland/elsa/blob/5419ed2/Makefile#L2
    go generate;
    go run ./bootstrap/;
    # go build -o elsa .
  '';

  src = fetchFromGitHub {
    owner = "elsaland";
    repo = "elsa";
    rev = revision;
    sha256 = "0ny2fsj7r05711d7k3xpl35k4pz86y2vnrk4bqqrdb5xqlh1i7aq";
  };

  doCheck = false;

  vendorSha256 = "1n3yj3p5nikbr5fwk44rpjk3wvay015k0gvl6pwdyx0yvpazrl4p";

  subPackages = [ "." ];

  meta = with stdenv.lib; {
    maintainer = with maintainers; [ ];
    license = licenses.mit;
    description = "Elsa is a minimal, fast and secure runtime for Javascript and Typescript written in Go";
  };
}

Running the nix-build command I get:

@nix { "action": "setPhase", "phase": "unpackPhase" } unpacking sources unpacking source archive /nix/store/a5bg5xqns8lzal9a6f04sdc9d1pr1vjp-source source root is source @nix { "action": "setPhase", "phase": "patchPhase" } patching sources @nix { "action": "setPhase", "phase": "configurePhase" } configuring @nix { "action": "setPhase", "phase": "buildPhase" } building 2020/09/30 08:10:43 Bundling 00_core.js 2020/09/30 08:10:43 Bundling 01_namespace.js 2020/09/30 08:10:43 Bundling 02_console.js 2020/09/30 08:10:43 Bundling 03_fetch.js 2020/09/30 08:10:43 Bundling 04_event.js 2020/09/30 08:10:43 Bundling 05_compiler.js 2020/09/30 08:10:43 Bundling 10_window.js 2020/09/30 08:10:43 Running command and waiting for it to finish... 2020/09/30 08:10:43 Command finished with error: exit status 1 Building subPackage ./. github.com/asaskevich/govalidator github.com/go-bindata/go-bindata github.com/elsaland/elsa/packager github.com/spf13/pflag github.com/spf13/cobra github.com/elsaland/elsa/cmd github.com/elsaland/quickjs github.com/imroc/req github.com/spf13/afero/mem golang.org/x/text/transform golang.org/x/text/unicode/norm github.com/spf13/afero github.com/elsaland/elsa/core/ops golang.org/x/sys/internal/unsafeheader golang.org/x/sys/unix github.com/mattn/go-isatty github.com/mattn/go-colorable github.com/fatih/color github.com/logrusorgru/aurora github.com/elsaland/elsa/core # github.com/elsaland/elsa/core core/run.go:37:13: undefined: Asset github.com/evanw/esbuild/internal/compat github.com/evanw/esbuild/internal/logger github.com/evanw/esbuild/internal/js_ast github.com/evanw/esbuild/internal/config github.com/evanw/esbuild/internal/fs github.com/evanw/esbuild/internal/js_lexer github.com/evanw/esbuild/internal/renamer github.com/evanw/esbuild/internal/runtime github.com/evanw/esbuild/internal/sourcemap github.com/evanw/esbuild/internal/js_parser github.com/evanw/esbuild/internal/js_printer github.com/evanw/esbuild/internal/resolver github.com/evanw/esbuild/internal/bundler github.com/evanw/esbuild/pkg/api

573 avatar Sep 30 '20 08:09 573

@573 you need to run the bootstrap first.

go run ./bootstrap/

littledivy avatar Sep 30 '20 08:09 littledivy

With

# default.nix
{ stdenv, fetchFromGitHub, buildGoModule, go, go-bindata, go-bindata-assetfs }:

buildGoModule rec {
  pname = "elsa";
  version = "master";
  revision = "0375d76d2c802b497cec44e5069920643287cc98";
  goPackagePath = "github.com/elsaland/elsa";

  nativeBuildInputs = [ go go-bindata go-bindata-assetfs ];

  buildPhase = ''
    runHook preBuild
    # use make instead of go build
    runHook postBuild
    '';

  installPhase = ''
    runHook preInstall
    make build
    runHook postInstall
  '';

  src = fetchFromGitHub {
    owner = "elsaland";
    repo = "elsa";
    rev = revision;
    sha256 = "0ny2fsj7r05711d7k3xpl35k4pz86y2vnrk4bqqrdb5xqlh1i7aq";
  };

  doCheck = false;

  vendorSha256 = "1n3yj3p5nikbr5fwk44rpjk3wvay015k0gvl6pwdyx0yvpazrl4p";

  subPackages = [ "." ];

  meta = with stdenv.lib; {
    maintainer = with maintainers; [ ];
    license = licenses.mit;
    description = "Elsa is a minimal, fast and secure runtime for Javascript and Typescript written in Go";
  };
}

(go run ./bootstrap according to Makefile) I (still) get:

@nix { "action": "setPhase", "phase": "unpackPhase" } unpacking sources unpacking source archive /nix/store/a5bg5xqns8lzal9a6f04sdc9d1pr1vjp-source source root is source @nix { "action": "setPhase", "phase": "patchPhase" } patching sources @nix { "action": "setPhase", "phase": "configurePhase" } configuring @nix { "action": "setPhase", "phase": "buildPhase" } building @nix { "action": "setPhase", "phase": "installPhase" } installing go run ./bootstrap 2020/09/30 08:37:51 Bundling 00_core.js 2020/09/30 08:37:51 Bundling 01_namespace.js 2020/09/30 08:37:51 Bundling 02_console.js 2020/09/30 08:37:51 Bundling 03_fetch.js 2020/09/30 08:37:51 Bundling 04_event.js 2020/09/30 08:37:51 Bundling 05_compiler.js 2020/09/30 08:37:51 Bundling 10_window.js 2020/09/30 08:37:51 Running command and waiting for it to finish... 2020/09/30 08:37:51 Command finished with error: exit status 1 go build -o elsa . # github.com/elsaland/elsa/core core/run.go:37:13: undefined: Asset make: *** [Makefile:3: build] Error 2

573 avatar Sep 30 '20 08:09 573

Hmm looks like it is not perisisting the assets.go created by bootstrap at building. Can you try building on NixOS manually (make build) ?

I don't have much insight into how Nix works but I think building Elsa should be possible.

littledivy avatar Sep 30 '20 08:09 littledivy

@littledivy is it related to the 2020/09/30 08:37:51 Command finished with error: exit status 1 line maybe ?

EDIT: I added a find command to have assets.go's location printed directly after go run ./bootstrap:

{ stdenv, fetchFromGitHub, buildGoModule, go, go-bindata, go-bindata-assetfs, go2nix }:

buildGoModule rec {
  pname = "elsa";
  version = "master";
  revision = "0375d76d2c802b497cec44e5069920643287cc98";
  goPackagePath = "github.com/elsaland/elsa";

  nativeBuildInputs = [ go go-bindata go-bindata-assetfs go2nix ];

  buildPhase = ''
    runHook preBuild
    # run go run ./bootstrap manually
    go run ./bootstrap
    find . -path '*target' -print
    find . -path '*assets.go' -print
    # use make instead of go build
    runHook postBuild
    '';

  installPhase = ''
    runHook preInstall
    make
    runHook postInstall
  '';

  src = fetchFromGitHub {
    owner = "elsaland";
    repo = "elsa";
    rev = revision;
    sha256 = "0ny2fsj7r05711d7k3xpl35k4pz86y2vnrk4bqqrdb5xqlh1i7aq";
  };

  doCheck = false;

  vendorSha256 = "1n3yj3p5nikbr5fwk44rpjk3wvay015k0gvl6pwdyx0yvpazrl4p";

  subPackages = [ "." ];

  meta = with stdenv.lib; {
    maintainer = with maintainers; [ ];
    license = licenses.mit;
    description = "Elsa is a minimal, fast and secure runtime for Javascript and Typescript written in Go";
  };
}

Still no assets.go.

573 avatar Sep 30 '20 09:09 573

@573 I might've figured out the issue. Can you mkdir target. I think the bootstrap fails as it cannot create the path by itself.

littledivy avatar Sep 30 '20 11:09 littledivy

@littledivy when I add find . -path '*target' -print to the build clauses as in the edited comment above, I get:

these derivations will be built: /nix/store/2bdw9cjkb89r51bkwqdanc9zzvngqlcp-elsa-master.drv building '/nix/store/2bdw9cjkb89r51bkwqdanc9zzvngqlcp-elsa-master.drv'... unpacking sources unpacking source archive /nix/store/a5bg5xqns8lzal9a6f04sdc9d1pr1vjp-source source root is source patching sources configuring building 2020/09/30 11:56:16 Bundling 00_core.js 2020/09/30 11:56:16 Bundling 01_namespace.js 2020/09/30 11:56:16 Bundling 02_console.js 2020/09/30 11:56:16 Bundling 03_fetch.js 2020/09/30 11:56:16 Bundling 04_event.js 2020/09/30 11:56:16 Bundling 05_compiler.js 2020/09/30 11:56:16 Bundling 10_window.js 2020/09/30 11:56:16 Running command and waiting for it to finish... 2020/09/30 11:56:16 Command finished with error: exit status 1 ./target ...

the target folder seems to be there already.

573 avatar Sep 30 '20 11:09 573

Alright, another reason could be go-bindata not being avaliable in your $GOSRC go get github.com/go-bindata/go-bindata

PS: it needs to be retrieved via go get

littledivy avatar Sep 30 '20 13:09 littledivy