home: create 'modules/home' folder
Consolidating all modules under the same path, to clear out the top-level directory.
This commit is contained in:
parent
c856933803
commit
65a8f7c481
119 changed files with 2 additions and 2 deletions
69
modules/home/direnv/lib/nix.sh
Normal file
69
modules/home/direnv/lib/nix.sh
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#shellcheck shell=bash
|
||||
|
||||
use_pkgs() {
|
||||
if ! has nix; then
|
||||
# shellcheck disable=2016
|
||||
log_error 'use_pkgs: `nix` is not in PATH'
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Use user-provided default value, or fallback to nixpkgs
|
||||
local DEFAULT_FLAKE="${DIRENV_DEFAULT_FLAKE:-nixpkgs}"
|
||||
# Additional args that should be forwarded to `nix`
|
||||
local args=()
|
||||
|
||||
# Allow changing the default flake through a command line switch
|
||||
while true; do
|
||||
case "$1" in
|
||||
-b|--broken)
|
||||
args+=(--impure)
|
||||
export NIXPKGS_ALLOW_BROKEN=1
|
||||
shift
|
||||
;;
|
||||
-f|--flake)
|
||||
DEFAULT_FLAKE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-i|--impure)
|
||||
args+=(--impure)
|
||||
shift
|
||||
;;
|
||||
-s|--insecure)
|
||||
args+=(--impure)
|
||||
export NIXPKGS_ALLOW_INSECURE=1
|
||||
shift
|
||||
;;
|
||||
-u|--unfree)
|
||||
args+=(--impure)
|
||||
export NIXPKGS_ALLOW_UNFREE=1
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
# Allow specifying a full installable, or just a package name and use the default flake
|
||||
local packages=()
|
||||
for pkg; do
|
||||
if [[ $pkg =~ .*#.* ]]; then
|
||||
packages+=("$pkg")
|
||||
else
|
||||
packages+=("$DEFAULT_FLAKE#$pkg")
|
||||
fi
|
||||
done
|
||||
|
||||
# shellcheck disable=2154
|
||||
direnv_load nix shell "${args[@]}" "${packages[@]}" --command "$direnv" dump
|
||||
|
||||
# Clean-up after ourselves (assumes the user does not set them before us)
|
||||
unset NIXPKGS_ALLOW_BROKEN
|
||||
unset NIXPKGS_ALLOW_INSECURE
|
||||
unset NIXPKGS_ALLOW_UNFREE
|
||||
}
|
||||
22
modules/home/direnv/lib/postgres.sh
Normal file
22
modules/home/direnv/lib/postgres.sh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#shellcheck shell=bash
|
||||
|
||||
layout_postgres() {
|
||||
if ! has postgres || ! has initdb; then
|
||||
# shellcheck disable=2016
|
||||
log_error 'layout_postgres: `postgres` and `initdb` are not in PATH'
|
||||
return 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=2155
|
||||
export PGDATA="$(direnv_layout_dir)/postgres"
|
||||
export PGHOST="$PGDATA"
|
||||
|
||||
if [[ ! -d "$PGDATA" ]]; then
|
||||
initdb
|
||||
cat >> "$PGDATA/postgresql.conf" << EOF
|
||||
listen_addresses = ''
|
||||
unix_socket_directories = '$PGHOST'
|
||||
EOF
|
||||
echo "CREATE DATABASE $USER;" | postgres --single -E postgres
|
||||
fi
|
||||
}
|
||||
25
modules/home/direnv/lib/python.sh
Normal file
25
modules/home/direnv/lib/python.sh
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#shellcheck shell=bash
|
||||
|
||||
layout_poetry() {
|
||||
if ! has poetry; then
|
||||
# shellcheck disable=2016
|
||||
log_error 'layout_poetry: `poetry` is not in PATH'
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ ! -f pyproject.toml ]]; then
|
||||
# shellcheck disable=2016
|
||||
log_error 'layout_poetry: no pyproject.toml found. Use `poetry new` or `poetry init` to create one first'
|
||||
return 1
|
||||
fi
|
||||
|
||||
# create venv if it doesn't exist
|
||||
poetry run true
|
||||
|
||||
# shellcheck disable=2155
|
||||
export VIRTUAL_ENV=$(poetry env info --path)
|
||||
export POETRY_ACTIVE=1
|
||||
PATH_add "$VIRTUAL_ENV/bin"
|
||||
watch_file pyproject.toml
|
||||
watch_file poetry.lock
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue