mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-16 23:03:40 +01:00
29027fd1e1
Using pkgs.lib on the spine of module evaluation is problematic because the pkgs argument depends on the result of module evaluation. To prevent an infinite recursion, pkgs and some of the modules are evaluated twice, which is inefficient. Using ‘with lib’ prevents this problem.
38 lines
659 B
Nix
38 lines
659 B
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.logrotate;
|
|
|
|
configFile = pkgs.writeText "logrotate.conf"
|
|
cfg.config;
|
|
|
|
cronJob = ''
|
|
5 * * * * root ${pkgs.logrotate}/sbin/logrotate ${configFile}
|
|
'';
|
|
|
|
in
|
|
{
|
|
options = {
|
|
services.logrotate = {
|
|
enable = mkOption {
|
|
default = false;
|
|
description = ''
|
|
Enable the logrotate cron job
|
|
'';
|
|
};
|
|
|
|
config = mkOption {
|
|
default = "";
|
|
description = ''
|
|
The contents of the logrotate config file
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
services.cron.systemCronJobs = [ cronJob ];
|
|
};
|
|
}
|