dot_direnvrc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. # -*- mode: Sh; fill-column: 78; -*-
  2. export_function()
  3. {
  4. local name=$1
  5. local alias_dir=$PWD/.direnv/aliases
  6. mkdir -p "$alias_dir"
  7. PATH_add "$alias_dir"
  8. local target="$alias_dir/$name"
  9. if declare -f "$name" >/dev/null; then
  10. echo "#!$SHELL" > "$target"
  11. declare -f "$name" >> "$target" 2>/dev/null
  12. # Notice that we add shell variables to the function trigger.
  13. echo "$name \$*" >> "$target"
  14. chmod +x "$target"
  15. fi
  16. }
  17. use_haunt()
  18. {
  19. gcroot="${HOME}/.config/guix/gcroots/haunt"
  20. if [ -L "$gcroot" ]
  21. then
  22. rm -v "$gcroot"
  23. fi
  24. PACKAGES_MAINTENANCE=(direnv git sshpass password-store less openssh gnupg)
  25. PACKAGES=(bash coreutils grep findutils which)
  26. eval "$(guix time-machine --channels="${HOME}/.local/share/chezmoi/dotfiles/channels-current-guix-image-workstation.scm" -- environment --search-paths --root="$gcroot" --pure --load=guix.scm --ad-hoc ${PACKAGES[@]} ${PACKAGES_MAINTENANCE[@]} "$@")"
  27. }
  28. use_guix()
  29. {
  30. GUIX_GITHUB_TOKEN="$(pass show github/tokens/GUIX_GITHUB_TOKEN)"
  31. export GUIX_GITHUB_TOKEN
  32. GUIX_PACKAGE_PATH=""
  33. export GUIX_PACKAGE_PATH
  34. packages_maintenance=(
  35. direnv
  36. git
  37. git:send-email
  38. git-cal
  39. gnupg
  40. guile-colorized
  41. guile-readline
  42. inetutils
  43. less
  44. ncurses
  45. openssh
  46. password-store
  47. sshpass
  48. which
  49. )
  50. export ENV_PACKAGES_MAINTENANCE="${packages_maintenance[@]}"
  51. packages=(help2man guile-sqlite3 guile-gcrypt)
  52. export ENV_PACKAGES="${packages[@]}"
  53. GIT_SSL_CAINFO=/run/current-system/profile/etc/ssl/certs/ca-certificates.crt
  54. export GIT_SSL_CAINFO
  55. SSL_CERT_DIR=/etc/ssl/certs
  56. export SSL_CERT_DIR
  57. NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
  58. export NIX_SSL_CERT_FILE
  59. SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
  60. export SSL_CERT_FILE
  61. # https://lists.gnu.org/archive/html/guix-devel/2016-09/msg00859.html
  62. environment()
  63. {
  64. set -x
  65. case "$1" in
  66. build)
  67. guix time-machine --channels="${HOME}/.local/share/chezmoi/dotfiles/channels-current-guix-image-workstation.scm" -- environment --pure guix --ad-hoc ${ENV_PACKAGES[@]} ${ENV_PACKAGES_MAINTENANCE[@]} -- .direnv/aliases/build
  68. ;;
  69. *)
  70. guix time-machine --channels="${HOME}/.local/share/chezmoi/dotfiles/channels-current-guix-image-workstation.scm" -- environment --pure guix --ad-hoc ${ENV_PACKAGES[@]} ${ENV_PACKAGES_MAINTENANCE[@]} "$@"
  71. ;;
  72. esac
  73. }
  74. export_function environment
  75. repl()
  76. {
  77. set -x
  78. ./pre-inst-env guix repl -L "$(./pre-inst-env guix build emacs-geiser)"/share/geiser/guile
  79. }
  80. export_function repl
  81. configure()
  82. {
  83. ./configure --localstatedir=/var --prefix=
  84. }
  85. export_function configure
  86. build()
  87. {
  88. make -k -j "$(nproc)"
  89. if [ $# -gt 0 ]
  90. then
  91. case "$1" in
  92. refresh)
  93. ./pre-inst-env guix refresh -l "${@:2}" \
  94. | cut -d: -f 2 \
  95. | tr ' ' '\n' \
  96. | cut -d@ -f 1 \
  97. | xargs ./pre-inst-env guix build --no-grafts --no-offload
  98. ;;
  99. *)
  100. ./pre-inst-env guix build --no-grafts --no-offload "$@"
  101. ;;
  102. esac
  103. fi
  104. for file in po/*/*.po
  105. do
  106. git update-index --assume-unchanged "$file"
  107. done
  108. }
  109. export_function build
  110. push()
  111. {
  112. sshpass -Ppassphrase -p"$(pass show localhost/ssh/id_rsa_savannah)" git push --set-upstream origin
  113. }
  114. export_function push
  115. pull()
  116. {
  117. sshpass -Ppassphrase -p"$(pass show localhost/ssh/id_rsa_savannah)" git pull --rebase
  118. }
  119. export_function pull
  120. guix_pull()
  121. {
  122. mkdir -p current
  123. guix pull --profile="${PWD}/current/guix" --url="file://${PWD}" --disable-authentication "$@"
  124. }
  125. export_function guix_pull
  126. shell()
  127. {
  128. guix time-machine --channels="${HOME}/.local/share/chezmoi/dotfiles/channels-current-guix-image-workstation.scm" -- shell ${ENV_PACKAGES[@]} ${ENV_PACKAGES_MAINTENANCE[@]} --development guix "$@"
  129. }
  130. export_function shell
  131. clear
  132. echo "
  133. direnv:
  134. build build a package or just a project if no argument provided
  135. configure run ./configure with predefined parameters
  136. environment WARNING: deprecated: run 'guix environment' with presetted arguments
  137. push push to upstream Git repository
  138. pull pull changes from upstream Git repository
  139. repl run guix repl
  140. shell run 'guix shell' with presetted arguments
  141. guix_pull guix pull current directory
  142. "
  143. export XDG_RUNTIME_DIR="/run/user/$UID"
  144. export EDITOR="$HOME/.guix-profile/bin/emacsclient -nc"
  145. cat <<'EOF'
  146. sudo --login \
  147. GUILE_LOAD_PATH="${HOME}/.local/share/chezmoi/dotfiles/guixsd/modules:${GUILE_LOAD_PATH}" \
  148. "${PWD}/pre-inst-env" guix system build \
  149. --load-path="${HOME}/src/gitlab.com/nonguix/nonguix" \
  150. --load-path="${HOME}/src/cgit.duckdns.org/guix/guix-wigust/guix" \
  151. --load-path="${HOME}/.local/share/chezmoi/dotfiles/guixsd/modules" \
  152. "${HOME}/.local/share/chezmoi/dotfiles/guixsd/guixsd.scm"
  153. EOF
  154. }
  155. use_emacs-guix()
  156. {
  157. gcroot="${HOME}/.config/guix/gcroots/guix"
  158. if [ -L "$gcroot" ]
  159. then
  160. rm -v "$gcroot"
  161. fi
  162. PACKAGES_MAINTENANCE=(
  163. direnv
  164. emacs
  165. git
  166. git-cal
  167. gnupg
  168. guile
  169. guile-colorized
  170. guile-irregex
  171. guile-readline
  172. inetutils
  173. less
  174. ncurses
  175. openssh
  176. password-store
  177. sshpass
  178. st
  179. which
  180. )
  181. PACKAGES=(help2man)
  182. # https://lists.gnu.org/archive/html/guix-devel/2016-09/msg00859.html
  183. eval "$(guix time-machine --channels="${HOME}/.local/share/chezmoi/dotfiles/channels-current-guix-image-workstation.scm" -- environment --search-paths --root="$gcroot" --pure --load=guix.scm --ad-hoc ${PACKAGES[@]} ${PACKAGES_MAINTENANCE[@]} "$@")"
  184. GUILE_LOAD_PATH=$PWD/scheme:$GUILE_LOAD_PATH
  185. export GUILE_LOAD_PATH
  186. GUILE_LOAD_COMPILED_PATH=$PWD/scheme:$GUILE_LOAD_COMPILED_PATH
  187. export GUILE_LOAD_COMPILED_PATH
  188. EMACSLOADPATH="$PWD/elisp:$EMACSLOADPATH"
  189. export EMACSLOADPATH
  190. }
  191. use_dotfiles()
  192. {
  193. check()
  194. {
  195. make check TESTS="tests/connect.bats tests/executables.bats tests/mail.bats tests/mjru.bats" "$@"
  196. }
  197. export_function check
  198. GUILE_LOAD_PATH="${PWD}/dotfiles/guixsd/modules:${GUILE_LOAD_PATH}"
  199. export GUILE_LOAD_PATH
  200. GUIX_PACKAGE_PATH="${PWD}/dotfiles/guixsd/modules:${GUIX_PACKAGE_PATH}"
  201. export GUIX_PACKAGE_PATH
  202. }
  203. use_guile()
  204. {
  205. unset GUIX_PACKAGE_PATH
  206. PACKAGES=(
  207. autoconf
  208. automake
  209. bash
  210. coreutils
  211. flex
  212. gettext
  213. libtool
  214. readline
  215. texinfo
  216. )
  217. PACKAGES_MAINTENANCE=(
  218. direnv
  219. )
  220. gcroot="${HOME}/.config/guix/gcroots/guile"
  221. if [ -L "$gcroot" ]
  222. then
  223. rm -v "$gcroot"
  224. fi
  225. eval "$(guix time-machine --channels="${HOME}/.local/share/chezmoi/dotfiles/channels-current-guix-image-workstation.scm" -- environment --search-paths --root="$gcroot" --pure guile --ad-hoc ${PACKAGES[@]} ${PACKAGES_MAINTENANCE[@]} "$@")"
  226. }
  227. use_fasm()
  228. {
  229. PACKAGES_MAINTENANCE=(bash binutils coreutils direnv)
  230. PACKAGES=(fasm)
  231. eval "$(guix time-machine --channels="${HOME}/.local/share/chezmoi/dotfiles/channels-current-guix-image-workstation.scm" -- environment --search-paths --pure --ad-hoc ${PACKAGES[@]} ${PACKAGES_MAINTENANCE[@]} "$@")"
  232. }
  233. use_artanis()
  234. {
  235. PACKAGES_MAINTENANCE=(bash binutils coreutils direnv)
  236. PACKAGES=(artanis guile@2)
  237. eval "$(guix time-machine --channels="${HOME}/.local/share/chezmoi/dotfiles/channels-current-guix-image-workstation.scm" -- environment --search-paths --pure --ad-hoc ${PACKAGES[@]} ${PACKAGES_MAINTENANCE[@]} "$@")"
  238. }
  239. use_mjru_ci_jenkins()
  240. {
  241. jenkins-jobs()
  242. {
  243. export PYTHONPATH=''
  244. "$HOME/.nix-profile/bin/jenkins-jobs" --conf "$HOME/.config/jenkins_jobs/jenkins_jobs_majordomo.ini" "$@"
  245. }
  246. export_function jenkins-jobs
  247. }
  248. use_mjru_nix()
  249. {
  250. export NIX_ARGS
  251. nix-build()
  252. {
  253. "$HOME/.nix-profile/bin/nix-build" "${NIX_ARGS[@]}" "$@"
  254. }
  255. export_function nix-build
  256. nix-instantiate()
  257. {
  258. "$HOME/.nix-profile/bin/nix-instantiate" "${NIX_ARGS[@]}" "$@"
  259. }
  260. export_function nix-instantiate
  261. nix-shell()
  262. {
  263. NIX_ARGS=("--no-out-link"
  264. "--option" "trusted-public-keys" "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.nixos.intr:6VD7bofl5zZFTEwsIDsUypprsgl7r9I+7OGY4WsubFA="
  265. "--option" "builders" "ssh://nixos.intr x86_64-linux"
  266. "--substituters" "https://cache.nixos.org/ https://cache.nixos.intr/")
  267. "$HOME/.nix-profile/bin/nix-shell" "${NIX_ARGS[@]}" "$@"
  268. }
  269. export_function nix-shell
  270. }
  271. use_nixpkgs()
  272. {
  273. echo '+/home/oleg/src/nixpkgs' > .dumbjump
  274. }