[Source](https://nixos.wiki/wiki/Systemd/Timers).
Adding [[systemd]] services to [[NixOS]] is fairly easy:
```nix
systemd.services."hello-world" = {
script = ''
set -eu
${pkgs.coreutils}/bin/echo "Hello World"
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
```
Similarly, systemd timers can be set up with the following:
```nix
systemd.timers."hello-world" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "5m";
Unit = "hello-world.service";
};
};
```
The configure a schedule for a timer, use something like this:
```nix
...
timerConfig = {
OnCalendar = "daily";
Persistent = true;
};
};
```
The above examples were copied verbatim from the source linked at the top. For more information on systemd targets, look at the man pages.
# Shells
When using a shell besides `sh` (or is it `bash`?), you can use the form:
```nix
script = "exec ${./path/to/script}"
```
to honor the `#!` in the script file. The script itself is loaded into the Nix store and tracked as intended.
Dependencies can be injected into the environment using `path`.