Skip to content

Instantly share code, notes, and snippets.

@chisui
Last active October 16, 2018 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chisui/bba90fccc930f614743dc259fbadae6d to your computer and use it in GitHub Desktop.
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`
{ 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!";
'';
};
}
{ 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