From 6644d0031da7af16effda4287ea2da17506ee415 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 26 Apr 2020 00:24:49 +0100 Subject: feat(fun/idual && nixos/camden): Add light alarm systemd units Adds a systemd unit to run the idual light alarm using a transient timer created by systemd-run. --- fun/idual/__init__.py | 2 ++ fun/idual/default.nix | 11 ++++++++--- ops/nixos/camden/default.nix | 12 +++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/fun/idual/__init__.py b/fun/idual/__init__.py index 2c0f97170b54..ad103ef049b5 100644 --- a/fun/idual/__init__.py +++ b/fun/idual/__init__.py @@ -62,8 +62,10 @@ if __name__ == "__main__": # # The command sending doesn't always work, hence this brute-force # approach. + print('Initialising light controller') ctrl = LightController() + print('Turning on the lights. Wakey, wakey!') for i in range(9): ctrl.send_cmd('morning') time.sleep(0.2) diff --git a/fun/idual/default.nix b/fun/idual/default.nix index e051f1c812e4..1ac87ab47f0f 100644 --- a/fun/idual/default.nix +++ b/fun/idual/default.nix @@ -12,8 +12,13 @@ let python.broadlink ]; }; -in lib.fix (self: { package = python3Packages.buildPythonPackage opts; script = python3Packages.buildPythonApplication opts; - python = python3.withPackages (_: [ self.package ]); -}) +in { + inherit script; + python = python3.withPackages (_: [ package ]); + setAlarm = pkgs.writeShellScriptBin "set-alarm" '' + echo "setting an alarm for ''${1}" + ${pkgs.systemd}/bin/systemd-run --user --on-calendar="''${1} Europe/London" --unit=light-alarm.service + ''; +} diff --git a/ops/nixos/camden/default.nix b/ops/nixos/camden/default.nix index 0528e5c3585b..f37d6a1f7884 100644 --- a/ops/nixos/camden/default.nix +++ b/ops/nixos/camden/default.nix @@ -1,5 +1,5 @@ # This file configures camden.tazj.in, my homeserver. -{ depot, lib, ... }: +{ depot, pkgs, lib, ... }: config: let nixpkgs = import depot.third_party.nixpkgsSrc { @@ -100,6 +100,7 @@ in lib.fix(self: { environment.systemPackages = # programs from the depot (with depot; [ + fun.idual.setAlarm third_party.git third_party.honk third_party.pounce @@ -347,5 +348,14 @@ in lib.fix(self: { }; }; + # Timer units that can be started with systemd-run to set my alarm. + systemd.user.services.light-alarm = { + script = "${depot.fun.idual.script}/bin/__init__.py"; + postStart = "${pkgs.systemd}/bin/systemctl --user stop light-alarm.timer"; + serviceConfig = { + Type = "oneshot"; + }; + }; + system.stateVersion = "19.09"; }) -- cgit 1.4.1