fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , moduleName , mainSection , programName , defaultPackage 2, examplePackage , mainExecutable , appletExecutable , xdgConfigFilePath 3, serviceDocumentation } : 4 5with lib ; 6 7let 8 9cfg = config . services .${ moduleName }; 10settingsFormat = pkgs . formats . ini { }; 11 12in { 13meta . maintainers = with maintainers ; [ rycee thiagokokada ]; 14 15imports = let 16mkRenamed = old :new : 17mkRenamedOptionModule ([ "services" moduleName ] ++ old ) [ 18"services" 19moduleName 20"settings" 21mainSection 22new 23]; 24in [ 25( mkRemovedOptionModule [ "services" moduleName "extraOptions" ] 26"All ${ programName } configuration is now available through services. ${ moduleName } .settings instead." ) 27( mkRenamed [ "brightness" "day" ] "brightness-day" ) 28( mkRenamed [ "brightness" "night" ] "brightness-night" ) 29]; 30 31options = { 32enable = mkEnableOption programName ; 33 34dawnTime = mkOption { 35type = types . nullOr types . str ; 36default = null ; 37example = "6:00-7:45" ; 38description = '' 39Set the time interval of dawn manually. 40The times must be specified as HH:MM in 24-hour format. 41'' ; 42}; 43 44duskTime = mkOption { 45type = types . nullOr types . str ; 46default = null ; 47example = "18:35-20:15" ; 48description = '' 49Set the time interval of dusk manually. 50The times must be specified as HH:MM in 24-hour format. 51'' ; 52}; 53 54latitude = mkOption { 55type = with types ; nullOr ( either str float ); 56default = null ; 57description = '' 58Your current latitude, between `-90.0` and 59`90.0`. Must be provided along with 60longitude. 61'' ; 62}; 63 64longitude = mkOption { 65type = with types ; nullOr ( either str float ); 66default = null ; 67description = '' 68Your current longitude, between `-180.0` and 69`180.0`. Must be provided along with 70latitude. 71'' ; 72}; 73 74provider = mkOption { 75type = types . enum [ "manual" "geoclue2" ]; 76default = "manual" ; 77description = '' 78The location provider to use for determining your location. If set to 79`manual` you must also provide latitude/longitude. 80If set to `geoclue2`, you must also enable the global 81geoclue2 service. 82'' ; 83}; 84 85temperature = { 86day = mkOption { 87type = types . int ; 88default = 5500 ; 89description = '' 90Colour temperature to use during the day, between 91`1000` and `25000` K. 92'' ; 93}; 94night = mkOption { 95type = types . int ; 96default = 3700 ; 97description = '' 98Colour temperature to use at night, between 99`1000` and `25000` K. 100'' ; 101}; 102}; 103 104package = mkOption { 105type = types . package ; 106default = defaultPackage ; 107defaultText = literalExpression examplePackage ; 108description = '' 109${ programName } derivation to use. 110'' ; 111}; 112 113enableVerboseLogging = mkEnableOption "verbose service logging" ; 114 115tray = mkOption { 116type = types . bool ; 117default = false ; 118example = true ; 119description = '' 120Start the ${ appletExecutable } tray applet. 121'' ; 122}; 123 124settings = mkOption { 125type = types . submodule { freeformType = settingsFormat . type ; }; 126default = { }; 127example = literalExpression '' 128{ 129${ mainSection } = { 130adjustment-method = "randr"; 131}; 132randr = { 133screen = 0; 134}; 135}; 136'' ; 137description = '' 138The configuration to pass to ${ programName } . 139Available options for ${ programName } described in 140{manpage}` ${ moduleName } (1)`. 141'' ; 142}; 143}; 144 145config = { 146assertions = [ 147( hm . assertions . assertPlatform "services. ${ moduleName } " pkgs 148platforms . linux ) 149 150{ 151assertion = ( cfg . settings ?${ mainSection }. dawn-time || cfg . settings 152 ?${ mainSection }. dusk-time ) 153|| ( cfg . settings .${ mainSection }. location-provider ) == "geoclue2" 154|| (( cfg . settings .${ mainSection }. location-provider ) == "manual" 155&& ( cfg . settings ?manual . lat || cfg . settings ?manual . lon )); 156message = '' 157In order for ${ programName } to know the time of action, you need to set one of 158- services. ${ moduleName } .provider = "geoclue2" for automatically inferring your location 159(you also need to enable Geoclue2 service separately) 160- services. ${ moduleName } .longitude and .latitude for specifying your location manually 161- services. ${ moduleName } .dawnTime and .duskTime for specifying the times manually 162'' ; 163} 164]; 165 166services .${ moduleName }. settings = { 167${ mainSection } = { 168temp-day = cfg . temperature . day ; 169temp-night = cfg . temperature . night ; 170location-provider = cfg . provider ; 171dawn-time = mkIf ( cfg . dawnTime != null ) cfg . dawnTime ; 172dusk-time = mkIf ( cfg . duskTime != null ) cfg . duskTime ; 173}; 174manual = mkIf ( cfg . provider == "manual" ) { 175lat = mkIf ( cfg . latitude != null ) ( toString cfg . latitude ); 176lon = mkIf ( cfg . longitude != null ) ( toString cfg . longitude ); 177}; 178}; 179 180xdg . configFile .${ xdgConfigFilePath }. source = 181settingsFormat . generate xdgConfigFilePath cfg . settings ; 182 183home . packages = [ cfg . package ]; 184 185systemd . user . services .${ moduleName } = { 186Unit = let 187geoclueAgentService = 188lib . optional ( cfg . provider == "geoclue2" ) "geoclue-agent.service" ; 189in { 190Description = " ${ programName } colour temperature adjuster" ; 191Documentation = serviceDocumentation ; 192After = [ "graphical-session-pre.target" ] ++ geoclueAgentService ; 193Wants = geoclueAgentService ; 194PartOf = [ "graphical-session.target" ]; 195}; 196 197Install = { WantedBy = [ "graphical-session.target" ]; }; 198 199Service = { 200ExecStart = let 201command = if cfg . tray then appletExecutable else mainExecutable ; 202configFullPath = config . xdg . configHome + "/ ${ xdgConfigFilePath } " ; 203in " ${ cfg . package } /bin/ ${ command } " + cli . toGNUCommandLineShell { } { 204v = cfg . enableVerboseLogging ; 205c = configFullPath ; 206}; 207RestartSec = 3 ; 208Restart = "on-failure" ; 209}; 210}; 211}; 212}