<h1class="blog-title">Home Manager automatically changing dark/light mode at sunrise/set</h1>
<pclass="blog-content">Firstly, to do this you need pkgs.sunwait (though other options would work with a bit of changing). Make a script like this, I put mine in my home.file, but you can also just make it a file on it's own.<br/><divclass="indent code">'scripts/mode-switcher-based-on-sunlight.sh' = {<br> text = ''<br> run_a_command() {<br> if [[ "$light" == "DAY" ]]; then<br> sed -i 's/MODE = ".*"/MODE = "light"/' $HOME/.config/home/home.nix<br> home-manager switch<br> else<br> sed -i 's/MODE = ".*"/MODE = "dark"/' $HOME/.config/home/home.nix<br> home-manager switch<br> fi<br> };<br> #!/bin/bash<br> # Set your latitude and longitude<br> LATITUDE="53.43N"<br> LONGITUDE="-1.89E"<br><br> # Calculate the sunrise and sunset times for today using sunwait<br> light=$(sunwait poll $LATITUDE $LONGITUDE)<br><br> run_a_command<br> while sleep 5; do<br> new_light=$(sunwait poll $LATITUDE $LONGITUDE)<br> if [[ "$new_light" != "$light" ]]; then<br> run_a_command<br> fi<br>