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

Feature request: Add nix build #47

Open
573 opened this issue Sep 30, 2020 · 7 comments
Open

Feature request: Add nix build #47

573 opened this issue Sep 30, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@573
Copy link

573 commented Sep 30, 2020

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

@littledivy
Copy link
Collaborator

@573 you need to run the bootstrap first.

go run ./bootstrap/

@573
Copy link
Author

573 commented Sep 30, 2020

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

@littledivy
Copy link
Collaborator

littledivy commented Sep 30, 2020

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.

@573
Copy link
Author

573 commented Sep 30, 2020

@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.

@littledivy
Copy link
Collaborator

@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 littledivy added the bug Something isn't working label Sep 30, 2020
@573
Copy link
Author

573 commented Sep 30, 2020

@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.

@littledivy
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants