Compare commits

..

92 Commits

Author SHA1 Message Date
e8fca12861 Prototype for trying out blesh 2025-10-12 17:54:04 -04:00
anmiller
d67b07d275 Only source direnv if it hasn't already been sourced 2025-08-12 21:41:58 +00:00
anmiller
dda5fcc784 Update prompt manipulation with functions! 2025-08-12 21:41:41 +00:00
b66b03bc78 Fix nix installer 2025-05-23 14:05:57 +00:00
da7a244f95 Fix nix installer up 2025-05-20 18:45:04 +00:00
4a461eb974 More specifically identify if nix is installed 2025-05-20 18:03:39 +00:00
a6257ed7d1 Pass through shell environment variable 2025-05-12 23:24:15 -04:00
d487ade6f2 Add vim-helm for helm file detection 2025-05-01 18:46:29 +00:00
e24e8a1c49 Add prompt generation commands for git/kubernetes 2025-04-08 15:29:36 +00:00
b1f6fc2f52 Turns out I didn't need to do all that 2025-04-05 16:38:28 -04:00
0f8a05b561 Add bash completion sourcing, with cache 2025-04-05 16:38:28 -04:00
5f75d539b5 Fix kubeconfig xdg confg 2025-04-05 16:38:28 -04:00
dae19a88b4 Add script to symlink to old paths for legacy support 2025-04-05 16:38:28 -04:00
6d78938056 XDGify kubernetes config 2025-04-05 16:38:28 -04:00
6876cad10b Support nix XDG pathing 2025-04-05 16:38:28 -04:00
3583770d94 Add XDG support 2025-04-05 16:38:28 -04:00
ddf5d19c51 Add gitconfig in xdg location
Recommendations came from this blog post:
    https://blog.gitbutler.com/how-git-core-devs-configure-git/

Let's see how this works out lol

Test
2025-04-05 16:38:28 -04:00
86b85c4102 Add xdg-utils 2025-04-05 16:38:28 -04:00
b0aba1f3e1 Make screen default to bash explicitly
Implictly I've never needed this as my user shell has always been bash
but in some containers recently the default shell is /bin/sh
2025-04-05 16:38:28 -04:00
033500c6bb Remove vim classic and add screen to standard utils 2025-04-05 16:38:28 -04:00
b3ac2a57df Re-enable slow packages that have to be compiled from source 2025-04-05 16:38:28 -04:00
cd4488ff24 Update nix to 2.24.12 which is the current stable 2025-04-05 16:38:28 -04:00
189acc497d Source nix profile after installing nix 2025-04-05 16:38:28 -04:00
9016dfdaf3 Update dotfile application to check for prereqs 2025-04-05 16:38:28 -04:00
c3a9ed26f7 Refactor profile flake installer
Add support for exporting to archive.nar
Add support for importing from an archive.nar
Add simple support for adding a flake.lock
2025-04-05 16:38:28 -04:00
29db01cdd6 Conditionally source nix-profile if needed on non-nixos machines 2025-04-05 16:38:28 -04:00
93a2836154 Refactor code so coder_template_type is considered 2025-04-05 16:38:28 -04:00
9fadf8b26f In a devcontainer setup install nix packages 2025-04-05 16:38:28 -04:00
f080a6cd5a Add distrobox 2025-04-05 16:38:28 -04:00
4883342630 Add zk for zettelkansten notes 2025-04-05 16:38:28 -04:00
ad9d32a1c2 Add terraform LSP/config 2025-04-05 16:38:28 -04:00
20934a6a08 Fix .bashrc 2025-04-05 16:38:28 -04:00
42ec31431e Improve Xtrace by hiding output of prompt commands 2025-04-05 16:38:28 -04:00
db76feed3e Add python + LSP + gitlab-ci-local tool 2025-04-05 16:38:28 -04:00
82d5a313c4 Adjust PS1 for distrobox containers 2025-04-05 16:38:28 -04:00
aa7b4417d0 Add nvim zk plugin 2025-04-05 16:38:28 -04:00
e6ac283459 Add vim option select to shell profile 2025-04-05 16:38:28 -04:00
b060cb0f83 Update colorscheme fix to be conditional on neovim version 2025-04-05 16:38:28 -04:00
e12d4ae431 Refactor KDE to use konsave 2025-04-05 16:38:28 -04:00
e0176bec1e Fix colorscheme for neovim v0.10+ 2025-04-05 16:38:28 -04:00
c2d137749d Add vim-gitgutter to configuration 2025-04-05 16:38:28 -04:00
4d1f34dfe5 Update removal for newer nix profile output 2025-04-05 16:38:28 -04:00
c0bf68b9e7 Update language servers/dev tools 2025-04-05 16:38:28 -04:00
fa0d2e7077 Update nix to 2.18.7 and conditionally add ssl-cert to conf.nix 2025-04-05 16:38:28 -04:00
9dc7288b77 Add solargraph 2025-04-05 16:38:28 -04:00
99b5fd8319 Attempt to fix pinentry on non-nixos 2025-04-05 16:38:28 -04:00
9027cd9bc6 Add nix-shell prompt condition 2025-04-05 16:38:28 -04:00
dec1d4009c More screen improvements 2025-04-05 16:38:28 -04:00
f44ef83e66 Add ruby by default 2025-04-05 16:38:28 -04:00
da3b0e4ab5 Extend default scrollback for screen 2025-04-05 16:38:28 -04:00
6935843cee Move vim option select to execute logic at alias def time
Using the function would cause problems when trying to perform a `sudo
vim`. The sudo command would run in a root shell which does not have my
shells functions (but does have it's aliases) so then any attempt to
sudo vim would fail with "vim_option_select: command not found"
2025-04-05 16:38:28 -04:00
0ce1d88173 Improve highlighting on selected pmenu 2025-04-05 16:38:28 -04:00
1019f48597 Update flakes to support 24.05 and unstable branches 2025-04-05 16:38:28 -04:00
0165d9bad2 Ensure persistent history exists 2025-04-05 16:38:28 -04:00
17be8f5726 Improve escaping for PS1 2025-04-05 16:38:28 -04:00
8fc91ea898 Fix for vim colorscheme
LSP diagnostics use the same coloration as menu completion, which I had
_mostly_ ignored for a long time because while black on magenta is bad,
most of the text was black. Now that LSP is trying to use it, it then
rehighlights the text within the box many colors and then having magenta
as a background is bad
2025-04-05 16:38:28 -04:00
6cdd6cea15 Improve default window name for slime 2025-04-05 16:38:28 -04:00
8c65fc2c45 Attempt to automatically extract session name from curren screen session 2025-04-05 16:38:28 -04:00
c3ab44d1e2 Don't do weird things with autocmd 2025-04-05 16:38:28 -04:00
1829f987e9 Update regex to match new direnv versions 2025-04-05 16:38:28 -04:00
16bbf912c1 Add basic autocmds to wrap on markdown and open logs at the end 2025-04-05 16:38:28 -04:00
4d5084e5aa Make a root single user nix install possible
Taken from this issue https://github.com/NixOS/nix/issues/1559

This is only so that the script will succeed when running in docker
containers without systemd (can't use multi-user) and that have root as
the default user, a shockingly common practice
2025-04-05 16:38:28 -04:00
39a666c7b7 Automatically install coder in nix environments 2025-04-05 16:38:28 -04:00
223fd65981 Remove vestigial vagrant reference 2025-04-05 16:38:28 -04:00
94083316f6 Add installers for common programs to bring along 2025-04-05 16:38:28 -04:00
4ef1d15958 Make direnv prompt updating conditional to direnv's presence 2025-04-05 16:38:28 -04:00
97a4f9fa91 Fix Direnv prompt whenver off primary hosts 2025-04-05 16:38:28 -04:00
0f59972f1b Beginner luasnip configuration for terraform 2025-04-05 16:38:28 -04:00
1961395687 Option select on tput working or use old fallback control codes 2025-04-05 16:38:28 -04:00
c394c74421 Attempt to fix recursive cloning for submodules 2025-04-05 16:38:28 -04:00
3636fb6d07 Add a vim option select 2025-04-05 16:38:28 -04:00
ab6350f15a Added conditional coloring of bash prompt dependent on direnv status 2025-04-05 16:38:28 -04:00
54a937f610 Move persistent history to more appropriate location 2025-04-05 16:38:28 -04:00
709e9a7dd7 Update git plugins 2025-04-05 16:38:28 -04:00
44cf82a669 Improve bash history, add persistent history file 2025-04-05 16:38:28 -04:00
fd08d4ed13 Alias cat to always add a newline
Sometimes if a file doesn't have a newline cat will not do one, causing
prompt strangeness
2025-04-05 16:38:28 -04:00
ae09d9af9d Add aliases for easy searching of history 2025-04-05 16:38:28 -04:00
3ce108cc40 Add readline shortcuts for improved history searching 2025-04-05 16:38:28 -04:00
1e340b2a52 Address issues that cause shell lines to break 2025-04-05 16:38:28 -04:00
f9040142cd Beginning binding/config for luasnip 2025-04-05 16:38:28 -04:00
8de18fd135 Split up neonvim configuration into lua files rather than lua heredoc 2025-04-05 16:38:28 -04:00
673500eea6 Pin plugins to specific tagged versions rather than master + add luasnip 2025-04-05 16:38:28 -04:00
82db8eb050 Update plugins 2025-04-05 16:38:28 -04:00
f409105b58 Update lspconfig 2025-04-05 16:38:28 -04:00
9780b18e08 Add conditional SSH config construction 2025-04-05 16:38:28 -04:00
582ec5aba5 Update plugins 2025-04-05 16:38:28 -04:00
cd149a2cf5 More neovim testing 2025-04-05 16:38:28 -04:00
b2c9f720ab Begin to examine neovim config 2025-04-05 16:38:28 -04:00
381a5b8f05 Add support for progressive neovimming 2025-04-05 16:38:28 -04:00
fc9a068d01 Set hostname in prompt if through SSH 2025-04-05 16:38:28 -04:00
ce8f3b4463 Add firefox as BROWSER 2025-04-05 16:38:28 -04:00
f9a84f9b58 Make dotfiles compatible with gitpod style dotfiles
Add an install.sh that attempts to determine the OS, install stow and
then call my apply-dotfiles script to use stow.

The old installation process that was based on nix, has been moved to
nix-install.
2025-04-05 16:38:19 -04:00
16 changed files with 325 additions and 63 deletions

3
.gitmodules vendored
View File

@@ -61,3 +61,6 @@
[submodule "vim/.vim/nvim-bundle/zk-nvim"]
path = vim/.vim/nvim-bundle/zk-nvim
url = https://github.com/zk-org/zk-nvim.git
[submodule "vim/.vim/bundle/vim-helm"]
path = vim/.vim/bundle/vim-helm
url = https://github.com/towolf/vim-helm.git

View File

@@ -17,6 +17,9 @@ apply_dotfile sh
apply_dotfile readline
apply_dotfile screen
apply_dotfile git
apply_dotfile xdg
apply_dotfile vim
apply_dotfile ruby

View File

@@ -1,5 +1,46 @@
#{- ~/.bashrc -}#
#{- SOURCING -}#
# Source profile, if it hasn't already been loaded
if [ -z "$__PROFILE_DONE" ]; then
. $HOME/.profile
fi
# Source .env to extend with secret/sensitive environment variables if it exists
if [ -r "$HOME/.env" ]; then
. "$HOME/.env"
fi
if [ -r "$HOME/.config/xdg/env" ]; then
. "$HOME/.config/xdg/env"
fi
# Source aliases, if they exist
if [ -f "$HOME/.aliases" ] && [ -r "$HOME/.aliases" ]; then
. "$HOME/.aliases"
fi
# Source private aliases, if they exist
if [ -f "$HOME/.private_aliases" ] && [ -r "$HOME/.private_aliases" ]; then
. "$HOME/.private_aliases"
fi
# Source functions, if they exist
if [ -f "$HOME/.functions" ] && [ -r "$HOME/.functions" ]; then
. "$HOME/.functions"
fi
# Source private functions, if they exist
if [ -f "$HOME/.private_functions" ] && [ -r "$HOME/.private_functions" ]; then
. "$HOME/.private_functions"
fi
if blesh-available; then
# blesh-activate
:
fi
#{- PROMPT -}#
if which tput &> /dev/null && tput bold &> /dev/null; then
@@ -20,7 +61,6 @@ else
no_color="\[\033[0m\]"
fi
export PS1="${green}"'\$'"${no_color} "
export DIRENV_PS1="${red}"'\$'"${no_color} "
export NIX_SHELL_PS1="${blue}"'λ'"${no_color} "
@@ -55,7 +95,7 @@ if which direnv &> /dev/null; then
PS1=${ORIG_PS1}
fi
}
PROMPT_COMMAND="update_prompt; $PROMPT_COMMAND"
prompt_command_prepend "update_prompt"
fi
# Continuation Prompt: "> " in cyan
@@ -65,8 +105,14 @@ export PS4="${blue}#${no_color} "
#{- HISTORY -}#
PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
# PROMPT_COMMAND="echo hist1; history; history -n; echo hist2; history; history -w; echo hist3; history; history -c; echo hist4; history; history -r; echo hist5; history; $PROMPT_COMMAND"
if blesh-attached; then
bleopt history_share=1
else
prompt_command_prepend "history -r"
prompt_command_prepend "history -c"
prompt_command_prepend "history -w"
prompt_command_prepend "history -n"
fi
export HISTFILE="$HOME/.history/bash"
export HISTTIMEFORMAT="%F %T "
export HISTCONTROL="erasedups:ignoreboth"
@@ -93,42 +139,17 @@ log_bash_persistent_history()
fi
}
PROMPT_COMMAND="log_bash_persistent_history; $PROMPT_COMMAND"
prompt_command_prepend "log_bash_persistent_history"
#{- SOURCING -}#
# Source profile, if it hasn't already been loaded
if [ -z "$__PROFILE_DONE" ]; then
. $HOME/.profile
fi
# Source .env to extend with secret/sensitive environment variables if it exists
if [ -r "$HOME/.env" ]; then
. "$HOME/.env"
fi
# Source aliases, if they exist
if [ -f "$HOME/.aliases" ] && [ -r "$HOME/.aliases" ]; then
. "$HOME/.aliases"
fi
# Source private aliases, if they exist
if [ -f "$HOME/.private_aliases" ] && [ -r "$HOME/.private_aliases" ]; then
. "$HOME/.private_aliases"
fi
# Source functions, if they exist
if [ -f "$HOME/.functions" ] && [ -r "$HOME/.functions" ]; then
. "$HOME/.functions"
fi
# Source private functions, if they exist
if [ -f "$HOME/.private_functions" ] && [ -r "$HOME/.private_functions" ]; then
. "$HOME/.private_functions"
fi
# Source bash completion, this file will then lazy load all other completions
source_completions() {
if [ -r "/usr/share/bash-completion/bash_completion" ]; then
. "/usr/share/bash-completion/bash_completion"
elif [ -r "/etc/bash_completion" ]; then
. "/etc/bash_completion"
fi
}
source_completions
# Preserve the usefulness of set -x by attempting to hide everything that
# happens in prompt_command
@@ -145,8 +166,12 @@ preserve_xtrace_reset() {
fi
} 2>/dev/null
PROMPT_COMMAND="preserve_xtrace; $PROMPT_COMMAND preserve_xtrace_reset"
prompt_command_prepend "preserve_xtrace"
prompt_command_append "preserve_xtrace_reset"
if $(which direnv &> /dev/null); then
eval "$(direnv hook bash)"
# Only if direnv isn't already defined in our prompt_command
if ! grep -q _direnv_hook <<< $PROMPT_COMMAND; then
eval "$(direnv hook bash)"
fi
fi

View File

@@ -18,6 +18,85 @@ maths()
cat_with_newline()
{
cat "$@" && echo
\cat "$@" && echo
}
alias cat="cat_with_newline"
k_prompt()
{
set -x
if [ -z ${KUBE_PROMPT+x} ]; then
export KUBE_PROMPT=1
else
unset KUBE_PROMPT
fi
set +x
}
kube_prompt()
{
set -x
if ! [ -z ${KUBE_PROMPT+x} ]; then
context=$(\cat ${KUBECONFIG} \
| grep "current-context: " \
| sed "s/current-context: //")
echo {$context}
fi
set +x
}
g_prompt()
{
if ! [ -z ${GIT_PROMPT+x} ]; then
export GIT_PROMPT=1
else
unset GIT_PROMPT
fi
}
git_prompt()
{
if ! [ -z ${GIT_PROMPT+x} ]; then
# Determine if we are in a git repository
if git rev-parse --is-inside-work-tree &> /dev/null; then
branch=$(git rev-parse --abbrev-ref HEAD)
echo [$branch]
fi
fi
}
prompt_command_append() {
arg=${1}
PROMPT_COMMAND=${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}"${arg}"
}
prompt_command_prepend() {
arg=${1}
PROMPT_COMMAND="${arg}"${PROMPT_COMMAND:+"; $PROMPT_COMMAND"}
}
blesh-activate()
{
BLESH_PATH=$HOME/.nix-profile/share/blesh/ble.sh
if [ -r $BLESH_PATH ]; then
[[ $- == *i* ]] && . $HOME/.nix-profile/share/blesh/ble.sh
[[ ! ${BLE_VERSION-} ]] || ble-attach
fi
}
blesh-available() {
BLESH_PATH=$HOME/.nix-profile/share/blesh/ble.sh
if [ -r $BLESH_PATH ]; then
return 0
else
return 1
fi
}
blesh-attached () {
if [ -z ${BLE_VERSION:+x} ]; then
return 1
else
return 0
fi
}

25
git/.config/git/config Normal file
View File

@@ -0,0 +1,25 @@
[branch]
sort = -committerdate
[column]
ui = auto
[tag]
sort = version:refname
[init]
defaultBranch = main
[diff]
algorithm = histogram
colorMoved = plain
mnemonicPrefix = true
renames = true
[push]
default = simple
autoSetupRemote = true
followTags = true
[fetch]
prune = true
pruneTags = true
all = true
[commit]
verbose = true
[core]
excludefiles = ~/.config/git/ignore

View File

@@ -6,17 +6,36 @@ set -ex
echo "PWD: $PWD"
# Coder dotfiles (and most other ways of doing this) will not do a recursive clone, so do that in install script.
git submodule init && git submodule update
# Match case insensitively to make things easier for this part
shopt -s nocasematch
echo "Installing dotfiles..."
if [ -f /etc/os-release ]; then
if [ "${CODER_TEMPLATE_TYPE}" == "Devcontainer" ]; then
installers/install-nix.sh
installers/install-nix-packages-flake.sh
if [ -r "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
elif [ -r "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh" ]; then
. "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh"
fi
elif [ "${CODER_OS_FAMILY:-}" == "Ubuntu" ]; then
echo "Detected OS as Ubuntu, using apt";
sudo apt-get update;
sudo apt-get install -y stow;
installers/install-nix.sh
if [ -r "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
elif [ -r "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh" ]; then
. "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh"
fi
elif [ -f /etc/os-release ]; then
echo "Idenitfying OS to install GNU stow..."
if [ "${CODER_OS_FAMILY:-}" == "Ubuntu" ] || grep -q -i debian /etc/os-release; then
if grep -q -i debian /etc/os-release; then
echo "Detected OS as Ubuntu, using apt";
sudo apt-get update;
sudo apt-get install -y stow;
installers/install-nix.sh
elif grep -q -i rhel /etc/os-release || grep -q -i fedora /etc/os-release; then
echo "You've got RedHat (or maybe Fedora)! Which is unsupported right now sorry!";
# sudo yum install -y stow;
@@ -31,15 +50,20 @@ if [ -f /etc/os-release ]; then
exit 1;
fi;
else
if [ "${CODER_TEMPLATE_TYPE}" == "Devcontainer" ]; then
installers/install-nix.sh
fi
echo "ERROR: Unable to find '/etc/os-release' information!" 1>&2;
exit 1;
fi
shopt -u nocasematch
# Apply the dotfiles with stow
echo "Running apply dotfiles"
./apply-dotfiles
if which stow &> /dev/null; then
./apply-dotfiles
elif which nix &> /dev/null; then
./apply-dotfiles-nix
else
echo "Tools for installing dotfiles are unavailable, failing..."
exit 1
fi
echo "Dotfiles applied successfully"

View File

@@ -2,14 +2,30 @@
# Installs packages to the nix profile using nix profile
# Reference: https://nixos.org/manual/nixpkgs/stable/#sec-declarative-package-management
set -ex
set -e
FLAKE_PATH="${HOME}/.config/nix/flakes/my-package-collection"
FLAKE_NAME="flake.nix"
ARCHIVE_PATH="${FLAKE_PATH}/archive.nar"
if ! which nix &>/dev/null; then
if [ -r "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
elif [ -r "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh" ]; then
. "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh"
else
echo "Nix isn't available. Exiting now!"
exit 1
fi
fi
nix_packages=(
# Personal tools
"vimHugeX"
"ranger"
"jq"
"yq"
"screen"
"xdg-utils" # For xdg-open
"zk"
# Neovim + Plugin dependencies
@@ -65,13 +81,13 @@ unstable_packages=(
)
mkdir -p ~/.config/nixpkgs/
templated_insert="$(for nix_package in ${nix_packages[@]}; do echo " $nix_package"; echo; done)"
templated_insert=${templated_insert}$(for unstable_package in ${unstable_packages[@]}; do echo; echo " unstablePkgs.$unstable_package"; done)
generate_flake() {
mkdir -p "${FLAKE_PATH}"
templated_insert="$(for nix_package in ${nix_packages[@]}; do echo " $nix_package"; echo; done)"
templated_insert=${templated_insert}$(for unstable_package in ${unstable_packages[@]}; do echo; echo " unstablePkgs.$unstable_package"; done)
# Reference: https://discourse.nixos.org/t/nix-profile-in-combination-with-declarative-package-management/21228/9
cat << EOF > ~/.config/nixpkgs/flake.nix
# Reference: https://discourse.nixos.org/t/nix-profile-in-combination-with-declarative-package-management/21228/9
cat <<EOF > "${FLAKE_PATH}/${FLAKE_NAME}"
{
description = "A declarative system installation";
@@ -103,7 +119,7 @@ cat << EOF > ~/.config/nixpkgs/flake.nix
pkgs = nixpkgs.legacyPackages.\${system}; # here we need just legacy packages
unstablePkgs = import unstable { inherit system; config.allowUnfree = true; };
in pkgs.buildEnv {
name = "myPackages";
name = "myPackageCollection";
paths = with pkgs; [
${templated_insert}
];
@@ -114,6 +130,19 @@ ${templated_insert}
}; # outputs
}
EOF
}
lock_flake() {
nix flake lock "${FLAKE_PATH}"
}
flake_lock_exists() {
if [ -r "${FLAKE_PATH}/flake.lock" ]; then
return 0
else
return 1
fi
}
install_nix_packages()
{
@@ -122,13 +151,48 @@ install_nix_packages()
if [ "${nix_packages[*]}" ]; then
# Updated to process new nix profile format, proper processing probably needs JQ
# But JQ would be another dependency and this is good enough for now
if nix profile list --json | grep -i "\"attrPath\":\"${package_name}\""; then
# Okay we are installing jq to do stuff now but I don't feel like reworking this
if nix profile list --json | grep -qi "\"attrPath\":\"${package_name}\""; then
echo "Removing previous version of profile"
nix profile remove "${package_name}"
store_path=$(nix profile list --json | nix-shell --quiet -p jq --run 'jq -r .elements.myPackageCollection.storePaths[0]')
nix profile remove "${store_path}"
fi
echo "Installing profile"
nix profile install "${HOME}/.config/nixpkgs/flake.nix#myPackageCollection"
nix profile install "${FLAKE_PATH}/#myPackageCollection"
fi
}
get_store_path() {
# This is only called post successful installation so jq is available
nix profile list --json | jq -r .elements.myPackageCollection.storePaths[0]
}
export_archive() {
store_path="${1}"
mkdir -p "$(dirname ${ARCHIVE_PATH})"
nix-store --export $(nix-store --query --requisites ${store_path}) > "${ARCHIVE_PATH}"
}
import_archive() {
nix-store --import < "${ARCHIVE_PATH}" > /dev/null
}
archive_exists() {
if [ -r "${ARCHIVE_PATH}" ]; then
return 0
else
return 1
fi
}
if archive_exists; then
import_archive
fi
generate_flake
if ! flake_lock_exists; then
lock_flake
fi
install_nix_packages
if ! archive_exists; then
export_archive "$(get_store_path)"
fi

View File

@@ -7,8 +7,12 @@ set -e
set -x
# Abort installation if Nix is already installed
if [ -d /nix ]; then
if [ -d /nix/store ]; then
exit 0
elif [ -d /nix ] && ! [ -O /nix ]; then
# If we don't own /nix use sudo to chown it.
# If we can't sudo then nothing we do here will work so we just let this fail
sudo chown $UID /nix
fi
# Workaround to make a single user install work as root
@@ -18,7 +22,7 @@ if [ "${USER:-}" == "root" ] || [ "${UID:-}" == "0" ]; then
fi
# Download the Nix installer and it's signature from NixOS.org
curl -so install-nix https://releases.nixos.org/nix/nix-2.18.7/install
curl -so install-nix https://releases.nixos.org/nix/nix-2.24.12/install
# Run the installer
sh ./install-nix
@@ -28,6 +32,8 @@ cat << EOF > ~/.bashrc
# Source nix if it's installed
if [ -r ~/.nix-profile/etc/profile.d/nix.sh ]; then
. ~/.nix-profile/etc/profile.d/nix.sh
elif [ -r "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh" ]; then
. "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh"
fi
EOF
@@ -40,6 +46,7 @@ NIX_CONF_FILE=${NIX_CONF_DIR}/nix.conf
mkdir -p ${NIX_CONF_DIR}
cat <<EOF > ${NIX_CONF_FILE}
experimental-features = flakes nix-command
use-xdg-base-directories = true
EOF
# Conditionally add a link to system certificates for nix
if [ -f /etc/ssl/certs/ca-certificates.crt ]; then

View File

@@ -1,3 +1,5 @@
# Defaults to using bash as the shell
defshell $SHELL
# Extend scrollback buffer
defscrollback 100000
# Disable startup message

View File

@@ -50,4 +50,6 @@ export HISTFILESIZE=10000
if [ -r "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
elif [ -r "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh" ]; then
. "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh"
fi

14
xdg/.config/xdg/env Normal file
View File

@@ -0,0 +1,14 @@
export XDG_DATA_HOME="${HOME}/.local/share"
export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_STATE_HOME="${HOME}/.local/state"
export XDG_CACHE_HOME="${HOME}/.cache"
# Set environment variables to force programs to respect XDG that do not by default
export SCREENRC="${XDG_CONFIG_HOME}/screen/screenrc"
export GNUPGHOME="$XDG_DATA_HOME"/gnupg
export MYSQL_HISTFILE="$XDG_DATA_HOME"/mysql_history
export INPUTRC="$XDG_CONFIG_HOME"/readline/inputrc
export IRBRC="$XDG_CONFIG_HOME/irb/irbrc"
export KUBECONFIG="${XDG_CONFIG_HOME}/kube/config"
mkdir -p "$(dirname ${KUBECONFIG})"

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# For older systems that don't support newer versions of programs that may
# support XDG config paths natively we have to symlink to the new paths from
# the expected locations of the older paths.
# This can also be used to support migrations from systems before we started XDGifying
ln -s "${XDG_CONFIG_HOME}/screen/screenrc" "${HOME}/.screenrc"
ln -s "${XDG_DATA_HOME}/.gnupg" "${HOME}/.gnupg"
ln -s "${XDG_DATA_HOME}/mysql_history" "${HOME}/.mysql_history"
ln -s "${XDG_CONFIG_HOME}/readline/inputrc" "${HOME}/.inputrc"
ln -s "${XDG_CONFIG_HOME}/irb/irbc" "${HOME}/.irbrc"
ln -s "${XDG_CONFIG_HOME}/kube/config" "${HOME}/.kubeconfig"