Skip to content

Commit 650ac68

Browse files
committed
nix: add default.nix and envrc/shell.nix
1 parent 69f4c2b commit 650ac68

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

.envrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if type lorri &>/dev/null; then
2+
echo "direnv: using lorri from PATH ($(type -p lorri))"
3+
eval "$(lorri direnv)"
4+
else
5+
# fall back to using direnv's builtin nix support
6+
# to prevent bootstrapping problems.
7+
use nix
8+
fi

default.nix

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{ rev ? "c7e0e9ed5abd0043e50ee371129fcb8640264fc4"
2+
, sha256 ? "0c28mpvjhjc8kiwj2w8zcjsr2rayw989a1wnsqda71zpcyas3mq2"
3+
, pkgs ? import (builtins.fetchTarball { inherit sha256;
4+
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
5+
}) { }
6+
7+
, stdenv ? if useClang
8+
then (if pkgs.stdenv.cc.isClang
9+
then pkgs.stdenv
10+
else pkgs.llvmPackages_latest.stdenv)
11+
else (if pkgs.stdenv.cc.isGNU
12+
then pkgs.stdenv
13+
else pkgs.gcc.stdenv)
14+
, lib ? pkgs.lib
15+
16+
, debug ? false # Debug Build
17+
, useClang ? false # Use Clang over GCC
18+
, useJemalloc ? true # Use the Dynamic Memory Allocator
19+
, withGraphicsMagick ? true # Allow Media Thumbnails
20+
}:
21+
22+
stdenv.mkDerivation rec {
23+
pname = "matrix-construct";
24+
version = "development";
25+
26+
src = lib.cleanSource ./.;
27+
28+
preAutoreconf = let
29+
VERSION_COMMIT_CMD = "git rev-parse --short HEAD";
30+
VERSION_BRANCH_CMD = "git rev-parse --abbrev-ref HEAD";
31+
VERSION_TAG_CMD = "git describe --tags --abbrev=0 --dirty --always";
32+
VERSION_CMD = "git describe --tags --always";
33+
runWithGit = id: cmd: lib.removeSuffix "\n" (builtins.readFile (pkgs.runCommandNoCCLocal "construct-${id}" {
34+
buildInputs = [ pkgs.git ];
35+
} "cd ${./.} && ${cmd} > $out"));
36+
in ''
37+
substituteInPlace configure.ac --replace "${VERSION_COMMIT_CMD}" "echo ${runWithGit "version-commit" VERSION_COMMIT_CMD}"
38+
substituteInPlace configure.ac --replace "${VERSION_BRANCH_CMD}" "echo ${runWithGit "version-branch" VERSION_BRANCH_CMD}"
39+
substituteInPlace configure.ac --replace "${VERSION_TAG_CMD}" "echo ${runWithGit "version-tag" VERSION_TAG_CMD}"
40+
substituteInPlace configure.ac --replace "${VERSION_CMD}" "echo ${runWithGit "version" VERSION_CMD}"
41+
'';
42+
43+
configureFlags = [
44+
"--enable-generic"
45+
"--with-custom-branding=nix"
46+
"--with-custom-version=dev"
47+
"--with-boost-libdir=${pkgs.boost.out}/lib"
48+
"--with-boost=${pkgs.boost.dev}"
49+
"--with-magic-file=${pkgs.file}/share/misc/magic.mgc"
50+
] ++ lib.optional useJemalloc "--enable-jemalloc"
51+
++ lib.optional withGraphicsMagick [
52+
"--with-imagemagick-includes=${pkgs.graphicsmagick}/include/GraphicsMagick"
53+
] ++ lib.optional debug "--with-log-level=DEBUG";
54+
55+
preBuild = ''
56+
make clean
57+
'';
58+
59+
enableParallelBuilding = true;
60+
61+
nativeBuildInputs = with pkgs; [
62+
autoreconfHook pkg-config
63+
] ++ lib.optional useClang llvmPackages_latest.llvm
64+
++ lib.optional useJemalloc jemalloc;
65+
buildInputs = with pkgs; [
66+
libsodium openssl file boost gmp
67+
(rocksdb.overrideAttrs (super: rec {
68+
version = "5.16.6";
69+
src = pkgs.fetchFromGitHub {
70+
owner = "facebook";
71+
repo = "rocksdb";
72+
rev = "v${version}";
73+
sha256 = "0yy09myzbi99qdmh2c2mxlddr12pwxzh66ym1y6raaqglrsmax66";
74+
};
75+
cmakeFlags = builtins.map (f: if f == "-DWITH_TOOLS=0" then "-DWITH_TOOLS=1" else f) super.cmakeFlags;
76+
NIX_CFLAGS_COMPILE = "${super.NIX_CFLAGS_COMPILE} -Wno-error=redundant-move";
77+
}))
78+
] ++ lib.optional withGraphicsMagick graphicsmagick;
79+
}

shell.nix

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{ pkgs ? import <nixpkgs> { } }:
2+
3+
let
4+
package = pkgs.callPackage ./. {};
5+
in pkgs.mkShell {
6+
buildInputs = with pkgs; [
7+
libsodium openssl file boost gmp llvm
8+
(rocksdb.overrideAttrs (super: rec {
9+
version = "5.16.6";
10+
src = pkgs.fetchFromGitHub {
11+
owner = "facebook";
12+
repo = "rocksdb";
13+
rev = "v${version}";
14+
sha256 = "0yy09myzbi99qdmh2c2mxlddr12pwxzh66ym1y6raaqglrsmax66";
15+
};
16+
NIX_CFLAGS_COMPILE = "${super.NIX_CFLAGS_COMPILE} -Wno-error=redundant-move";
17+
}))
18+
zlib lz4 snappy
19+
graphicsmagick
20+
jemalloc
21+
];
22+
nativeBuildInputs = with pkgs; [ git autoconf automake libtool gcc clang cmake pkg-config ];
23+
24+
shellHook = ''
25+
WORKDIR=$(mktemp -d)
26+
export RUNTIME_DIRECTORY=$WORKDIR/runtime
27+
export STATE_DIRECTORY=$WORKDIR/state
28+
export CACHE_DIRECTORY=$WORKDIR/cache
29+
export LOGS_DIRECTORY=$WORKDIR/logs
30+
export CONFIGURATION_DIRECTORY=$WORKDIR/configuration
31+
32+
mkdir -p $RUNTIME_DIRECTORY $STATE_DIRECTORY $LOGS_DIRECTORY
33+
mkdir -p $CACHE_DIRECTORY $CONFIGURATION_DIRECTORY
34+
'';
35+
}

0 commit comments

Comments
 (0)