fork/home-manager
git clone https://git.julia.blue/fork/home-manager
b25161c6
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6cfg = config . services . darkman ; 7 8yamlFormat = pkgs . formats . yaml { }; 9 10scriptsOptionType = kind : 11mkOption { 12type = types . attrsOf ( types . oneOf [ types . path types . lines ]); 13default = { }; 14example = literalExpression '' 15{ 16gtk-theme = ''' 17''${pkgs.dconf}/bin/dconf write \ 18/org/gnome/desktop/interface/color-scheme "'prefer- ${ kind } '" 19'''; 20my-python-script = pkgs.writers.writePython3 "my-python-script" { } ''' 21print('Do something!') 22'''; 23} 24'' ; 25description = '' 26Scripts to run when switching to " ${ kind } mode". 27 28Multiline strings are interpreted as Bash shell scripts and a shebang is 29not required. 30'' ; 31}; 32 33generateScripts = folder : 34mapAttrs' ( k :v :{ 35name = " ${ folder } / ${ k } " ; 36value = { 37source = if builtins . isPath v || isDerivation v then 38v 39else 40pkgs . writeShellScript ( hm . strings . storeFileName k ) v ; 41}; 42}); 43in { 44meta . maintainers = [ maintainers . xlambein ]; 45 46options . services . darkman = { 47enable = mkEnableOption '' 48darkman, a tool that automatically switches dark-mode on and off based on 49the time of the day'' ; 50 51package = mkPackageOption pkgs "darkman" { }; 52 53settings = mkOption { 54type = types . submodule { freeformType = yamlFormat . type ; }; 55example = literalExpression '' 56{ 57lat = 52.3; 58lng = 4.8; 59usegeoclue = true; 60} 61'' ; 62description = '' 63Settings for the {command}`darkman` command. See 64<https://darkman.whynothugo.nl/#CONFIGURATION> for details. 65'' ; 66}; 67 68darkModeScripts = scriptsOptionType "dark" ; 69 70lightModeScripts = scriptsOptionType "light" ; 71}; 72 73config = mkIf cfg . enable { 74assertions = [ 75( hm . assertions . assertPlatform "services.darkman" pkgs platforms . linux ) 76]; 77 78home . packages = [ cfg . package ]; 79 80xdg . configFile = { 81"darkman/config.yaml" = mkIf ( cfg . settings != { }) { 82source = yamlFormat . generate "darkman-config.yaml" cfg . settings ; 83}; 84}; 85 86xdg . dataFile = mkMerge [ 87( mkIf ( cfg . darkModeScripts != { }) 88( generateScripts "dark-mode.d" cfg . darkModeScripts )) 89( mkIf ( cfg . lightModeScripts != { }) 90( generateScripts "light-mode.d" cfg . lightModeScripts )) 91]; 92 93systemd . user . services . darkman = { 94Unit = { 95Description = "Darkman system service" ; 96Documentation = "man:darkman(1)" ; 97PartOf = [ "graphical-session.target" ]; 98BindsTo = [ "graphical-session.target" ]; 99X-Restart-Triggers = 100[ " ${ config . xdg . configFile . "darkman/config.yaml" . source } " ]; 101}; 102 103Service = { 104Type = "dbus" ; 105BusName = "nl.whynothugo.darkman" ; 106ExecStart = " ${ getExe cfg . package } run" ; 107Restart = "on-failure" ; 108TimeoutStopSec = 15 ; 109Slice = "background.slice" ; 110}; 111 112Install . WantedBy = mkDefault [ "graphical-session.target" ]; 113}; 114}; 115}