From 25e6aecd5c51ded411bb600da70c260a813f2e66 Mon Sep 17 00:00:00 2001 From: mat ess Date: Mon, 28 Nov 2022 16:55:43 -0500 Subject: [PATCH] Add helix theme switching --- darwin/bootstrap.nix | 4 +- flake.nix | 5 ++- home/fish.nix | 2 +- home/helix.nix | 30 +++++++++++++++ home/programs.nix | 12 +----- modules/home/programs/helix/extras.nix | 48 ++++++++++++++++++++++++ modules/home/programs/kakoune/extras.nix | 2 - 7 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 home/helix.nix create mode 100644 modules/home/programs/helix/extras.nix diff --git a/darwin/bootstrap.nix b/darwin/bootstrap.nix index 308179e..b634e15 100644 --- a/darwin/bootstrap.nix +++ b/darwin/bootstrap.nix @@ -52,8 +52,8 @@ end end ''; - environment.variables.SHELL = "${pkgs.fish}/bin/fish"; - environment.loginShell = "${pkgs.fish}/bin/fish"; + environment.variables.SHELL = "/run/current-system/sw/bin/fish"; + environment.loginShell = "/run/current-system/sw/bin/fish"; # Install and setup ZSH to work with nix(-darwin) as well programs.zsh.enable = true; diff --git a/flake.nix b/flake.nix index 5a4062c..e217b6f 100644 --- a/flake.nix +++ b/flake.nix @@ -287,6 +287,7 @@ files = import ./home/files.nix; fish = import ./home/fish.nix; git = import ./home/git.nix; + helix = import ./home/helix.nix; kitty = import ./home/kitty.nix; programs = import ./home/programs.nix; starship = import ./home/starship.nix; @@ -298,8 +299,8 @@ darwin.fullCopies = true; }; # modules - # TODO: migrate to helix - # programs-kakoune-extras = import ./modules/home/programs/kakoune/extras.nix; + programs-kakoune-extras = import ./modules/home/programs/kakoune/extras.nix; # currently unused + programs-helix-extras = import ./modules/home/programs/helix/extras.nix; programs-kitty-extras = import ./modules/home/programs/kitty/extras.nix; home-primary-user = { lib, ... }: { options.home.primaryUser = diff --git a/home/fish.nix b/home/fish.nix index f4e373a..98a8112 100644 --- a/home/fish.nix +++ b/home/fish.nix @@ -15,7 +15,7 @@ } ]; - home.file."${config.xdg.configHome}/fish/fish_plugins".text = '' + xdg.configFile."fish/fish_plugins".text = '' jorgebucaran/autopair.fish jorgebucaran/replay.fish jorgebucaran/getopts.fish diff --git a/home/helix.nix b/home/helix.nix new file mode 100644 index 0000000..a8d58e3 --- /dev/null +++ b/home/helix.nix @@ -0,0 +1,30 @@ +{ pkgs, ... }: + +{ + programs.helix.enable = true; + + programs.helix.package = pkgs.helix-flake; + + programs.helix.settings = { + editor.bufferline = "multiple"; + editor.color-modes = true; + editor.indent-guides.render = true; + editor.indent-guides.skip-levels = 1; + editor.line-number = "relative"; + editor.whitespace.render = { + space = "none"; + tab = "all"; + newline = "all"; + }; + }; + + programs.helix.extras.autoTheme = { + enable = true; + light = "rose_pine_dawn"; + dark = "rose_pine"; + }; + + home.sessionVariables = { + EDITOR = "hx"; + }; +} diff --git a/home/programs.nix b/home/programs.nix index 3982c0c..9ae78b8 100644 --- a/home/programs.nix +++ b/home/programs.nix @@ -5,9 +5,7 @@ let in { # Programs + packages with configuration --------------------------------------------------------------- {{{ - home.sessionVariables = { - EDITOR = "hx"; - } // lib.optionalAttrs pkgs.stdenv.isDarwin { + home.sessionVariables = lib.optionalAttrs pkgs.stdenv.isDarwin { SSH_AUTH_SOCK = secretiveAuthSocket; }; programs = { @@ -26,14 +24,6 @@ in enable = true; nix-direnv.enable = true; }; - helix = { - enable = true; - package = pkgs.helix-flake; - settings = { - theme = "rose_pine"; - editor.indent-guides.render = true; - }; - }; nix-index = { enable = true; enableFishIntegration = true; diff --git a/modules/home/programs/helix/extras.nix b/modules/home/programs/helix/extras.nix new file mode 100644 index 0000000..aef2888 --- /dev/null +++ b/modules/home/programs/helix/extras.nix @@ -0,0 +1,48 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.helix; + inherit (cfg) extras; + tomlFormat = pkgs.formats.toml { }; + inherit (lib) mkIf mkEnableOption mkOption types; +in +{ + options.programs.helix.extras = { + autoTheme.enable = mkEnableOption "Automatically switch helix theme with night mode"; + + autoTheme.light = mkOption { + type = types.str; + description = "Light mode theme"; + }; + + autoTheme.dark = mkOption { + type = types.str; + description = "Dark mode theme"; + }; + }; + + config = mkIf (cfg.enable && extras.autoTheme.enable) { + xdg.configFile = { + "helix/light.toml".source = tomlFormat.generate "helix-autotheme" (cfg.settings // { theme = extras.autoTheme.light; }); + "helix/dark.toml".source = tomlFormat.generate "helix-autotheme" (cfg.settings // { theme = extras.autoTheme.dark; }); + }; + + programs.fish.shellAbbrs = { + hxl = "${cfg.package} --config ${config.xdg.configHome}/helix/light.toml"; + hxd = "${cfg.package} --config ${config.xdg.configHome}/helix/dark.toml"; + }; + + programs.fish.functions = { + hx = { + description = "Helix invocation wrapper to automatically select the right theme"; + body = '' + if is-dark-mode + hxd $argv + else + hxl $argv + end + ''; + }; + }; + }; +} diff --git a/modules/home/programs/kakoune/extras.nix b/modules/home/programs/kakoune/extras.nix index 7893b18..f7f334d 100644 --- a/modules/home/programs/kakoune/extras.nix +++ b/modules/home/programs/kakoune/extras.nix @@ -1,5 +1,3 @@ -# TODO: migrate this to helix - { config, lib, pkgs, ... }: with lib;