fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . random-background ; 8 9flags = lib . concatStringsSep " " 10([ "--bg- ${ cfg . display } " "--no-fehbg" "--randomize" ] 11++ lib . optional ( ! cfg . enableXinerama ) "--no-xinerama" ); 12 13in { 14meta . maintainers = [ maintainers . rycee ]; 15 16options = { 17services . random-background = { 18enable = mkEnableOption "" // { 19description = '' 20Whether to enable random desktop background. 21 22Note, if you are using NixOS and have set up a custom 23desktop manager session for Home Manager, then the session 24configuration must have the `bgSupport` 25option set to `true` or the background 26image set by this module may be overwritten. 27'' ; 28}; 29 30imageDirectory = mkOption { 31type = types . str ; 32example = "%h/backgrounds" ; 33description = '' 34The directory of images from which a background should be 35chosen. Should be formatted in a way understood by systemd, 36e.g., '%h' is the home directory. 37'' ; 38}; 39 40display = mkOption { 41type = types . enum [ "center" "fill" "max" "scale" "tile" ]; 42default = "fill" ; 43description = "Display background images according to this option." ; 44}; 45 46interval = mkOption { 47default = null ; 48type = types . nullOr types . str ; 49example = "1h" ; 50description = '' 51The duration between changing background image, set to null 52to only set background when logging in. Should be formatted 53as a duration understood by systemd. 54'' ; 55}; 56 57enableXinerama = mkOption { 58default = true ; 59type = types . bool ; 60description = '' 61Will place a separate image per screen when enabled, 62otherwise a single image will be stretched across all 63screens. 64'' ; 65}; 66}; 67}; 68 69config = mkIf cfg . enable ( mkMerge ([ 70{ 71assertions = [ 72( hm . assertions . assertPlatform "services.random-background" pkgs 73platforms . linux ) 74]; 75 76systemd . user . services . random-background = { 77Unit = { 78Description = "Set random desktop background using feh" ; 79After = [ "graphical-session-pre.target" ]; 80PartOf = [ "graphical-session.target" ]; 81}; 82 83Service = { 84Type = "oneshot" ; 85ExecStart = " ${ pkgs . feh } /bin/feh ${ flags } ${ cfg . imageDirectory } " ; 86IOSchedulingClass = "idle" ; 87}; 88 89Install = { WantedBy = [ "graphical-session.target" ]; }; 90}; 91} 92( mkIf ( cfg . interval != null ) { 93systemd . user . timers . random-background = { 94Unit = { Description = "Set random desktop background using feh" ; }; 95 96Timer = { OnUnitActiveSec = cfg . interval ; }; 97 98Install = { WantedBy = [ "timers.target" ]; }; 99}; 100}) 101])); 102}