feat(guix): global npm & conda

This commit is contained in:
Pavel Korytov 2021-07-12 19:32:59 +03:00
parent c138635f6a
commit 342b9f5d48
4 changed files with 156 additions and 36 deletions

View file

@ -27,32 +27,43 @@ done
# Guix settings:1 ends here
# [[file:Console.org::*Guix settings][Guix settings:2]]
if [ -f /run/current-system/profile/etc/profile.d/nix.sh ]; then
. /run/current-system/profile/etc/profile.d/nix.sh
fi
export JUPYTER_CONFIG_DIR=$HOME/.config/jupyter
# Guix settings:2 ends here
# [[file:Console.org::*Guix settings][Guix settings:3]]
export GUIX_PACKAGE_PATH=~/guix-packages
# Guix settings:3 ends here
# [[file:Console.org::*Other package managers][Other package managers:1]]
export XDG_DATA_DIRS="$XDG_DATA_DIRS:$HOME/.local/share/flatpak/exports/share"
# Other package managers:1 ends here
# [[file:Console.org::*Other package managers][Other package managers:2]]
if [ -f /run/current-system/profile/etc/profile.d/nix.sh ]; then
. /run/current-system/profile/etc/profile.d/nix.sh
fi
# Other package managers:2 ends here
# [[file:Console.org::*Other package managers][Other package managers:3]]
if [ -d "$HOME/.guix-extra-profiles/desktop" ]; then
export FONTCONFIG_PATH="$HOME/.guix-extra-profiles/desktop/desktop/etc/fonts"
fi
# Guix settings:3 ends here
# Other package managers:3 ends here
# [[file:Console.org::*Guix settings][Guix settings:4]]
export JUPYTER_CONFIG_DIR=$HOME/.config/jupyter
# Guix settings:4 ends here
# [[file:Console.org::*Guix settings][Guix settings:5]]
export GUIX_PACKAGE_PATH=~/guix-packages
# Guix settings:5 ends here
# [[file:Console.org::*Guix settings][Guix settings:6]]
export XDG_DATA_DIRS="$XDG_DATA_DIRS:$HOME/.local/share/flatpak/exports/share"
# Guix settings:6 ends here
# [[file:Console.org::*Guix settings][Guix settings:7]]
# [[file:Console.org::*Other package managers][Other package managers:4]]
export XDG_DATA_DIRS="$XDG_DATA_DIRS:$HOME/.nix-profile/share/applications"
# Guix settings:7 ends here
# Other package managers:4 ends here
# [[file:Console.org::*npm][npm:2]]
export NPM_CONFIG_USERCONFIG=$HOME/._npmrc
# npm:2 ends here
# [[file:Console.org::*npm][npm:3]]
NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$PATH:$NPM_PACKAGES/bin"
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"
# npm:3 ends here
# [[file:Console.org::*XResources][XResources:1]]
xrdb ~/.Xresources

View file

