NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.16k stars 14.19k forks source link

OpenHAB: packages and module #55364

Open colemickens opened 5 years ago

colemickens commented 5 years ago

Issue description

Hello,

openhab seems like an identical candidate for usage under NixOS. It would be great to see a package and module for it.

I might try to look at this soon but I'm not experienced with Java.

Steps to reproduce

Technical details

Please run nix-shell -p nix-info --run "nix-info -m" and paste the results.

hypersw commented 5 years ago

I've managed to put up a package which fetches the stable ZIP and patches AWK/Java/bash paths, then a module file which writes up a service config, and all this loads and runs but-- it wouldn't open any HTTP/HTTPS ports for listening, only the control port which it uses for shutting down or whatever. Based on the logs, it gets stuck on startlevel 100. Will be trying to dig this further. I attribute the trouble to the fact that native OpenHAB folder structure is a total mess of R/O, one-time-config, and full R/W userdata folders, so it won't run off the /nix/store/... path for sure; I've overridden the paths I felt relevant (to go under /var/lib, /var/log, and /run, but something isn't firing up, and it won't tell it right away.

dniku commented 4 years ago

@hypersw any progress on getting openhab to run? I'd love to see it working under NixOS :)

hypersw commented 4 years ago

Not really. I've reproduced the setup "locally" (not inside a service), but didn't get much further with that. My next thoughts were to contact the OpenHAB community for comments, because Apache Karaf and its peculiarities are a bit off what I'm usually dealing with. In the meantime I were a bit disappointed with OpenHAB UI and were exploring other suff, like making core automation over raw MQTT with some external UI. I think I should push this to some conclusion anyway.

hypersw commented 4 years ago

@dniku: well, this does not mean you cannot run OpenHAB on NixOS, this is just lacking a nice way of installing it along the NixOS lines, and backing up the settings. But if you bother to download the ZIP https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F2.4.0%2Fopenhab-2.4.0.zip and expand it and kick together a service like this...

{ config, lib, pkgs, ... }:
let
  username = "openhabsrvtry";
  pathTmpOpenhab = "/var/lib/try.openhab";
in
{
    imports = [ ];

    environment = with pkgs;
    {
      systemPackages =
      [
        mc
        jre
        gawk
        procps
      ];
    };

    users.users = lib.singleton
    {
        name = username;
        description = "OpenHAB Server User (Try)";
    };

    systemd.services.openhabtry =
    {
      description = "OpenHAB Server Try";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];   ## TODO: is it?

      environment =
      {
          JAVA_HOME = "${pkgs.jre}"; # where to look for java.exe
      };
      path = [ "${pkgs.gawk}/bin" "${pkgs.procps}/bin"];

      serviceConfig =
      {
        ExecStart  = "${pathTmpOpenhab}/runtime/bin/karaf server";
        ExecStop   = "${pathTmpOpenhab}/runtime/bin/karaf stop";

        Restart = "always";
        RestartSec = "10";
        TimeoutStopSec = "30";  # Assume might be executing shutdown scripts

        User = username;
      };
    };

    # Otherwise it's UTC
    time.timeZone = "Europe/Moscow";
}

(that's taken from a container declaration I've been playing with, file mounted with

    containers = 
    {
        #openhab = { autoStart = true; config = { config, pkgs, ... }: { imports = [ ./openhab.nix ]; }; };
        try = { autoStart = true; config = { config, pkgs, ... }: { imports = [ ./try.nix ]; }; };
        };

to the main OS config)

... then it would be up and running (and shutting down and restarting as needed), but not as a real package (yet).

stale[bot] commented 4 years ago

Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on irc.freenode.net.
mbrgm commented 3 years ago

still important to me

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

madorian commented 2 years ago

since there is no openhab package for nixos, how about a declarative way to install it via docker or some other packages?

nagisa commented 1 year ago

An issue that I’m seeing with openhab’s progress is that every attempt to add this is trying really hard to do everything, while just having the package definitions in nixpkgs would be a really good start. Adding a good nixos module on top of that would a cherry on cake, but its also perfectly reasonable for it to be configured with plain environment."etc"... and systemd.service declarations at first (so people can experiment and find what works well.)