initial commit

This commit is contained in:
Simonas Kazlauskas
2023-02-20 23:58:44 +02:00
commit 1fe37caf74
4 changed files with 123 additions and 0 deletions

26
flake.nix Normal file
View File

@@ -0,0 +1,26 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
openhab-distro = {
url = "github:openhab/openhab-distro";
flake = false;
};
};
outputs = { flake-utils, nixpkgs, openhab-distro, ... }: flake-utils.lib.eachDefaultSystem (system: {
packages = rec {
jdk-openhab = nixpkgs.legacyPackages.${system}.jdk11;
maven-openhab = nixpkgs.legacyPackages.${system}.maven.override { jdk = jdk-openhab; };
openhab-repository = nixpkgs.legacyPackages.${system}.callPackage ./openhab-repository.nix {
inherit openhab-distro;
maven = maven-openhab;
};
openhab = nixpkgs.legacyPackages.${system}.callPackage ./openhab.nix {
inherit openhab-distro openhab-repository jdk-openhab;
maven = maven-openhab;
};
default = openhab;
};
});
}

25
openhab-repository.nix Normal file
View File

@@ -0,0 +1,25 @@
# Downloads various dependencies for the openhab build.
{ lib, stdenv, maven, openhab-distro }:
stdenv.mkDerivation {
pname = "openhab-repository";
version = openhab-distro.shortRev;
nativeBuildInputs = [ maven ];
src = openhab-distro;
buildPhase = ''
mvn -B -T 128 -Drelease -Dmaven.repo.local="$out" package
'';
installPhase = ''
# Delete all ephemeral files with lastModified timestamps inside
find "$out" -type f '(' \
-name '*.lastUpdated' -or \
-name 'resolver-status.properties' -or \
-name '_remote.repositories' ')' -delete
'';
dontFixup = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = builtins.readFile ./openhab-repository.sha256;
}

View File

@@ -0,0 +1 @@
sha256-po8EjHV8lPUOxkuOnZ5mQOODg+LAhgazfx7wW6Modqc=

71
openhab.nix Normal file
View File

@@ -0,0 +1,71 @@
{
gawk,
bash,
coreutils,
jdk-openhab,
makeWrapper,
lib,
maven,
openhab-distro,
openhab-repository,
stdenv,
}:
stdenv.mkDerivation rec {
pname = "openhab";
version = openhab-distro.shortRev;
src = openhab-distro;
nativeBuildInputs = [ makeWrapper maven ];
buildInputs = [ bash ];
outputs = [ "out" "demo" ];
extraPath = lib.makeBinPath [ jdk-openhab gawk coreutils ];
wrappedExecutables = [
"start.sh"
"start_debug.sh"
"runtime/bin/karaf"
"runtime/bin/backup"
"runtime/bin/client"
"runtime/bin/instance"
"runtime/bin/karaf"
"runtime/bin/restore"
"runtime/bin/shell"
"runtime/bin/start"
"runtime/bin/status"
"runtime/bin/stop"
"runtime/bin/update"
];
buildPhase = ''
runHook preBuild
echo "Using repository ${openhab-repository}"
cp -r ${openhab-repository} ./repository
chmod -R +rw ./repository
mvn --offline -B -T $NIX_BUILD_CORES -Drelease -Dmaven.repo.local=./repository package
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir $out
tar -C $out -xf distributions/openhab/target/openhab-3.4.2.tar.gz
mv distributions/openhab-addons/target/openhab-addons-3.4.2.kar $out/addons/
mkdir $demo
tar -C $demo -xf distributions/openhab-demo/target/openhab-demo-3.4.2.tar.gz
rm -rfv \
"$out/"*.bat \
"$out/runtime/bin/"*.bat \
"$out/runtime/bin/"*.ps1 \
"$out/runtime/bin/"*.psm1 \
"$out/runtime/bin/"*.lst
for exe in $wrappedExecutables; do
echo "Wrapping $exe"
wrapProgram $out/$exe --prefix PATH ':' $extraPath
done
runHook postInstall
'';
}