@ -14,7 +14,12 @@
- [[#contents][Contents]]
- [[#profile][.profile]]
- [[#environment][Environment]]
- [[#various-paths][Various paths]]
- [[#my-paths][My paths]]
- [[#guix-settings][Guix settings]]
- [[#other-package-managers][Other package managers]]
- [[#npm][npm]]
- [[#xresources][XResources]]
- [[#off-package-manager-paths][(OFF) Package manager paths]]
- [[#bash][Bash]]
- [[#bash_profile][.bash_profile]]
- [[#bashrc][.bashrc]]
@ -33,6 +38,8 @@
- [[#copy-to-clipboard][Copy to clipboard]]
- [[#ui][UI]]
- [[#alacritty][Alacritty]]
- [[#various-console-applications][Various console applications]]
- [[#guix-settings][Guix settings]]
:END:
* =.profile=
@ -73,6 +80,23 @@ for i in $GUIX_EXTRA_PROFILES/*; do
done
#+end_src
Set Jupyter config PATH. It defaults to readonly directory somewhere in Guix profile.
#+begin_src sh
export JUPYTER_CONFIG_DIR=$HOME/.config/jupyter
#+end_src
Set a folder for my packages.
#+begin_src sh
export GUIX_PACKAGE_PATH=~/guix-packages
#+end_src
** Other package managers
Using other package managers with Guix requires some extra work.
Make flatpak apps visible to launchers:
#+begin_src sh
export XDG_DATA_DIRS="$XDG_DATA_DIRS:$HOME/.local/share/flatpak/exports/share"
#+end_src
Enable Nix
#+begin_src sh
if [ -f /run/current-system/profile/etc/profile.d/nix.sh ]; then
@ -87,25 +111,34 @@ if [ -d "$HOME/.guix-extra-profiles/desktop" ]; then
fi
#+end_src
Set Jupyter config PATH. It defaults to readonly directory somewhere in Guix profile.
#+begin_src sh
export JUPYTER_CONFIG_DIR=$HOME/.config/jupyter
#+end_src
Set a folder for my packages.
#+begin_src sh
export GUIX_PACKAGE_PATH=~/guix-packages
#+end_src
Make flatpak apps visible to launchers
#+begin_src sh
export XDG_DATA_DIRS="$XDG_DATA_DIRS:$HOME/.local/share/flatpak/exports/share"
#+end_src
Make nix apps visible to launchers
Make nix apps visible to launchers:
#+begin_src sh
export XDG_DATA_DIRS="$XDG_DATA_DIRS:$HOME/.nix-profile/share/applications"
#+end_src
*** npm
npm is especially cumbersome, for instance because by default it tries to install packages to =/gnu/store/=.
In principle, one can set a prefix like this:
#+begin_src conf :tangle ~/._npmrc
prefix=/home/pavel/.npm-packages
#+end_src
But I also want to use node from conda occasionally, where prefix is already set correctly. So instead of tangling the above to the =~/.npmrc= directly, I set an environment variable in the profile:
#+begin_src sh
export NPM_CONFIG_USERCONFIG=$HOME/._npmrc
#+end_src
The variable is unset in a script in [[file:Guix.org::*conda][Guix.org]].
Set PATH & MANPATH
#+begin_src sh
NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$PATH:$NPM_PACKAGES/bin"
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"
#+end_src
** XResources
| Guix dependency |
|-----------------|
@ -307,7 +340,7 @@ if [ -d "/usr/share/fzf" ]; then
fi
#+end_src
*** Aliases
#+begin_src bash :noweb-ref shell-aliases
#+begin_src bash :noweb yes :noweb-ref shell-aliases
alias v="vim"
alias gg="lazygit"
alias ls="exa --icons"

View file

@ -41,6 +41,7 @@ References:
- [[#flatpak][flatpak]]
- [[#conda][conda]]
- [[#slack][Slack]]
- [[#virt-manager][virt-manager]]
- [[#wakatime-cli][wakatime-cli]]
- [[#manifest][Manifest]]
:END:
@ -647,3 +648,42 @@ System
'(
<<packages("system")>>))
#+end_src
Finally, I also want to have an ability to use global npm. Some settings for that are located in [[file:Console::*npm][Console.org]]. Here we want to unset =NPM_CONFIG_USERCONFIG= if there is npm available in the environment.
So here is a script to set up conda hooks:
#+begin_src bash :tangle ~/bin/scripts/setup-conda-npm
# Get writable conda envs with npm & without
readarray -t CONDA_ENVS_ALL <<< $(conda env list --json | jq '.envs[]')
CONDA_ENVS_NPM=()
CONDA_ENVS_NO_NPM=()
for env in "${CONDA_ENVS_ALL[@]}"; do
env="${env:1:${#env}-2}"
if [ -w "$env" ]; then
if [ -f "$env/bin/npm" ]; then
CONDA_ENVS_NPM+=($env)
else
CONDA_ENVS_NO_NPM+=($env)
fi
fi
done
for env in "${CONDA_ENVS_NPM[@]}"; do
echo "Found npm in $env"
mkdir -p "$env/etc/conda/activate.d"
mkdir -p "$env/etc/conda/deactivate.d"
echo "unset NPM_CONFIG_USERCONFIG" > "$env/etc/conda/activate.d/conda.sh"
echo "set -e NPM_CONFIG_USERCONFIG" > "$env/etc/conda/activate.d/conda.fish"
echo "export NPM_CONFIG_USERCONFIG=$HOME/._npmrc" > "$env/etc/conda/deactivate.d/conda.sh"
echo "export NPM_CONFIG_USERCONFIG=$HOME/._npmrc" > "$env/etc/conda/deactivate.d/conda.fish"
done
for env in "${CONDA_ENVS_NO_NPM}"; do
echo "Did not found npm in $env"
rm -rf "$env/etc/conda/activate.d/conda.sh" || true
rm -rf "$env/etc/conda/activate.d/conda.fish" || true
rm -rf "$env/etc/conda/deactivate.d/conda.sh" || true
rm -rf "$env/etc/conda/deactivate.d/conda.fish" || true
done
#+end_src

36
bin/scripts/setup-conda-npm Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# [[file:../../Guix.org::*Manifest][Manifest:3]]
# Get writable conda envs with npm & without
readarray -t CONDA_ENVS_ALL <<< $(conda env list --json | jq '.envs[]')
CONDA_ENVS_NPM=()
CONDA_ENVS_NO_NPM=()
for env in "${CONDA_ENVS_ALL[@]}"; do
env="${env:1:${#env}-2}"
if [ -w "$env" ]; then
if [ -f "$env/bin/npm" ]; then
CONDA_ENVS_NPM+=($env)
else
CONDA_ENVS_NO_NPM+=($env)
fi
fi
done
for env in "${CONDA_ENVS_NPM[@]}"; do
echo "Found npm in $env"
mkdir -p "$env/etc/conda/activate.d"
mkdir -p "$env/etc/conda/deactivate.d"
echo "unset NPM_CONFIG_USERCONFIG" > "$env/etc/conda/activate.d/conda.sh"
echo "set -e NPM_CONFIG_USERCONFIG" > "$env/etc/conda/activate.d/conda.fish"
echo "export NPM_CONFIG_USERCONFIG=$HOME/._npmrc" > "$env/etc/conda/deactivate.d/conda.sh"
echo "export NPM_CONFIG_USERCONFIG=$HOME/._npmrc" > "$env/etc/conda/deactivate.d/conda.fish"
done
for env in "${CONDA_ENVS_NO_NPM}"; do
echo "Did not found npm in $env"
rm -rf "$env/etc/conda/activate.d/conda.sh" || true
rm -rf "$env/etc/conda/activate.d/conda.fish" || true
rm -rf "$env/etc/conda/deactivate.d/conda.sh" || true
rm -rf "$env/etc/conda/deactivate.d/conda.fish" || true
done
# Manifest:3 ends here