Use dark-mode-notify to tell fish+kitty to update

work
mat ess 2022-07-16 16:34:47 -04:00
parent e83576a183
commit e4359f5245
4 changed files with 96 additions and 11 deletions

View File

@ -1,5 +1,21 @@
{ {
"nodes": { "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": { "darwin": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -123,6 +139,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"dark-mode-notify-src": "dark-mode-notify-src",
"darwin": "darwin", "darwin": "darwin",
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",

View File

@ -16,6 +16,11 @@
# Other sources # Other sources
flake-compat = { url = github:edolstra/flake-compat; flake = false; }; flake-compat = { url = github:edolstra/flake-compat; flake = false; };
flake-utils.url = github:numtide/flake-utils; 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: outputs = { self, darwin, nixpkgs, home-manager, flake-utils, ... }@inputs:
@ -28,12 +33,17 @@
nixpkgsConfig = { nixpkgsConfig = {
config = { allowUnfree = true; }; config = { allowUnfree = true; };
overlays = attrValues self.overlays ++ singleton ( overlays = attrValues self.overlays ++ singleton (
final: prev: optionalAttrs final: prev:
(prev.stdenv.system == "aarch64-darwin")
{ {
# Sub in x86 version of packages that don't build on Apple Silicon yet dark-mode-notify = final.callPackage ./pkgs/dark-mode-notify.nix { inherit (inputs) dark-mode-notify-src; };
inherit (final.pkgs-x86); } // optionalAttrs
} // final.patched (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);
}
); );
}; };

View File

@ -6,7 +6,9 @@
programs.fish.enable = true; programs.fish.enable = true;
# Add Fish plugins # Add Fish plugins
home.packages = with pkgs.fishPlugins; [ done ]; home.packages = with pkgs.fishPlugins; [
done
];
programs.fish.plugins = [ programs.fish.plugins = [
{ {
@ -68,16 +70,26 @@
# Set `$term_background` based on whether macOS is light or dark mode. Other Fish functions # 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 # trigger when this variable changes. We use a universal variable so that all instances of Fish
# have the same value for the variable. # 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 = '' body = ''
# Returns 'Dark' if in dark mode fails otherwise. switch $$env_var
if defaults read -g AppleInterfaceStyle &>/dev/null case 1
set -U term_background dark set -U term_background dark
else case 0
set -U term_background light set -U term_background light
end end
''; '';
onVariable = "PWD";
}; };
# Sets Fish Shell to light or dark colorscheme based on `$term_background`. # 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 # 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"
];
};
};
# }}}
} }

26
pkgs/dark-mode-notify.nix Normal file
View File

@ -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;
}