about summary refs log tree commit diff
path: root/nixos/modules/services/misc/preload.nix
blob: d26e2c3d383e8cad172538facf3d2a8af43353ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.preload;
in {
  meta = { maintainers = pkgs.preload.meta.maintainers; };

  options.services.preload = {
    enable = mkEnableOption "preload";
    package = mkPackageOption pkgs "preload" { };
  };

  config = mkIf cfg.enable {
    systemd.services.preload = {
      description = "Loads data into ram during idle time of CPU.";
      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        EnvironmentFile = "${cfg.package}/etc/conf.d/preload";
        ExecStart = "${getExe cfg.package} -l '' --foreground $PRELOAD_OPTS";
        Type = "simple";
        # Only preload data during CPU idle time
        IOSchedulingClass = 3;
        DynamicUser = true;
        StateDirectory = "preload";
      };
    };
  };
}