at 15.09-beta 2.3 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.locate; 7in { 8 9 ###### interface 10 11 options = { 12 13 services.locate = { 14 15 enable = mkOption { 16 type = types.bool; 17 default = false; 18 description = '' 19 If enabled, NixOS will periodically update the database of 20 files used by the <command>locate</command> command. 21 ''; 22 }; 23 24 period = mkOption { 25 type = types.str; 26 default = "15 02 * * *"; 27 description = '' 28 This option defines (in the format used by cron) when the 29 locate database is updated. 30 The default is to update at 02:15 at night every day. 31 ''; 32 }; 33 34 extraFlags = mkOption { 35 type = types.listOf types.str; 36 default = [ ]; 37 description = '' 38 Extra flags to pass to <command>updatedb</command>. 39 ''; 40 }; 41 42 output = mkOption { 43 type = types.path; 44 default = "/var/cache/locatedb"; 45 description = '' 46 The database file to build. 47 ''; 48 }; 49 50 localuser = mkOption { 51 type = types.str; 52 default = "nobody"; 53 description = '' 54 The user to search non-network directories as, using 55 <command>su</command>. 56 ''; 57 }; 58 59 includeStore = mkOption { 60 type = types.bool; 61 default = false; 62 description = '' 63 Whether to include <filename>/nix/store</filename> in the locate database. 64 ''; 65 }; 66 67 }; 68 69 }; 70 71 ###### implementation 72 73 config = { 74 systemd.services.update-locatedb = 75 { description = "Update Locate Database"; 76 path = [ pkgs.su ]; 77 script = 78 '' 79 mkdir -m 0755 -p $(dirname ${toString cfg.output}) 80 exec updatedb \ 81 --localuser=${cfg.localuser} \ 82 ${optionalString (!cfg.includeStore) "--prunepaths='/nix/store'"} \ 83 --output=${toString cfg.output} ${concatStringsSep " " cfg.extraFlags} 84 ''; 85 serviceConfig.Nice = 19; 86 serviceConfig.IOSchedulingClass = "idle"; 87 }; 88 89 services.cron.systemCronJobs = optional config.services.locate.enable 90 "${config.services.locate.period} root ${config.systemd.package}/bin/systemctl start update-locatedb.service"; 91 92 }; 93 94}