Last active
April 15, 2020 12:52
-
-
Save Drainful/a3cd702dc590480cf4897a9859fc499f to your computer and use it in GitHub Desktop.
Example shell.nix setting environment variables through emacsHook
This file contains 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
;; direnv (and lorri) are necessary for this to be useful | |
(use-package direnv | |
:config | |
(direnv-mode) | |
;; This advice evaluates the contents of the emacsHook environment | |
;; variable when direnv updates. Note that this runs every time | |
;; direnv-update-directory-environment is called whether or not | |
;; there was a change. | |
(defun run-emacs-hook () | |
(when (getenv "emacsHook") | |
(eval (car (read-from-string | |
(format "(progn %s)" | |
(getenv "emacsHook"))))))) | |
(advice-add 'direnv-update-directory-environment | |
:after | |
#'run-emacs-hook)) | |
;; These are the functions I used to facilitate path manipulation | |
(defun add-to-env (env val) | |
(setenv env (concat (getenv env) val))) | |
(cl-defun add-to-path (paths &optional (env "PATH") (seperator ":")) | |
(dolist (path (split-string paths seperator)) | |
(unless (find-if (lambda (s) | |
(string= s path)) | |
(split-string (getenv env) seperator)) | |
(add-to-env env (concat seperator paths))))) |
This file contains 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
with import <nixpkgs> {}; | |
mkShell rec { | |
name = "Example"; | |
buildInputs = [ | |
love_11 | |
lua51Packages.lua | |
lua51Packages.luarocks | |
lua51Packages.cqueues | |
]; | |
# This allows me to update emacs environment variables (or evaluate other elisp) when direnv updates. | |
emacsHook = '' | |
(add-to-path "/home/adrian/.luarocks/share/lua/5.1/?.lua;/home/adrian/.luarocks/share/lua/5.1/?/init.lua" | |
"LUA_PATH" ";") | |
(add-to-path "/home/adrian/.luarocks/lib/lua/5.1/?.so" | |
"LUA_CPATH" ";") | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment