Ok, I’m stuck!
Here’s as far as I’v got. This overlay is based on recent(ish) vlang/v
commits that I know to be “good” (I can compile via cloned source and make
, but ultimately get the same issues with openssl
that you’ll see at the end of this post)…
self: super: {
vlang = super.stdenv.mkDerivation rec {
pname = "vlang";
version = "0.1.25-imj";
###src = /home/ian/Projects/v;
src = super.fetchFromGitHub {
owner = "vlang";
repo = "v";
rev = "522de0871a6ad87c1e9da2c9ac771e0984b83528";
sha256 = "090q1gd8nyrx9wzimibxz7znqavn14637h4zx4pinx1cbvd96091";
};
vc = super.fetchFromGitHub {
owner = "vlang";
repo = "vc";
rev = "f5207d7ce2e1daf482420d32f4b656fed73b999b";
sha256 = "06y4xy36z4fy647jayliyqi0dwvjr1q9ajshb8mz5yqw9mdmdw9m";
};
propagatedBuildInputs = [ self.glfw self.freetype self.openssl ];
buildPhase = ''
runHook preBuild
echo "Using cc to build v.c..."
cc $CFLAGS -std=gnu11 -w -o v2 $vc/v.c $LDFLAGS -lm
echo "Using vc to build v..."
./v2 -o v3 cmd/v
echo "Using v to build v (prod)..."
./v3 -o v -prod cmd/v
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,lib,share}
cp -r examples $out/share
cp -r {vlib,thirdparty} $out/lib
cp v $out/lib
ln -s $out/lib/v $out/bin/v
runHook postInstall
'';
};
}
$vc
is the C source that V produces when something is changed in the core compiler, it’s what can be used to build the v
compiler when v
isn’t already available. The v
compiler is effectively a v
=> c
=> binary
machine.
So, v.c
is used to compile v2
, a “true” v
. Then in this overlay, we use v2
to compile a v3
, i.e. v
self compile, then v3
to v
itself in a production mode (as a good test and final small binary).
This ultimately produces this output…
unpacking source archive /build/522de0871a6ad87c1e9da2c9ac771e0984b83528.tar.gz
building '/nix/store/4mpdwkvl9fsbi2sp2wwqbf33ayjvsm5l-vlang-0.1.25-imj.drv'...
unpacking sources
unpacking source archive /nix/store/xibzz443kyjacl759lxn2d2f5vflx217-source
source root is source
patching sources
configuring
no configure script, doing nothing
building
Using cc to build v.c...
Using vc to build v...
V panic: No such file or directory
builder for '/nix/store/4mpdwkvl9fsbi2sp2wwqbf33ayjvsm5l-vlang-0.1.25-imj.drv' failed with exit code 1
cannot build derivation '/nix/store/kz6m6gqfxyfahysc5ka212m8g2k2m83l-system-path.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/v2jkcf6n4wjaas6b622080q55cg6za7v-nixos-system-ians-apollo-20.03pre211190.a21c2fa3ea2.drv': 1 dependencies couldn't be built
error: build of '/nix/store/v2jkcf6n4wjaas6b622080q55cg6za7v-nixos-system-ians-apollo-20.03pre211190.a21c2fa3ea2.drv' failed
Something is not happy in the v
compiler, it can’t find some file, I’m presuming this is due to the way NixOS works when building a derivation in sandbox mode (because I want this to also work on Hydra if converted to a PR for the package).
If I instead reduce the build phase to …
buildPhase = ''
runHook preBuild
echo "Using cc to build v.c..."
cc $CFLAGS -std=gnu11 -w -o v $vc/v.c $LDFLAGS -lm
runHook postBuild
'';
… i.e. just use the C compiler to produce v
, then the overlay works.
However, this for some reason does not “propagate” the libraries, e.g. this is what I get when trying to run one of the examples that relies on the openssl
lib…
ian@ians-apollo:~/Projects/v/examples/vweb/vweb_assets (master) $ which v
/run/current-system/sw/bin/v
ian@ians-apollo:~/Projects/v/examples/vweb/vweb_assets (master) $ v run .
warning: /nix/store/yhisgrsfls9i5scfqn0w9f33pc8gxqnl-vlang-0.1.25-imj/lib/vlib/vweb/assets/assets.v:197:3: `am` is declared as mutable, but it was never changed
==================
/home/ian/.cache/v/vweb_assets.tmp.c:423:10: fatal error: openssl/ssl.h: No such file or directory
423 | #include <openssl/ssl.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
...
==================
(Use `v -cg` to print the entire error message)
V error: C error.
Please make sure that:
- You have all V dependencies installed.
- You did not declare a C function that was not included. (Try commenting your code that involves C interop)
- You are running the latest version of V. (Try running `v up` and rerunning your command)
If you're confident that all of the above is true, please try running V with the `-cg` option which enables more debugging capabilities.
ian@ians-apollo:~/Projects/v/examples/vweb/vweb_assets (master) $ nix-shell -p openssl
these paths will be fetched (0.05 MiB download, 0.28 MiB unpacked):
/nix/store/h3iim69ysaha4v7lgk6s26i57vmwffaw-bash-interactive-4.4-p23-dev
copying path '/nix/store/h3iim69ysaha4v7lgk6s26i57vmwffaw-bash-interactive-4.4-p23-dev' from 'https://cache.nixos.org'...
[nix-shell:~/Projects/v/examples/vweb/vweb_assets]$ v run .
warning: /nix/store/yhisgrsfls9i5scfqn0w9f33pc8gxqnl-vlang-0.1.25-imj/lib/vlib/vweb/assets/assets.v:197:3: `am` is declared as mutable, but it was never changed
Running a Vweb app on http://localhost:8081 ...
So that’s a lot of information there, sorry!
But maybe someone can see the errors in my ways?
I’d be super happy if we could just get the v.c
compiled version to work properly with propagatedBuildInputs
, that would be a major win!