Only run create-plans script once per day on hera
This commit is contained in:
parent
771904f67b
commit
ce6d608100
3 changed files with 48 additions and 44 deletions
|
@ -162,5 +162,6 @@ in {
|
||||||
./roles/mail2rss.nix
|
./roles/mail2rss.nix
|
||||||
./roles/headless-mpd.nix
|
./roles/headless-mpd.nix
|
||||||
./roles/headless.nix
|
./roles/headless.nix
|
||||||
|
./roles/create-plans.nix
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
47
home-manager/roles/create-plans.nix
Normal file
47
home-manager/roles/create-plans.nix
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
{pkgs, ...}: let
|
||||||
|
plans = pkgs.privateValue
|
||||||
|
{
|
||||||
|
"workDay" = "pass";
|
||||||
|
"weekend" = "pass";
|
||||||
|
}
|
||||||
|
"plans";
|
||||||
|
createPlans = pkgs.writeHaskellScript
|
||||||
|
{
|
||||||
|
name = "create-plans";
|
||||||
|
bins = [pkgs.khal pkgs.vdirsyncer];
|
||||||
|
imports = [
|
||||||
|
"Data.Time"
|
||||||
|
];
|
||||||
|
} ''
|
||||||
|
main = do
|
||||||
|
today <- localDay . zonedTimeToLocalTime <$> getZonedTime
|
||||||
|
[0..7] & fmap (`addDays` today) & mapM_ \day -> do
|
||||||
|
planned <- khal ["list", "-a", "Planung", show day, "06:00", "24h", "--notstarted"] |> captureTrim
|
||||||
|
when (planned == "No events") $ do
|
||||||
|
say $ "Creating events for " <> show day
|
||||||
|
if (dayOfWeek day `elem` [Saturday, Sunday]) then do
|
||||||
|
${plans.weekend}
|
||||||
|
else do
|
||||||
|
${plans.workDay}
|
||||||
|
'';
|
||||||
|
in {
|
||||||
|
systemd.user = {
|
||||||
|
services.create-plans = {
|
||||||
|
Unit.Description = "Create planning appointments in calendar";
|
||||||
|
Service = {
|
||||||
|
Type = "oneshot";
|
||||||
|
ExecStart = toString (pkgs.writeShellScript "update-plans" ''
|
||||||
|
set -e
|
||||||
|
${pkgs.vdirsyncer}/bin/vdirsyncer sync nextcloud_calendar/planung
|
||||||
|
${createPlans}/bin/create-plans
|
||||||
|
${pkgs.vdirsyncer}/bin/vdirsyncer sync nextcloud_calendar/planung
|
||||||
|
'');
|
||||||
|
};
|
||||||
|
};
|
||||||
|
timers.create-plans = {
|
||||||
|
Unit.Description = "Create planning appointments in calendar";
|
||||||
|
Timer.OnCalendar = "00:01:00";
|
||||||
|
Install.WantedBy = ["timers.target"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,30 +1,5 @@
|
||||||
{pkgs, ...}: let
|
{pkgs, ...}: let
|
||||||
calendars = pkgs.privateValue [] "calendars";
|
calendars = pkgs.privateValue [] "calendars";
|
||||||
plans = pkgs.privateValue
|
|
||||||
{
|
|
||||||
"workDay" = "pass";
|
|
||||||
"weekend" = "pass";
|
|
||||||
}
|
|
||||||
"plans";
|
|
||||||
createPlans = pkgs.writeHaskellScript
|
|
||||||
{
|
|
||||||
name = "create-plans";
|
|
||||||
bins = [pkgs.khal pkgs.vdirsyncer];
|
|
||||||
imports = [
|
|
||||||
"Data.Time"
|
|
||||||
];
|
|
||||||
} ''
|
|
||||||
main = do
|
|
||||||
today <- localDay . zonedTimeToLocalTime <$> getZonedTime
|
|
||||||
[0..7] & fmap (`addDays` today) & mapM_ \day -> do
|
|
||||||
planned <- khal ["list", "-a", "Planung", show day, "06:00", "24h", "--notstarted"] |> captureTrim
|
|
||||||
when (planned == "No events") $ do
|
|
||||||
say $ "Creating events for " <> show day
|
|
||||||
if (dayOfWeek day `elem` [Saturday, Sunday]) then do
|
|
||||||
${plans.weekend}
|
|
||||||
else do
|
|
||||||
${plans.workDay}
|
|
||||||
'';
|
|
||||||
ui = pkgs.writeShellScriptBin "calendar" ''
|
ui = pkgs.writeShellScriptBin "calendar" ''
|
||||||
ikhal -d Serien
|
ikhal -d Serien
|
||||||
'';
|
'';
|
||||||
|
@ -57,23 +32,4 @@ in {
|
||||||
calendars
|
calendars
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
systemd.user = {
|
|
||||||
services.create-plans = {
|
|
||||||
Unit.Description = "Create planning appointments in calendar";
|
|
||||||
Service = {
|
|
||||||
Type = "oneshot";
|
|
||||||
ExecStart = toString (pkgs.writeShellScript "update-plans" ''
|
|
||||||
set -e
|
|
||||||
${pkgs.vdirsyncer}/bin/vdirsyncer sync nextcloud_calendar/planung
|
|
||||||
${createPlans}/bin/create-plans
|
|
||||||
${pkgs.vdirsyncer}/bin/vdirsyncer sync nextcloud_calendar/planung
|
|
||||||
'');
|
|
||||||
};
|
|
||||||
};
|
|
||||||
timers.create-plans = {
|
|
||||||
Unit.Description = "Create planning appointments in calendar";
|
|
||||||
Timer.OnCalendar = "hourly";
|
|
||||||
Install.WantedBy = ["timers.target"];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue