nix: add default.nix and envrc/shell.nix

This commit is contained in:
Tony Olagbaiye 2020-04-20 05:51:06 +01:00
parent 69f4c2b224
commit 650ac68669
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910
3 changed files with 122 additions and 0 deletions

8
.envrc Normal file
View File

@ -0,0 +1,8 @@
if type lorri &>/dev/null; then
echo "direnv: using lorri from PATH ($(type -p lorri))"
eval "$(lorri direnv)"
else
# fall back to using direnv's builtin nix support
# to prevent bootstrapping problems.
use nix
fi

79
default.nix Normal file
View File

@ -0,0 +1,79 @@
{ rev ? "c7e0e9ed5abd0043e50ee371129fcb8640264fc4"
, sha256 ? "0c28mpvjhjc8kiwj2w8zcjsr2rayw989a1wnsqda71zpcyas3mq2"
, pkgs ? import (builtins.fetchTarball { inherit sha256;
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
}) { }
, stdenv ? if useClang
then (if pkgs.stdenv.cc.isClang
then pkgs.stdenv
else pkgs.llvmPackages_latest.stdenv)
else (if pkgs.stdenv.cc.isGNU
then pkgs.stdenv
else pkgs.gcc.stdenv)
, lib ? pkgs.lib
, debug ? false # Debug Build
, useClang ? false # Use Clang over GCC
, useJemalloc ? true # Use the Dynamic Memory Allocator
, withGraphicsMagick ? true # Allow Media Thumbnails
}:
stdenv.mkDerivation rec {
pname = "matrix-construct";
version = "development";
src = lib.cleanSource ./.;
preAutoreconf = let
VERSION_COMMIT_CMD = "git rev-parse --short HEAD";
VERSION_BRANCH_CMD = "git rev-parse --abbrev-ref HEAD";
VERSION_TAG_CMD = "git describe --tags --abbrev=0 --dirty --always";
VERSION_CMD = "git describe --tags --always";
runWithGit = id: cmd: lib.removeSuffix "\n" (builtins.readFile (pkgs.runCommandNoCCLocal "construct-${id}" {
buildInputs = [ pkgs.git ];
} "cd ${./.} && ${cmd} > $out"));
in ''
substituteInPlace configure.ac --replace "${VERSION_COMMIT_CMD}" "echo ${runWithGit "version-commit" VERSION_COMMIT_CMD}"
substituteInPlace configure.ac --replace "${VERSION_BRANCH_CMD}" "echo ${runWithGit "version-branch" VERSION_BRANCH_CMD}"
substituteInPlace configure.ac --replace "${VERSION_TAG_CMD}" "echo ${runWithGit "version-tag" VERSION_TAG_CMD}"
substituteInPlace configure.ac --replace "${VERSION_CMD}" "echo ${runWithGit "version" VERSION_CMD}"
'';
configureFlags = [
"--enable-generic"
"--with-custom-branding=nix"
"--with-custom-version=dev"
"--with-boost-libdir=${pkgs.boost.out}/lib"
"--with-boost=${pkgs.boost.dev}"
"--with-magic-file=${pkgs.file}/share/misc/magic.mgc"
] ++ lib.optional useJemalloc "--enable-jemalloc"
++ lib.optional withGraphicsMagick [
"--with-imagemagick-includes=${pkgs.graphicsmagick}/include/GraphicsMagick"
] ++ lib.optional debug "--with-log-level=DEBUG";
preBuild = ''
make clean
'';
enableParallelBuilding = true;
nativeBuildInputs = with pkgs; [
autoreconfHook pkg-config
] ++ lib.optional useClang llvmPackages_latest.llvm
++ lib.optional useJemalloc jemalloc;
buildInputs = with pkgs; [
libsodium openssl file boost gmp
(rocksdb.overrideAttrs (super: rec {
version = "5.16.6";
src = pkgs.fetchFromGitHub {
owner = "facebook";
repo = "rocksdb";
rev = "v${version}";
sha256 = "0yy09myzbi99qdmh2c2mxlddr12pwxzh66ym1y6raaqglrsmax66";
};
cmakeFlags = builtins.map (f: if f == "-DWITH_TOOLS=0" then "-DWITH_TOOLS=1" else f) super.cmakeFlags;
NIX_CFLAGS_COMPILE = "${super.NIX_CFLAGS_COMPILE} -Wno-error=redundant-move";
}))
] ++ lib.optional withGraphicsMagick graphicsmagick;
}

35
shell.nix Normal file
View File

@ -0,0 +1,35 @@
{ pkgs ? import <nixpkgs> { } }:
let
package = pkgs.callPackage ./. {};
in pkgs.mkShell {
buildInputs = with pkgs; [
libsodium openssl file boost gmp llvm
(rocksdb.overrideAttrs (super: rec {
version = "5.16.6";
src = pkgs.fetchFromGitHub {
owner = "facebook";
repo = "rocksdb";
rev = "v${version}";
sha256 = "0yy09myzbi99qdmh2c2mxlddr12pwxzh66ym1y6raaqglrsmax66";
};
NIX_CFLAGS_COMPILE = "${super.NIX_CFLAGS_COMPILE} -Wno-error=redundant-move";
}))
zlib lz4 snappy
graphicsmagick
jemalloc
];
nativeBuildInputs = with pkgs; [ git autoconf automake libtool gcc clang cmake pkg-config ];
shellHook = ''
WORKDIR=$(mktemp -d)
export RUNTIME_DIRECTORY=$WORKDIR/runtime
export STATE_DIRECTORY=$WORKDIR/state
export CACHE_DIRECTORY=$WORKDIR/cache
export LOGS_DIRECTORY=$WORKDIR/logs
export CONFIGURATION_DIRECTORY=$WORKDIR/configuration
mkdir -p $RUNTIME_DIRECTORY $STATE_DIRECTORY $LOGS_DIRECTORY
mkdir -p $CACHE_DIRECTORY $CONFIGURATION_DIRECTORY
'';
}