Last active
October 16, 2018 10:45
-
-
Save chisui/bba90fccc930f614743dc259fbadae6d to your computer and use it in GitHub Desktop.
nix file that provides a way to inject zsh dotfiles inside of a `shellHook`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} | |
, zdotdir ? import (builtins.fetchurl { | |
url = "https://gist.githubusercontent.com/chisui/bba90fccc930f614743dc259fbadae6d/raw/4108222addc1d646c1b0a6d12130083e2219ad28/zdotdir.nix"; | |
}) { inherit pkgs; } | |
}: | |
pkgs.stdenv.mkDerivation { | |
name = "withZshEnv"; | |
shellHook = zdotdir { | |
zshenv = '' | |
alias taco=echo\ "tacos!"; | |
''; | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} | |
}: | |
{ zshenv ? "" | |
, zshrc ? "" | |
}: | |
let | |
mkZshDotFile = fileName: content: builtins.toFile "custom.${fileName}" '' | |
if [ -z $\{ZDOTDIR_PARENT\} ]; | |
then | |
DOTFILE=$ZDOTDIR_PARENT/.${fileName}; | |
else | |
DOTFILE=$HOME/.${fileName}; | |
fi; | |
if [ -f $DOTFILE ]; | |
then | |
source $DOTFILE; | |
fi; | |
${content} | |
''; | |
zDotDir = pkgs.stdenv.mkDerivation { | |
name = "ZDOTDIR"; | |
phases = ["installPhase"]; | |
installPhase = '' | |
mkdir $out | |
cp ${mkZshDotFile "zshenv" zshenv} $out/.zshenv | |
cp ${mkZshDotFile "zshrc" zshrc} $out/.zshrc | |
''; | |
}; | |
in '' | |
if [[ -v ZDOTDIR ]]; | |
then | |
export ZDOTDIR_PARENT=$ZDOTDIR; | |
fi | |
export ZDOTDIR=${zDotDir}; | |
'' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment