Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{ stdenv, fetchFromGitHub }:
with stdenv.lib;
stdenv.mkDerivation rec {
name = "hass-custom-alarm-${version}";
version = "1.3.1";
src = fetchFromGitHub {
owner = "gazoscalvertos";
repo = "Hass-Custom-Alarm";
rev = "v${version}";
sha256 = "1xlwsyg45kmvx3gvkv7k5imbhkxan0s573lalkcqcflf078w7555";
};
dontInstall = true;
unpackPhase = ''
mkdir $out
cp -r * $out/.
'';
}
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.hass-custom-alarm;
hassConfig = config.services.home-assistant;
configDir = hassConfig.configDir;
files = ["/www/alarm/alarm.css"
"/www/lib/jquery-3.2.1.min.js"
"/www/lib/countdown360.js"
"/custom_components/alarm_control_panel/bwalarm.py"
"/panels/alarm.html"];
in {
options.services.hass-custom-alarm = {
enable = mkEnableOption "Home Assistant Custom Alarm Panel";
};
config = mkIf cfg.enable {
environment.systemPackages = with pkgs; [
hass-custom-alarm
];
systemd.services.hass-custom-alarm = {
description = "Home Assistant Custom Alarm Panel";
before = [ "home-assistant.service" ];
preStart = lib.foldl
(script: filePath: script + ''
mkdir -p ${configDir}${builtins.dirOf filePath}
ln -s ${pkgs.hass-custom-alarm}${filePath} ${configDir}${filePath}
'')
""
files;
postStop = lib.foldl
(script: filePath: script + ''
rm -f ${configDir}${filePath}
rmdir ${configDir}${builtins.dirOf filePath} &>/dev/null
'')
""
files;
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
User = "hass";
Group = "hass";
};
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.