Nix Cookbook: Difference between revisions

imported>Dustinlacewell
m Fix some formatting for "Creating Shell Scripts"
imported>Dustinlacewell
Added "Creating Periodic Services" recipe
Line 15: Line 15:
in {
in {
   environment.systemPackages = [ helloWorld ];
   environment.systemPackages = [ helloWorld ];
}
</syntaxHighlight>
=== Creating Periodic Services ===
Using the [https://nixos.org/nixos/manual/#sec-systemctl systemd support] periodic services can be defined. In this case a service named <code>simple-timer</code> writes out the current time to <code>/tmp/simple-timer.log</code> every minute.
<syntaxHighlight lang="nix>
{ pkgs, ... }:
{
  systemd = {
    timers.simple-timer = {
      wantedBy = [ "timers.target" ];
      partOf = [ "simple-timer.service" ];
      timerConfig.OnCalendar = "minutely";
    };
    services.simple-timer = {
      serviceConfig.Type = "oneshot";
      script = ''
        echo "Time: $(date)." >> /tmp/simple-timer.log
        chmod +r /tmp/simple-timer.log
      '';
    };
  };
}
}
</syntaxHighlight>
</syntaxHighlight>