From e4359f5245abb66925dfd1a2fd7c494815917ae8 Mon Sep 17 00:00:00 2001 From: mat ess Date: Sat, 16 Jul 2022 16:34:47 -0400 Subject: [PATCH] Use dark-mode-notify to tell fish+kitty to update --- flake.lock | 17 +++++++++++++++ flake.nix | 20 +++++++++++++----- home/shells.nix | 44 +++++++++++++++++++++++++++++++++------ pkgs/dark-mode-notify.nix | 26 +++++++++++++++++++++++ 4 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 pkgs/dark-mode-notify.nix diff --git a/flake.lock b/flake.lock index 67d7bb3..993cff1 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "dark-mode-notify-src": { + "flake": false, + "locked": { + "lastModified": 1657531789, + "narHash": "sha256-m/VTRz0lu+BMETRVY+6tESDNhKwlpNwfwMZ45BMwYzk=", + "owner": "bouk", + "repo": "dark-mode-notify", + "rev": "5ac81063f442ea72dab457c777d1860754cfaede", + "type": "github" + }, + "original": { + "owner": "bouk", + "repo": "dark-mode-notify", + "type": "github" + } + }, "darwin": { "inputs": { "nixpkgs": [ @@ -123,6 +139,7 @@ }, "root": { "inputs": { + "dark-mode-notify-src": "dark-mode-notify-src", "darwin": "darwin", "flake-compat": "flake-compat", "flake-utils": "flake-utils", diff --git a/flake.nix b/flake.nix index 00f1d3c..bb3b99e 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,11 @@ # Other sources flake-compat = { url = github:edolstra/flake-compat; flake = false; }; flake-utils.url = github:numtide/flake-utils; + + dark-mode-notify-src = { + url = github:bouk/dark-mode-notify; + flake = false; + }; }; outputs = { self, darwin, nixpkgs, home-manager, flake-utils, ... }@inputs: @@ -28,12 +33,17 @@ nixpkgsConfig = { config = { allowUnfree = true; }; overlays = attrValues self.overlays ++ singleton ( - final: prev: optionalAttrs - (prev.stdenv.system == "aarch64-darwin") + final: prev: { - # Sub in x86 version of packages that don't build on Apple Silicon yet - inherit (final.pkgs-x86); - } // final.patched + dark-mode-notify = final.callPackage ./pkgs/dark-mode-notify.nix { inherit (inputs) dark-mode-notify-src; }; + } // optionalAttrs + (prev.stdenv.system == "aarch64-darwin") + { + # Sub in x86 version of packages that don't build on Apple Silicon yet + inherit (final.pkgs-x86); + # Sub in one off patches + inherit (final.patched); + } ); }; diff --git a/home/shells.nix b/home/shells.nix index 4060fe7..c0d1de9 100644 --- a/home/shells.nix +++ b/home/shells.nix @@ -6,7 +6,9 @@ programs.fish.enable = true; # Add Fish plugins - home.packages = with pkgs.fishPlugins; [ done ]; + home.packages = with pkgs.fishPlugins; [ + done + ]; programs.fish.plugins = [ { @@ -68,16 +70,26 @@ # Set `$term_background` based on whether macOS is light or dark mode. Other Fish functions # trigger when this variable changes. We use a universal variable so that all instances of Fish # have the same value for the variable. - set-background-to-macOS = { + set-background-to-macOS.body = '' + # Returns 'Dark' if in dark mode fails otherwise. + if defaults read -g AppleInterfaceStyle &>/dev/null + set -U term_background dark + else + set -U term_background light + end + ''; + + # Set `$term_background` based on an env var. + set-background-to-env = { + argumentNames = [ "env_var" ]; body = '' - # Returns 'Dark' if in dark mode fails otherwise. - if defaults read -g AppleInterfaceStyle &>/dev/null + switch $$env_var + case 1 set -U term_background dark - else + case 0 set -U term_background light end ''; - onVariable = "PWD"; }; # Sets Fish Shell to light or dark colorscheme based on `$term_background`. @@ -211,4 +223,24 @@ # username.style_user = "bold blue"; # don't like the default }; # }}} + + # dark-mode-notify configuration + # {{{ + launchd.enable = true; + launchd.agents.dark-mode-notify = { + enable = true; + config = { + Label = "ke.bou.dark-mode-notify"; + KeepAlive = true; + StandardErrorPath = null; + StandardOutPath = null; + ProgramArguments = [ + "${pkgs.dark-mode-notify}/bin/dark-mode-notify" + "${pkgs.fish}/bin/fish" + "-c" + "set-background-to-env DARKMODE" + ]; + }; + }; + # }}} } diff --git a/pkgs/dark-mode-notify.nix b/pkgs/dark-mode-notify.nix new file mode 100644 index 0000000..bf74da8 --- /dev/null +++ b/pkgs/dark-mode-notify.nix @@ -0,0 +1,26 @@ +{ stdenv +, lib +, xcodeenv +, dark-mode-notify-src +, ... +}: +let + sdkVersion = "13.4.1"; + xcode = xcodeenv.composeXcodeWrapper { + version = sdkVersion; + xcodeBaseDir = "/Applications/Xcode.app"; + }; +in +stdenv.mkDerivation { + name = "dark-mode-notify"; + src = dark-mode-notify-src; + buildPhase = '' + ${xcode}/bin/xcrun swiftc dark-mode-notify.swift -o dark-mode-notify + ''; + installPhase = '' + mkdir -p $out/bin + cp dark-mode-notify $out/bin + ''; + meta.platforms = lib.platforms.darwin; +} +