Created
August 5, 2021 00:29
-
-
Save DavidRConnell/c72038841052e576c38a9347a1666883 to your computer and use it in GitHub Desktop.
Neo4j flake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
inputs = { | |
nixpkgs.url = "github:nixos/nixpkgs"; | |
flake-utils.url = "github:numtide/flake-utils"; | |
}; | |
outputs = { self, nixpkgs, flake-utils }: | |
flake-utils.lib.eachDefaultSystem (system: | |
let | |
pkgs = nixpkgs.legacyPackages.${system}; | |
jre = pkgs.openjdk11; | |
varHome = "/var/lib/neo4j"; | |
neo4j = (pkgs.stdenv.mkDerivation rec { | |
pname = "neo4j"; | |
version = "4.3.2"; | |
src = pkgs.fetchurl { | |
url = | |
"https://neo4j.com/artifact.php?name=neo4j-community-${version}-unix.tar.gz"; | |
sha256 = | |
"3474f3ec9da57fb627af71652ae6ecbd036e6ea689379f09e77e4cd8ba4b5515"; | |
}; | |
nativeBuildInputs = [ pkgs.makeWrapper pkgs.bashInteractive ]; | |
installPhase = '' | |
runHook preInstall | |
mkdir -p "$out/share/neo4j" | |
cp -R * "$out/share/neo4j" | |
compgen_wrapper="$out/share/neo4j/bin/compgen" | |
cat << _EOF_ > $compgen_wrapper | |
"${pkgs.bashInteractive}/bin/bash" -c 'compgen "\$@"' | |
_EOF_ | |
chmod +x $compgen_wrapper | |
mkdir -p "$out/bin" | |
for NEO4J_SCRIPT in neo4j neo4j-admin cypher-shell; do | |
makeWrapper "$out/share/neo4j/bin/$NEO4J_SCRIPT" \ | |
"$out/bin/$NEO4J_SCRIPT" \ | |
--prefix PATH : "${ | |
pkgs.lib.makeBinPath [ jre pkgs.which pkgs.gawk ] | |
}:$out/share/neo4j/bin/" \ | |
--set JAVA_HOME "${jre}" | |
done | |
rm -rf $out/share/neo4j/{run,logs,data} | |
for var_dir in run logs data; do | |
substituteInPlace "$out/share/neo4j/conf/neo4j.conf" \ | |
--replace "#dbms.directories.$var_dir=$var_dir" \ | |
"dbms.directories.$var_dir=${varHome}/$var_dir" | |
done | |
substituteInPlace "$out/share/neo4j/conf/neo4j.conf" \ | |
--replace '#dbms.security.auth_enabled=false' 'dbms.security.auth_enabled=false' | |
runHook postInstall | |
''; | |
meta = with pkgs.lib; { | |
description = | |
"A highly scalable, robust (fully ACID) native graph database"; | |
homepage = "http://www.neo4j.org/"; | |
license = licenses.gpl3Only; | |
maintainers = [ maintainers.offline ]; | |
platforms = pkgs.lib.platforms.unix; | |
}; | |
}); | |
in { | |
packages.neo4j = neo4j; | |
defaultPackage = self.packages.${system}.neo4j; | |
systemd.services.neo4j = { | |
description = "Neo4j Daemon"; | |
wantedBy = [ "multi-user.target" ]; | |
after = [ "network.target" ]; | |
serviceConfig = { | |
ExecStart = "${self.packages.neo4j}/bin/neo4j start"; | |
User = "neo4j"; | |
PermissionsStartOnly = true; | |
LimitNOFILE = 40000; | |
}; | |
preStart = '' | |
mkdir -m 0700 -p ${varHome}/{conf,logs,run} | |
chown -R neo4j ${varHome} | |
''; | |
users.users.neo4j = { | |
uid = pkgs.config.ids.uids.neo4j; | |
description = "Neo4j daemon user"; | |
home = varHome; | |
}; | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment