Skip to content

Commit

Permalink
Automate toggling the system theme
Browse files Browse the repository at this point in the history
  • Loading branch information
addisonbeck committed Nov 12, 2024
1 parent 573b34d commit 98166d7
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 51 deletions.
1 change: 1 addition & 0 deletions config/system-theme.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"light"
28 changes: 25 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
inherit (self) outputs;
supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
forAllSystemTypes = fn: nixpkgs.lib.genAttrs supportedSystems fn;
systemTheme = import ./config/system-theme.nix;
rootPath = ./.;
in {
nixosConfigurations = {
minecraft = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = {
inherit inputs outputs nixpkgs;
inherit inputs outputs nixpkgs rootPath systemTheme;
pkgs-forked = import inputs.nixpkgs-forked {
system = "x86_64-linux";
config.allowUnfree = true;
Expand All @@ -64,7 +66,8 @@
bw = nix-darwin.lib.darwinSystem {
system = "aarch64-darwin";
specialArgs = {
inherit inputs outputs nixpkgs;
inherit inputs outputs nixpkgs rootPath systemTheme;
hostname = "bw";
pkgs-forked = import inputs.nixpkgs-forked {
system = "aarch64-darwin";
config.allowUnfree = true;
Expand All @@ -82,7 +85,8 @@
air = nix-darwin.lib.darwinSystem {
system = "aarch64-darwin";
specialArgs = {
inherit inputs outputs nixpkgs;
inherit inputs outputs nixpkgs rootPath systemTheme;
hostname = "air";
pkgs-forked = import inputs.nixpkgs-forked {
system = "aarch64-darwin";
config.allowUnfree = true;
Expand Down Expand Up @@ -156,6 +160,24 @@
pkgs.nixd
];
};
toggle-theme = let
newSystemTheme = if systemTheme == "dark"
then { name = "light"; darwinBool = "false"; }
else { name = "dark"; darwinBool = "true"; };
in pkgs.mkShell {
inputsFrom = with self.devShells.${system}; [
building
];
packages = [
(pkgs.writeScriptBin "nix-toggle-theme" ''
cd ~/nix
echo "\"${newSystemTheme.name}\"" > "config/system-theme.nix"
osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to ${newSystemTheme.darwinBool}'
rebuild $1
kill -SIGUSR1 $KITTY_PID
'')
];
};
});
};
}
6 changes: 5 additions & 1 deletion system/with/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
outputs,
nixpkgs,
pkgs-forked,
rootPath,
systemTheme,
hostname,
...
}: {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = false;
home-manager.extraSpecialArgs = {inherit inputs outputs nixpkgs pkgs-forked;};
home-manager.extraSpecialArgs = {inherit inputs outputs nixpkgs pkgs-forked
rootPath systemTheme hostname;};
}
1 change: 1 addition & 0 deletions system/with/user/me.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
#./with/program/opentoonz.nix <- This doesn't work
./with/program/gimp.nix
./with/program/audacity.nix
./with/program/toggle-theme.nix
];

home.sessionPath = [];
Expand Down
4 changes: 2 additions & 2 deletions system/with/user/with/program/neovim/colors/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{...}: {
{systemTheme, ...}: {
options = {
background = "dark";
background = "${systemTheme}";
termguicolors = false;
};
highlights = {
Expand Down
78 changes: 35 additions & 43 deletions system/with/user/with/program/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,61 @@
pkgs,
lib,
inputs,
systemTheme,
...
}: let
options =
(
import ./options {}
)
// (
(import ./colors {}).options
(import ./colors { inherit systemTheme; }).options
);
in {
programs.nixvim = {
enable = true;
vimAlias = true;
opts = options;
highlight = (import ./colors {}).highlights;
colorschemes = (import ./colors {}).colorscheme;
highlightOverride = (import ./colors {}).highlightOverrides;

highlight = (import ./colors { inherit systemTheme; }).highlights;
colorschemes = (import ./colors { inherit systemTheme; }).colorscheme;
highlightOverride = (import ./colors { inherit systemTheme; }).highlightOverrides;
plugins = ((import ./plugins { inherit inputs pkgs; }).plugins);
extraPlugins = ((import ./plugins { inherit inputs pkgs; }).extraPlugins);
autoCmd = ((import ./auto-commands {}).autoCommands);
keymaps =
[
# Custom nixvim style keymaps can be added here if needed, but I
# stick to using `mkVimKeymaps` and the `commands` data structure it
# references.
]
++ (import ./commands {inherit lib;}).keymaps;
userCommands =
{
# Custom nixvim style commands can be added here if needed, but I
# stick to using `mkVimUserCommand` and the `commands` data structure
# it references.
}
// (import ./commands {inherit lib;}).userCommands;
diagnostics = {
signs = false;
underline = true;
update_in_insert = false;
float = {
focused = false;
style = "minimal";
border = "rounded";
source = "always";
header = "";
prefix = "";
};
};
globals.netrw_banner = 0;
# very cool

extraConfigVim = ''
set laststatus=0
hi! link StatusLine Normal
hi! link StatusLineNC Normal
set statusline=%{repeat('─',winwidth('.'))}
'';


extraConfigLua = ''
require('where-am-i').setup({
features = {
Expand Down Expand Up @@ -130,39 +156,5 @@ in {
italic = true,
})
'';
diagnostics = {
signs = false;
underline = true;
update_in_insert = false;
float = {
focused = false;
style = "minimal";
border = "rounded";
source = "always";
header = "";
prefix = "";
};
};

plugins = ((import ./plugins { inherit inputs pkgs; }).plugins);
extraPlugins = ((import ./plugins { inherit inputs pkgs; }).extraPlugins);

autoCmd = ((import ./auto-commands {}).autoCommands);

keymaps =
[
# Custom nixvim style keymaps can be added here if needed, but I
# stick to using `mkVimKeymaps` and the `commands` data structure it
# references.
]
++ (import ./commands {inherit lib;}).keymaps;

userCommands =
{
# Custom nixvim style commands can be added here if needed, but I
# stick to using `mkVimUserCommand` and the `commands` data structure
# it references.
}
// (import ./commands {inherit lib;}).userCommands;
};
}
4 changes: 2 additions & 2 deletions system/with/user/with/program/stylix.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{pkgs, ...}: {
{pkgs, systemTheme, ...}: {
stylix.enable = true;
stylix.image = ../wallpaper/empty.png;
stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-hard.yaml";
stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-${systemTheme}-hard.yaml";

stylix.fonts = {
serif = {
Expand Down
10 changes: 10 additions & 0 deletions system/with/user/with/program/toggle-theme.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#defaults write -g NSRequiresAquaSystemAppearance -bool ${newSystemTheme.darwinBool}
{pkgs, hostname, ...}: {
home.packages = [
(pkgs.writeShellScriptBin "toggle-theme" ''
cd ~/nix
nix develop .#toggle-theme --command nix-toggle-theme ${hostname}
'')
];
}

0 comments on commit 98166d7

Please sign in to comment.