From 1fe37caf7477cbfc5592212d8a73d636acb4f0a4 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 20 Feb 2023 23:58:44 +0200 Subject: [PATCH] initial commit --- flake.nix | 26 ++++++++++++++ openhab-repository.nix | 25 ++++++++++++++ openhab-repository.sha256 | 1 + openhab.nix | 71 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 flake.nix create mode 100644 openhab-repository.nix create mode 100644 openhab-repository.sha256 create mode 100644 openhab.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7fa0842 --- /dev/null +++ b/flake.nix @@ -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; + }; + }); +} diff --git a/openhab-repository.nix b/openhab-repository.nix new file mode 100644 index 0000000..b1f2cb9 --- /dev/null +++ b/openhab-repository.nix @@ -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; +} diff --git a/openhab-repository.sha256 b/openhab-repository.sha256 new file mode 100644 index 0000000..b9c1128 --- /dev/null +++ b/openhab-repository.sha256 @@ -0,0 +1 @@ +sha256-po8EjHV8lPUOxkuOnZ5mQOODg+LAhgazfx7wW6Modqc= diff --git a/openhab.nix b/openhab.nix new file mode 100644 index 0000000..88f00e5 --- /dev/null +++ b/openhab.nix @@ -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 + ''; +}