Derivation for linx-server - need help

I would like to build the following software for Nixos:

Therefore I have written the following derivation:

{ stdenv, buildGoPackage, fetchFromGitHub }:

buildGoPackage rec {
  pname = "linx-server";
  version = "v2.1.6";

  goPackagePath = "github.com/andreimarcu/linx-server";

  src = fetchFromGitHub {
    owner = "andreimarcu";
    repo = "linx-server";
    rev = version;
    sha256 = "1ykgb6f3si5a9ib0zmwh7n8higa52g63qcizmh7x19b1fsh8wanz";
  };

  goDeps = ./deps.nix;

  meta = with stdenv.lib; {
    homepage = "https://github.com/andreimarcu/linx-server";
    description = "Self-hosted file/code/media sharing website";
    maintainers = with maintainers; [ foxit64 ];
    platforms = platforms.unix;
    license = licenses.gpl3;
  };
}

The compiling works and I also have a binary that works but unfortunately something is not ok. I cannot start the tool:

~/nix/linx: cp result-bin/bin/linx-server tmp/
~/nix/linx: tmp/linx-server
2020/01/31 08:44:40 Error: could not load templatescould not locate box "templates"

strace shows me this:

6218  newfstatat(AT_FDCWD, "files/",  <unfinished ...>
6217  <... nanosleep resumed>NULL)      = 0
6218  <... newfstatat resumed>{st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
6217  rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1],  <unfinished ...>
6218  newfstatat(AT_FDCWD, "meta/",  <unfinished ...>
6217  <... rt_sigprocmask resumed>[], 8) = 0
6218  <... newfstatat resumed>{st_mode=S_IFDIR|0700, st_size=4096, ...}, 0) = 0
6217  mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7faad9ffc000
6218  newfstatat(AT_FDCWD, "/build/go/src/github.com/andreimarcu/linx-server/templates",  <unfinished ...>
6217  mprotect(0x7faad9ffd000, 8388608, PROT_READ|PROT_WRITE <unfinished ...>
6218  <... newfstatat resumed>0xc000378b98, 0) = -1 ENOENT (No such file or directory)
6217  <... mprotect resumed>)           = 0
6218  write(2, "2020/01/31 08:04:33 Error: could not load templatescould not locate box \"templates\"\n", 84 <unfinished ...>
6217  clone(child_stack=0x7faada7fbfb0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID <unfinished ...>
6218  <... write resumed>)              = 84
6218  exit_group(1 <unfinished ...>

Interesting:

6218  newfstatat(AT_FDCWD, "/build/go/src/github.com/andreimarcu/linx-server/templates",  <unfinished ...>

If I create the folder “/build” on the root-fs “/”, I get a different error message. This means that the paths were somehow not set correctly during compilation?

Unfortunately, I don’t have much experience with Nix and Go. Therefore I would be very grateful for help.

Another attempt, but it did not work either:

{ stdenv, buildGoPackage, fetchFromGitHub }:

buildGoPackage rec {
  pname = "linx-server";
  version = "v2.1.6";

  goPackagePath = "github.com/andreimarcu/linx-server";

  src = fetchFromGitHub {
    owner = "andreimarcu";
    repo = "linx-server";
    rev = version;
    sha256 = "1ykgb6f3si5a9ib0zmwh7n8higa52g63qcizmh7x19b1fsh8wanz";
  };

  goDeps = ./deps.nix;

  buildPhase = ''
    cd "go/src/$goPackagePath"
    patchShebangs build.sh
    GOOS=linux GOARCH=amd64 go build -o linx-server
  '';

  installPhase = ''
    install -Dm755 linx-server $bin/bin/linx-server
  '';

  meta = with stdenv.lib; {
    homepage = "https://github.com/andreimarcu/linx-server";
    description = "Self-hosted file/code/media sharing website";
    maintainers = with maintainers; [ foxit64 ];
    platforms = platforms.unix;
    license = licenses.gpl3;
  };
}

Thanks a lot

I don’t know this application, but it seems that should only be loaded from the filesystem during development and you are supposed to add templates/assets into the binary:

So, I guess the best approach to try is to embed the templates with rice.

I can install the command “rice” via “go get github.com/GeertJohan/go.rice/rice”. How can I add this to the build process?

  buildInputs = [ git go ];

  buildPhase = ''
    go get github.com/GeertJohan/go.rice/rice
  '';
building
# cd .; git clone https://github.com/GeertJohan/go.incremental /build/go/src/github.com/GeertJohan/go.incremental
Cloning into '/build/go/src/github.com/GeertJohan/go.incremental'...
fatal: unable to access 'https://github.com/GeertJohan/go.incremental/': Could not resolve host: github.com
package github.com/GeertJohan/go.incremental: exit status 128
# cd .; git clone https://github.com/akavel/rsrc /build/go/src/github.com/akavel/rsrc
Cloning into '/build/go/src/github.com/akavel/rsrc'...
fatal: unable to access 'https://github.com/akavel/rsrc/': Could not resolve host: github.com
package github.com/akavel/rsrc/binutil: exit status 128
package github.com/akavel/rsrc/coff: cannot find package "github.com/akavel/rsrc/coff" in any of:
        /nix/store/31cgv17wfsn0wkmlvzw62kylyfapfq71-go-1.12.9/share/go/src/github.com/akavel/rsrc/coff (from $GOROOT)
        /build/go/src/github.com/akavel/rsrc/coff (from $GOPATH)
# cd .; git clone https://github.com/jessevdk/go-flags /build/go/src/github.com/jessevdk/go-flags
Cloning into '/build/go/src/github.com/jessevdk/go-flags'...
fatal: unable to access 'https://github.com/jessevdk/go-flags/': Could not resolve host: github.com
package github.com/jessevdk/go-flags: exit status 128
# cd .; git clone https://github.com/nkovacs/streamquote /build/go/src/github.com/nkovacs/streamquote

I’m afraid that’s not gonna work.

Thanks