Skip to content

Instantly share code, notes, and snippets.

@damianbaar
Last active February 2, 2022 15:00
Show Gist options
  • Save damianbaar/57aff242d06c75444dbd36bf5400060e to your computer and use it in GitHub Desktop.
Save damianbaar/57aff242d06c75444dbd36bf5400060e to your computer and use it in GitHub Desktop.
nix expression that provides a way to copy your zsh configuration files
{ pkgs ? import <nixpkgs> {}
, zdotdir ? import (builtins.fetchurl {
url = "https://gist.githubusercontent.com/damianbaar/57aff242d06c75444dbd36bf5400060e/raw/83d074d45c81a18402146cadc595a20b91bb1985/zdotdir.nix";
}) { inherit pkgs; }
}:
pkgs.stdenv.mkDerivation {
name = "withZshEnv";
shellHook= zdotdir {
zshenv = builtins.path { path = ./zdotdir/zshenv; };
zshrc = builtins.path { path = ./zdotdir/zshrc; };
shellHook= ''
echo "welcome welcome"
'';
};
}
{ pkgs ? import <nixpkgs> {}
, lib ? import <nixpkgs/lib>
}:
{ zshenv ? ""
, zshrc ? ""
, shellHook ? ""
}:
let
getContentOfFile = content:
if lib.strings.isStorePath content
then builtins.readFile content
else content;
mkZshDotFile = fileName: content: builtins.toFile fileName content;
zshrcContent = getContentOfFile zshrc;
zshenvContent = getContentOfFile zshenv;
zDotDir = pkgs.stdenv.mkDerivation {
name = "ZDOTDIR";
phases = ["installPhase"];
installPhase = ''
mkdir $out
cp ${mkZshDotFile "zshenv" zshenvContent} $out/.zshenv
cp ${mkZshDotFile "zshrc" zshrcContent} $out/.zshrc
'';
};
in ''
export ZDOTDIR=${zDotDir}
${shellHook}
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment