feat: rearrange home-manager modules
This commit is contained in:
parent
89f6ab94b4
commit
58eae1d229
21 changed files with 44 additions and 30 deletions
home/shell
62
home/shell/.direnvrc
Normal file
62
home/shell/.direnvrc
Normal file
|
@ -0,0 +1,62 @@
|
|||
use_nix() {
|
||||
local path="$(nix-instantiate --find-file nixpkgs)"
|
||||
|
||||
if [ -f "${path}/.version-suffix" ]; then
|
||||
local version="$(< $path/.version-suffix)"
|
||||
elif [ -f "${path}/.git" ]; then
|
||||
local version="$(< $(< ${path}/.git/HEAD))"
|
||||
fi
|
||||
|
||||
local cache=".direnv/cache-${version:-unknown}"
|
||||
|
||||
local update_drv=0
|
||||
if [[ ! -e "$cache" ]] || \
|
||||
[[ "$HOME/.direnvrc" -nt "$cache" ]] || \
|
||||
[[ .envrc -nt "$cache" ]] || \
|
||||
[[ default.nix -nt "$cache" ]] || \
|
||||
[[ shell.nix -nt "$cache" ]];
|
||||
then
|
||||
[ -d .direnv ] || mkdir .direnv
|
||||
nix-shell --show-trace --pure "$@" --run "\"$direnv\" dump bash" > "$cache"
|
||||
update_drv=1
|
||||
else
|
||||
log_status using cached derivation
|
||||
fi
|
||||
local term_backup=$TERM path_backup=$PATH
|
||||
if ! [ -z ${TMPDIR+x} ]; then
|
||||
local tmp_backup=$TMPDIR
|
||||
fi
|
||||
|
||||
eval "$(< $cache)"
|
||||
export PATH=$PATH:$path_backup TERM=$term_backup TMPDIR=$tmp_backup
|
||||
if ! [ -z ${tmp_backup+x} ]; then
|
||||
export TMPDIR=${tmp_backup}
|
||||
else
|
||||
unset TMPDIR
|
||||
fi
|
||||
|
||||
# `nix-shell --pure` sets invalid ssl certificate paths
|
||||
if [ "${SSL_CERT_FILE:-}" = /no-cert-file.crt ]; then
|
||||
unset SSL_CERT_FILE
|
||||
fi
|
||||
if [ "${NIX_SSL_CERT_FILE:-}" = /no-cert-file.crt ]; then
|
||||
unset NIX_SSL_CERT_FILE
|
||||
fi
|
||||
|
||||
# This part is based on https://discourse.nixos.org/t/what-is-the-best-dev-workflow-around-nix-shell/418/4
|
||||
if [ "$out" ] && (( $update_drv )); then
|
||||
local drv_link=".direnv/drv"
|
||||
local drv="$(nix show-derivation $out | grep -E -o -m1 '/nix/store/.*.drv')"
|
||||
local stripped_pwd=${PWD/\//}
|
||||
local escaped_pwd=${stripped_pwd//-/--}
|
||||
local escaped_pwd=${escaped_pwd//\//-}
|
||||
ln -fs "$drv" "$drv_link"
|
||||
ln -fs "$PWD/$drv_link" "/nix/var/nix/gcroots/per-user/$LOGNAME/$escaped_pwd"
|
||||
log_status renewed cache and derivation link
|
||||
fi
|
||||
|
||||
if [[ $# = 0 ]]; then
|
||||
watch_file default.nix
|
||||
watch_file shell.nix
|
||||
fi
|
||||
}
|
8
home/shell/default.nix
Normal file
8
home/shell/default.nix
Normal file
|
@ -0,0 +1,8 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
./shell.nix
|
||||
./direnv.nix
|
||||
];
|
||||
}
|
15
home/shell/direnv.nix
Normal file
15
home/shell/direnv.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
with pkgs;
|
||||
{
|
||||
programs.direnv = {
|
||||
enable = true;
|
||||
enableBashIntegration = true;
|
||||
enableFishIntegration = true;
|
||||
stdlib = builtins.readFile ./.direnvrc;
|
||||
};
|
||||
|
||||
home.file.".envrc".text = ''
|
||||
dotenv
|
||||
'';
|
||||
}
|
21
home/shell/shell.nix
Normal file
21
home/shell/shell.nix
Normal file
|
@ -0,0 +1,21 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
shellAliases = {
|
||||
emacs = "emacsclient -c";
|
||||
};
|
||||
in
|
||||
{
|
||||
programs.fish = {
|
||||
enable = true;
|
||||
shellInit = ''
|
||||
fish_vi_key_bindings
|
||||
'';
|
||||
inherit shellAliases;
|
||||
};
|
||||
|
||||
programs.bash = {
|
||||
enable = true;
|
||||
inherit shellAliases;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue