@@ -4,10 +4,12 @@ with lib;
let
cfg = config . services . locate ;
isMLocate = hasPrefix " m l o c a t e " cfg . locate . name ;
isFindutils = hasPrefix " f i n d u t i l s " cfg . locate . name ;
in {
options . services . locate = {
options . services . locate = with types ; {
enable = mkOption {
type = types . bool;
type = bool ;
default = false ;
description = ''
I f e n a b l e d , N i x O S w i l l p e r i o d i c a l l y u p d a t e t h e d a t a b a s e o f
@@ -16,8 +18,9 @@ in {
} ;
locate = mkOption {
type = types . package;
type = package ;
default = pkgs . findutils ;
defaultText = " p k g s . f i n d u t i l s " ;
example = " p k g s . m l o c a t e " ;
description = ''
T h e l o c a t e i m p l e m e n t a t i o n t o u s e
@@ -25,7 +28,7 @@ in {
} ;
interval = mkOption {
type = types . str;
type = str ;
default = " 0 2 : 1 5 " ;
example = " h o u r l y " ;
description = ''
@@ -38,11 +41,8 @@ in {
'' ;
} ;
# This is no longer supported, but we keep it to give a better warning below
period = mkOption { visible = false ; } ;
extraFlags = mkOption {
type = types . listOf types . str ;
type = listOf str ;
default = [ ] ;
description = ''
E x t r a f l a g s t o p a s s t o < c o m m a n d > u p d a t e d b < / c o m m a n d > .
@@ -50,7 +50,7 @@ in {
} ;
output = mkOption {
type = types . path;
type = path ;
default = " / v a r / c a c h e / l o c a t e d b " ;
description = ''
T h e d a t a b a s e f i l e t o b u i l d .
@@ -58,7 +58,7 @@ in {
} ;
localuser = mkOption {
type = types . str ;
type = nullOr str ;
default = " n o b o d y " ;
description = ''
T h e u s e r t o s e a r c h n o n - n e t w o r k d i r e c t o r i e s a s , u s i n g
@@ -66,31 +66,81 @@ in {
'' ;
} ;
includeStore = mkOption {
type = types . bool ;
default = false ;
pruneFS = mkOption {
type = listOf str ;
default = [ " a f s " " a n o n _ i n o d e f s " " a u t o " " a u t o f s " " b d e v " " b i n f m t " " b i n f m t _ m i s c " " c g r o u p " " c i f s " " c o d a " " c o n f i g f s " " c r a m f s " " c p u s e t " " d e b u g f s " " d e v f s " " d e v p t s " " d e v t m p f s " " e c r y p t f s " " e v e n t p o l l f s " " e x o f s " " f u t e x f s " " f t p f s " " f u s e " " f u s e c t l " " g f s " " g f s 2 " " h o s t f s " " h u g e t l b f s " " i n o t i f y f s " " i s o 9 6 6 0 " " j f f s 2 " " l u s t r e " " m i s c " " m q u e u e " " n c p f s " " n n p f s " " o c f s " " o c f s 2 " " p i p e f s " " p r o c " " r a m f s " " r p c _ p i p e f s " " s e c u r i t y f s " " s e l i n u x f s " " s f s " " s h f s " " s m b f s " " s o c k f s " " s p u f s " " n f s " " N F S " " n f s 4 " " n f s d " " s s h f s " " s u b f s " " s u p e r m o u n t " " s y s f s " " t m p f s " " u b i f s " " u d f " " u s b f s " " v b o x s f " " v p e r f c t r f s " ] ;
description = ''
W h e t h e r t o i n c l u d e < f i l e n a me > / n i x / s t o r e < / f i l e n a m e > i n t h e l o c a t e d a t a b a s e .
W h i c h f i l e s y s t e m t y p e s t o e x c l u d e f r o m i n d e x i n g
'' ;
} ;
prunePaths = mkOption {
type = listOf path ;
default = [ " / t m p " " / v a r / t m p " " / v a r / c a c h e " " / v a r / l o c k " " / v a r / r u n " " / v a r / s p o o l " " / n i x / s t o r e " ] ;
description = ''
W h i c h p a t h s t o e x c l u d e f r o m i n d e x i n g
'' ;
} ;
pruneNames = mkOption {
type = listOf str ;
default = [ ] ;
description = ''
D i r e c t o r y c o m p o n e n t s w h i c h s h o u l d e x c l u d e p a t h s c o n t a i n i n g t h e m f r o m i n d e x i n g
'' ;
} ;
pruneBindMounts = mkOption {
type = bool ;
default = false ;
description = ''
W h e t h e r n o t t o i n d e x b i n d m o u n t s
'' ;
} ;
} ;
config = {
warnings =
let opt = options . services . locate . period ; in
optional opt . isDefined " T h e ‘ s e r v i c e s . l o c a t e . p e r i o d ’ o p t i o n i n ${ showFiles opt . files } h a s b e e n r e m o v e d ; p l e a s e r e p l a c e i t w i t h ‘ s e r v i c e s . l o c a t e . i n t e r v a l ’ , u s i n g t h e s y s t e m d . t i m e ( 7 ) c a l e n d a r e v e n t f o r m a t . " ;
config = mkIf cfg . enable {
users . extraGroups = mkIf isMLocate { mlocate = { } ; } ;
security . setuidOwners = mkIf isMLocate
[ { group = " m l o c a t e " ;
owner = " r o o t " ;
permissions = " u + r x , g + x , o + x " ;
setgid = true ;
setuid = false ;
program = " l o c a t e " ;
}
] ;
nixpkgs . config = { locate . dbfile = cfg . output ; } ;
environment . systemPackages = [ cfg . locate ] ;
environment . variables = mkIf ( ! isMLocate )
{ LOCATE_PATH = cfg . output ;
} ;
warnings = optional ( isMLocate && cfg . localuser != null ) " m l o c a t e d o e s n o t s u p p o r t s e a r c h i n g a s u s e r o t h e r t h a n r o o t "
++ optional ( isFindutils && cfg . pruneNames != [ ] ) " f i n d u t i l s l o c a t e d o e s n o t s u p p o r t p r u n i n g b y d i r e c t o r y c o m p o n e n t "
++ optional ( isFindutils && cfg . pruneBindMounts ) " f i n d u t i l s l o c a t e d o e s n o t s u p p o r t s k i p p i n g b i n d m o u n t s " ;
systemd . services . update-locatedb =
{ description = " U p d a t e L o c a t e D a t a b a s e " ;
path = [ pkgs . su ] ;
path = mkIf ( ! isMLocate ) [ pkgs . su ] ;
script =
''
m k d i r - m 0 7 55 - p $( d i r n a m e ${ toString cfg . output } )
i n s t a l l - m ${ if isMLocate then " 0 7 50 " else " 0 7 5 5 " } - o r o o t - g ${ if isMLocate then " m l o c a t e " else " r o o t " } - d $( d i r n a m e ${ cfg . output } )
e x e c ${ cfg . locate } / b i n / u p d a t e d b \
- - l o c a l u s e r = ${ cfg . localuser } \
${ optionalString ( ! cfg . includeStore ) " - - p r u n e p a t h s = ' / n i x / s t o r e ' " } \
${ optionalString ( cfg . localuser != null ) '' - - l o c a l u s e r = ${ cfg . localuser } '' } \
- - o u t p u t = ${ toString cfg . output } ${ concatStringsSep " " cfg . extraFlags }
'' ;
environment = {
PRUNEFS = concatStringsSep " " cfg . pruneFS ;
PRUNEPATHS = concatStringsSep " " cfg . prunePaths ;
PRUNENAMES = concatStringsSep " " cfg . pruneNames ;
PRUNE_BIND_MOUNTS = if cfg . pruneBindMounts then " y e s " else " n o " ;
} ;
serviceConfig . Nice = 19 ;
serviceConfig . IOSchedulingClass = " i d l e " ;
serviceConfig . PrivateTmp = " y e s " ;
@@ -100,7 +150,7 @@ in {
serviceConfig . ReadWriteDirectories = dirOf cfg . output ;
} ;
systemd . timers . update-locatedb = mkIf cfg . enable
systemd . timers . update-locatedb =
{ description = " U p d a t e t i m e r f o r l o c a t e d a t a b a s e " ;
partOf = [ " u p d a t e - l o c a t e d b . s e r v i c e " ] ;
wantedBy = [ " t i m e r s . t a r g e t " ] ;