Skip to content

Instantly share code, notes, and snippets.

@WhittlesJr
Created November 22, 2018 03:37
Show Gist options
  • Save WhittlesJr/8def925e93ee8362bbe7cbd6cde21b15 to your computer and use it in GitHub Desktop.
Save WhittlesJr/8def925e93ee8362bbe7cbd6cde21b15 to your computer and use it in GitHub Desktop.
{ 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