68 lines
4.3 KiB
Plaintext

{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://deadvey.com//socialweb/notes/76",
"type": "Note",
"hash": "76",
"content": "<b>Home Manager automatically changing dark/light mode at sunrise/set:</b><br/>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/><div class=\"indent code\">'scripts/mode-switcher-based-on-sunlight.sh' = {<br/>&#9;&#9;&#9;text = ''<br/>&#9;&#9;&#9;&#9;run_a_command() {<br/>&#9;&#9;&#9;&#9;&#9;if [[ \"$light\" == \"DAY\" ]]; then<br/>&#9;&#9;&#9;&#9;&#9;&#9;sed -i 's/MODE\\ =\\ \".*\"/MODE\\ =\\ \"light\"/' $HOME/.config/home/home.nix<br/>&#9;&#9;&#9;&#9;&#9;&#9;home-manager switch<br/>&#9;&#9;&#9;&#9;&#9;else<br/>&#9;&#9;&#9;&#9;&#9;&#9;sed -i 's/MODE\\ =\\ \".*\"/MODE\\ =\\ \"dark\"/' $HOME/.config/home/home.nix<br/>&#9;&#9;&#9;&#9;&#9;&#9;home-manager switch<br/>&#9;&#9;&#9;&#9;&#9;fi<br/>&#9;&#9;&#9;&#9;};<br/>&#9;&#9;&#9;&#9;#!/bin/bash<br/>&#9;&#9;&#9;&#9;# Set your latitude and longitude<br/>&#9;&#9;&#9;&#9;LATITUDE=\"53.43N\"<br/>&#9;&#9;&#9;&#9;LONGITUDE=\"-1.89E\"<br/><br/>&#9;&#9;&#9;&#9;# Calculate the sunrise and sunset times for today using sunwait<br/>&#9;&#9;&#9;&#9;light=$(sunwait poll $LATITUDE $LONGITUDE)<br/><br/>&#9;&#9;&#9;&#9;run_a_command<br/>&#9;&#9;&#9;&#9;while sleep 5; do<br/>&#9;&#9;&#9;&#9;&#9;new_light=$(sunwait poll $LATITUDE $LONGITUDE)<br/>&#9;&#9;&#9;&#9;&#9;if [[ \"$new_light\" != \"$light\" ]]; then<br/>&#9;&#9;&#9;&#9;&#9;&#9;run_a_command<br/>&#9;&#9;&#9;&#9;&#9;fi<br/>&#9;&#9;&#9;&#9;done<br/>&#9;&#9;&#9;'';<br/>&#9;&#9;&#9;executable = true;<br/>&#9;&#9;};</div><br/><br/><br/>I have this to autorun on startup in Hyprland with <div class=\"code\">exec-once=\"$HOME/scripts/mode-switcher-based-on-sunlight.sh\";</div> then in the home.nix, I of course have a variable defined called MODE as either \"dark\" or \"light\"<br/><br/><div class=\"indent code\"><br/>&#9;{config, pkgs, lib, ...}:<br/>&#9;let <br/>&#9;&#9;MODE = \"light\";<br/>&#9;in<br/>&#9;{<br/>&#9;&#9;# Home config<br/>&#9;}<br/></div><br/><br/>And then that should be it, of course you'll want to make to make gtk follow this theme, I do that by having different theme files which each define a set of GTK themes and then those are assigned as variables on rebuild <div class=\"code\">&#9;inherit (import ./themes/\\${THEME}_\\${MODE}.nix) GTK_THEME GTK_THEME_NAME;</div><br/>You can see my full nix configurations <a href=\"https://git.javalsai.dynv6.net/deadvey/nixos\">here</a><br/>Fly You High - DeaDvey",
"url": "https://deadvey.com/blog/76.html",
"attributedTo": "https://deadvey.com/@blog",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [],
"published": "Thu, 12 Dec 2024 18:40:26",
"replies": {
"id": "https://deadvey.com/socialweb/replies/76",
"type": "Collection",
"first": {
"type": "CollectionPage",
"next": "https://deadvey.com/socialweb/replies/76?page=true",
"partOf": "https://deadvey.com/socialweb/replies/76",
"items": []
}
},
"tag": [
{
"Type": "Hashtag",
"Href": "https://deadvey.com/blog/nixos.html",
"Name": "#nixos"
},
{
"Type": "Hashtag",
"Href": "https://deadvey.com/blog/home manager.html",
"Name": "#home manager"
},
{
"Type": "Hashtag",
"Href": "https://deadvey.com/blog/customisation.html",
"Name": "#customisation"
},
{
"Type": "Hashtag",
"Href": "https://deadvey.com/blog/guide.html",
"Name": "#guide"
},
{
"Type": "Hashtag",
"Href": "https://deadvey.com/blog/dark mode.html",
"Name": "#dark mode"
},
{
"Type": "Hashtag",
"Href": "https://deadvey.com/blog/light mode.html",
"Name": "#light mode"
},
{
"Type": "Hashtag",
"Href": "https://deadvey.com/blog/sunrise.html",
"Name": "#sunrise"
},
{
"Type": "Hashtag",
"Href": "https://deadvey.com/blog/sunset.html",
"Name": "#sunset"
}
]
}