diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d4b6206aa..bb310f98f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,14 +63,12 @@ jobs: run: | env export XDG_CONFIG_HOME=~/.config - # Don't care about outdated, broken linkages on CI. - # Otherwise, this might update node or php. - export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 - export HOMEBREW_NO_INSTALL_CLEANUP=1 # Make `infocmp` for nvim healthcheck succeed export TERM=dumb # Ignore potentially insecure directories on GitHub actions runner. export ZSH_DISABLE_COMPFIX=true + # Do not rate limit with public / untrusted access bucket + export NIX_CONFIG="access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" cd .dotfiles/ ./script/ci.sh - name: Rename versions report diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..ba44586bb5 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +.PHONY: update clean + +update: + nix run home-manager/release-24.05 -- --impure switch --flake .#myprofile + +clean: + nix-collect-garbage -d + +closuresize-all: + nix path-info -S /Users/kaihowl/.nix-profile/ -r | sort -n -k2 + +closuresize-single: + nix path-info -S /Users/kaihowl/.nix-profile/ + +print-dependencies: + nix-store --query ~/.nix-profile --graph | dot -Tpdf -o out.pdf && open out.pdf diff --git a/alacritty/install.sh b/alacritty/install.sh index a8d30779be..ebc3bb1ef1 100755 --- a/alacritty/install.sh +++ b/alacritty/install.sh @@ -1,15 +1,7 @@ #!/bin/bash set -e -SCRIPT_DIR=$(unset CDPATH; cd "$(dirname "$0")" > /dev/null; pwd -P) - if [ "$(uname)" == "Darwin" ]; then - source "${SCRIPT_DIR}/../common/brew.sh" - brew_install alacritty -elif [[ "$(lsb_release -i)" == *"Ubuntu"* ]]; then - sudo snap remove alacritty || true - source "${SCRIPT_DIR}/../common/apt.sh" - apt_add_repo alacritty https://ppa.launchpadcontent.net/aslatter/ppa/ubuntu ::codename:: 3a160895cc2ce253085d08a552b24df7d43b5377 - apt_install alacritty + # Actual copy needed, otherwise Spotlight will not show the app + sudo cp -rf ~/.nix-profile/Applications/Alacritty.app /Applications/ fi - diff --git a/alacritty/test.sh b/alacritty/test.sh index e8d7db9cd7..071ad08843 100755 --- a/alacritty/test.sh +++ b/alacritty/test.sh @@ -5,5 +5,13 @@ set -e echo "Check if alacritty is installed" which alacritty +echo "Check if alacritty is nix controlled" +actual_path=$(realpath "$(which alacritty)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected alacritty to be managed by nix + exit 1 +fi + echo "Check if alacritty is runnable" alacritty --version diff --git a/ccache/test.sh b/ccache/test.sh index 56b1dc7006..80800bc0ec 100755 --- a/ccache/test.sh +++ b/ccache/test.sh @@ -4,6 +4,14 @@ set -e echo "Check if ccache is available" which ccache +echo "Check if ccache is nix controlled" +actual_path=$(realpath "$(which ccache)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected ccache to be managed by nix + exit 1 +fi + echo "Check if ccache is runnable" ccache --version diff --git a/clangd/test.sh b/clangd/test.sh index 285a1361f7..3421442cb9 100755 --- a/clangd/test.sh +++ b/clangd/test.sh @@ -10,8 +10,10 @@ clangd --version echo "Check that clangd can be started" clangd --help > /dev/null -echo "Check that clangd is installed from llvm apt repo (Ubuntu-only)" -if [[ "$(lsb_release -i)" == *"Ubuntu"* ]]; then - apt-cache policy clangd - apt-cache policy clangd | grep -F '**' -A1 | grep -F apt.llvm.org +echo "Check that clangd is nix managed" +actual_path=$(realpath "$(which clangd)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected clangd to be managed by nix + exit 1 fi diff --git a/cmake/test.sh b/cmake/test.sh index b48c16ba93..6620333630 100755 --- a/cmake/test.sh +++ b/cmake/test.sh @@ -4,8 +4,10 @@ set -e echo "Check if cmake is available" which cmake -echo "Check that cmake is installed from llvm apt repo (Ubuntu-only)" -if [[ "$(lsb_release -i)" == *"Ubuntu"* ]]; then - apt-cache policy cmake - apt-cache policy cmake | grep -F '**' -A1 | grep -F apt.kitware.com +echo "Check if cmake is nix controlled" +actual_path=$(realpath "$(which cmake)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected cmake to be managed by nix + exit 1 fi diff --git a/colors/install.sh b/colors/install.sh index d8bcb48c98..9cf1ad9261 100755 --- a/colors/install.sh +++ b/colors/install.sh @@ -3,9 +3,4 @@ set -e SCRIPT_DIR=$(unset CDPATH; cd "$(dirname "$0")" > /dev/null; pwd -P) -# Depends on an installed zsh for using zparseopts in change-color -if ! command -v zsh > /dev/null; then - "${SCRIPT_DIR}/../zsh/install.sh" -fi - "${SCRIPT_DIR}/../colors/bin/change-color" diff --git a/common/apt.sh b/common/apt.sh index 091f354353..c2b9c894e4 100644 --- a/common/apt.sh +++ b/common/apt.sh @@ -19,11 +19,6 @@ function apt_install() { sudo apt-get -o DPkg::Lock::Timeout=-1 install --upgrade -y "$@" } -function apt_remove() { - wait_for_apt - sudo apt-get remove -y "$@" -} - function apt_add_repo_with_keyfile() { local name name=$1 diff --git a/common/python.sh b/common/python.sh index 46ca399664..720f5b3005 100644 --- a/common/python.sh +++ b/common/python.sh @@ -2,27 +2,11 @@ set -e -function ensure_python_installed() { - local script_dir - script_dir=$(unset CDPATH; cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null; pwd -P) - if [[ "$(uname)" == "Linux" && "$(lsb_release -i)" == *"Ubuntu"* ]]; then - source "${script_dir}/apt.sh" - # venv is needed as Ubuntu 22.04 otherwise has no ensurepip and venv fails. - # Install all of these packages as a sane baseline. - apt_install --no-install-recommends python3-pip python3-dev python3-venv - else - # The apple xcode python is broken. Use brew's python version instead. - source "${script_dir}/brew.sh" - brew_install python - fi -} - function install_in_named_virtualenv() { local venvname venvname=$1 shift - ensure_python_installed # Using venv instead of virtualenv as homebrews virtualenv is completely # separate from its python. I.e., it is not installed as a site package. # Installing virtualenv globally defeats the purpose of having venvs in the @@ -30,10 +14,15 @@ function install_in_named_virtualenv() { # Major difference, it does not seed wheel (needed by pynvim) into the # virtualenv. This is done manually including an upgrade of pip and # setuptools. - python3 -m venv "$HOME/.virtualenvs/$venvname" + python3Binary=$HOME/.virtualenvs/$venvname/bin/python3 + if [[ -f $python3Binary ]] && ! [[ $(realpath "$python3Binary") == /nix/store/* ]]; then + echo "Delete pre-nix-era venv, start fresh" + rm -rf "$HOME/.virtualenvs/$venvname/" + fi + ~/.nix-profile/bin/python3 -m venv "$HOME/.virtualenvs/$venvname" # Must run independently as wheel is a non-declared dependency of some packages. - "$HOME/.virtualenvs/$venvname/bin/python3" -m pip install --upgrade pip setuptools wheel - "$HOME/.virtualenvs/$venvname/bin/python3" -m pip install --upgrade "$*" + "$python3Binary" -m pip install --upgrade pip setuptools wheel + "$python3Binary" -m pip install --upgrade "$*" } function install_in_nvim_virtualenv() { diff --git a/ctags/test.sh b/ctags/test.sh index 68d854e593..890184b2c6 100755 --- a/ctags/test.sh +++ b/ctags/test.sh @@ -4,5 +4,13 @@ set -e echo "Check if (universal-)ctags is available" which ctags +echo "Check if ctags is nix controlled" +actual_path=$(realpath "$(which ctags)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected ctags to be managed by nix + exit 1 +fi + echo "Check if ctags is runnable" ctags --version diff --git a/efm/test.sh b/efm/test.sh index ce8c1c1f4a..fe1c62f8c7 100755 --- a/efm/test.sh +++ b/efm/test.sh @@ -9,9 +9,9 @@ efm-langserver -v echo "Check if efm-langserver is user-installed one" actual_path=$(realpath "$(which efm-langserver)") -if [[ "${actual_path}" != $(realpath ~/.efm/)* ]]; then +if [[ ${actual_path} != /nix/store/* ]]; then echo "Actual Path: $actual_path" - echo Expected to be in ~/.efm/ instead + echo Expected to be managed by nix exit 1 fi diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..10a6739c3c --- /dev/null +++ b/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1726989464, + "narHash": "sha256-Vl+WVTJwutXkimwGprnEtXc/s/s8sMuXzqXaspIGlwM=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "2f23fa308a7c067e52dfcc30a0758f47043ec176", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-24.05", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkg-unstable": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1730327045, + "narHash": "sha256-xKel5kd1AbExymxoIfQ7pgcX6hjw9jCgbiBjiUfSVJ8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "080166c15633801df010977d9d7474b4a6c549d7", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-24.05", + "type": "indirect" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nixpkg-unstable": "nixpkg-unstable", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..0d2562732f --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + description = "My home manager configuration"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-24.05"; + + nixpkg-unstable.url = "nixpkgs/nixos-unstable"; + + home-manager = { + url = "github:nix-community/home-manager/release-24.05"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { nixpkgs, home-manager, nixpkg-unstable, ... }: + let + lib = nixpkgs.lib; + system = builtins.currentSystem; + pkgs = import nixpkgs { inherit system; }; + pkgs-unstable = import nixpkg-unstable { inherit system; }; + in { + homeConfigurations = { + myprofile = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + extraSpecialArgs = {inherit pkgs-unstable;}; + modules = [ ./home.nix ]; + }; + }; + }; +} diff --git a/fzf/bootstrap.zsh b/fzf/bootstrap.zsh index 15104b1936..701b1600c0 100644 --- a/fzf/bootstrap.zsh +++ b/fzf/bootstrap.zsh @@ -1,2 +1,3 @@ -# shellcheck disable=SC1090 -[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh +# shellcheck disable=all +[ -f ~/.nix-profile/share/fzf/completion.zsh ] && source ~/.nix-profile/share/fzf/completion.zsh +[ -f ~/.nix-profile/share/fzf/key-bindings.zsh ] && source ~/.nix-profile/share/fzf/key-bindings.zsh diff --git a/fzf/test.sh b/fzf/test.sh index 62a8f33d62..9805be1770 100755 --- a/fzf/test.sh +++ b/fzf/test.sh @@ -4,8 +4,19 @@ set -e echo "Checking whether fzf is on path" which fzf +echo "Check if fzf is nix controlled" +actual_path=$(realpath "$(which fzf)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected fzf to be managed by nix + exit 1 +fi + echo "Check if fzf is runnable" fzf --version +echo "Check that ctrl-t is registered for fzf" +bindkey | grep -i '"\^T".*fzf' + echo "Check that ctrl-xo is registered" bindkey | grep -i '\^X\^O' diff --git a/gdb/install.sh b/gdb/install.sh index 37ac2bc7b5..5771711220 100755 --- a/gdb/install.sh +++ b/gdb/install.sh @@ -10,9 +10,9 @@ if [[ "$(lsb_release -i 2> /dev/null)" == *"Ubuntu"* ]]; then codename=$(lsb_release -cs) apt_add_repo ubuntu-toolchain-test https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu ::codename:: 60C317803A41BA51845E371A1E9377A2BA9EF27F if [[ "$codename" == *"focal"* ]]; then - apt_install clang gdb libstdc++6-10-dbg + apt_install clang libstdc++6-10-dbg elif [[ "$codename" == *"jammy"* ]]; then - apt_install clang gdb libstdc++6-12-dbg + apt_install clang libstdc++6-12-dbg else echo "Unsupported Ubuntu version $codename" echo "Maybe the following command will point to the correct version" diff --git a/gdb/test.sh b/gdb/test.sh index 9e0993f502..e342f56b07 100755 --- a/gdb/test.sh +++ b/gdb/test.sh @@ -6,6 +6,14 @@ if [ "$(uname)" == "Darwin" ]; then exit 0 fi +echo "Check if gdb is nix controlled" +actual_path=$(realpath "$(which gdb)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected gdb to be managed by nix + exit 1 +fi + # Example output: # GNU gdb (Ubuntu 10.2-0ubuntu1~20.04~1) 10.2 version=$(gdb --version | awk 'NR==1 {print $(NF)}') diff --git a/git/test.sh b/git/test.sh index 8e4d112c2f..2dfd2ac22c 100755 --- a/git/test.sh +++ b/git/test.sh @@ -7,6 +7,14 @@ which git echo "Check if git is runnable" git --version +echo "Check if git is nix controlled" +actual_path=$(realpath "$(which git)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected git to be managed by nix + exit 1 +fi + echo "Ensure git is >= 2.34.0 to support ssh signing" git --version version=$(git --version 2>&1 | cut -d' ' -f3) diff --git a/home.nix b/home.nix new file mode 100644 index 0000000000..96fbf153cc --- /dev/null +++ b/home.nix @@ -0,0 +1,43 @@ +{ lib, pkgs, pkgs-unstable, ... }: +{ + home = { + packages = with pkgs; [ + alacritty + ccache + clang-tools + cmake + universal-ctags + efm-langserver + fzf + git + ninja + neovim-unwrapped + ripgrep + rustup + shellcheck + tmux + zsh expect + python3 + python3Packages.virtualenv + python3Packages.virtualenvwrapper + python3Packages.pip + # support tooling + tree jq htop + pkgs-unstable.ncdu + flock + # Assumed to be present for Conan tooling + automake libtool pkg-config + ] + ++ (lib.optional pkgs.stdenv.isLinux gdb) + # TODO(kaihowl) Double check if reattach-to-user-namespace is still needed + # ++ (lib.optionals pkgs.stdenv.isDarwin [reattach-to-user-namespace coreutils]) + ; + + # This actually needs to be your username + # TODO(kaihowl) remove impurity again? + username = builtins.getEnv "USER"; + homeDirectory = /. + (builtins.getEnv "HOME"); + + stateVersion = "24.05"; + }; +} diff --git a/ninja/test.sh b/ninja/test.sh index 19305ef9d7..d810cc2756 100755 --- a/ninja/test.sh +++ b/ninja/test.sh @@ -4,5 +4,13 @@ set -e echo "Check if ninja is available" which ninja +echo "Check if ninja is nix controlled" +actual_path=$(realpath "$(which ninja)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected ninja to be managed by nix + exit 1 +fi + echo "Check if ninja is runnable" ninja --version diff --git a/nix/config--nix--nix.conf.symlink b/nix/config--nix--nix.conf.symlink new file mode 100644 index 0000000000..c7d7291eb0 --- /dev/null +++ b/nix/config--nix--nix.conf.symlink @@ -0,0 +1 @@ +experimental-features = nix-command flakes diff --git a/nvim/install.sh b/nvim/install.sh index 4eb9c92aa0..ba59b290f0 100755 --- a/nvim/install.sh +++ b/nvim/install.sh @@ -1,37 +1,6 @@ #!/bin/bash set -e -SCRIPT_DIR=$(unset CDPATH; cd "$(dirname "$0")" > /dev/null; pwd -P) - -version=0.10.1 - -if [ "$(uname -s)" = "Darwin" ]; then - if [ "$(uname -m)" = "arm64" ]; then - download_url="https://github.com/neovim/neovim/releases/download/v${version}/nvim-macos-arm64.tar.gz" - expect_hash="4b322a8da38f0bbdcdcc9a2b224a7b5267f0b1610b7345cb880d803e03bb860b" - else - download_url="https://github.com/neovim/neovim/releases/download/v${version}/nvim-macos-x86_64.tar.gz" - expect_hash="dd88c86164e6fb34ee364c4a2b42c6a1832890003ae7c9c733032697d92cf7a6" - fi -elif [[ "$(lsb_release -i)" == *"Ubuntu"* ]]; then - download_url="https://github.com/neovim/neovim/releases/download/v${version}/nvim-linux64.tar.gz" - expect_hash="4867de01a17f6083f902f8aa5215b40b0ed3a36e83cc0293de3f11708f1f9793" -fi - -file_name=nvim-${version}.tar.gz - -source "${SCRIPT_DIR}/../common/download.sh" -cache_file "$file_name" "$download_url" "$expect_hash" - -# Ensure a clean install with no left behind files -rm -rf ~/.nvim -mkdir -p ~/.nvim -tar -C ~/.nvim --extract -z -f "$(cache_path "${file_name}")" --strip-components 1 - -# Make freshly installed nvim available in path -script_dir=$(dirname "$0") -. "${script_dir}/path.zsh" - # update packages in Plug # install plug if not already installed plug_dir="${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim @@ -39,4 +8,4 @@ if [ ! -d "$plug_dir" ]; then curl -fLo "${plug_dir}" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim fi -nvim -u NONE --headless -c 'let g:first_time_startup=1' -c 'source ~/.config/nvim/init.vim' +PlugUpgrade '+PlugClean!' '+PlugUpdate!' +qall +~/.nix-profile/bin/nvim -u NONE --headless -c 'let g:first_time_startup=1' -c 'source ~/.config/nvim/init.vim' +PlugUpgrade '+PlugClean!' '+PlugUpdate!' +qall diff --git a/nvim/test.sh b/nvim/test.sh index 6ab791b214..3b1507a3a6 100755 --- a/nvim/test.sh +++ b/nvim/test.sh @@ -10,11 +10,15 @@ nvim --version echo "Check if vim alias is set" which vim +echo "Check if efm is available" +which efm-langserver +efm-langserver -v + echo "Check if nvim is user-installed one" actual_path=$(realpath "$(which nvim)") -if [[ "${actual_path}" != $(realpath ~/.nvim/bin)* ]]; then +if [[ "${actual_path}" != /nix/store/* ]]; then echo "Actual Path: $actual_path" - echo Expected to be in ~/.nvim/bin instead + echo Expected nvim to be managed by nix exit 1 fi diff --git a/rust/install.sh b/rust/install.sh index 69851389f4..40165cf3f5 100755 --- a/rust/install.sh +++ b/rust/install.sh @@ -1,22 +1,8 @@ #!/bin/bash set -e -SCRIPT_DIR=$(unset CDPATH; cd "$(dirname "$0")" > /dev/null; pwd -P) - -version=4 -download_url="https://sh.rustup.rs" -# Compare with https://github.com/rust-lang/rustup/blob/master/rustup-init.sh -expect_hash="32a680a84cf76014915b3f8aa44e3e40731f3af92cd45eb0fcc6264fd257c428" - -file_name=rustup-sh-${version} - -source "${SCRIPT_DIR}/../common/download.sh" -cache_file "$file_name" "$download_url" "$expect_hash" - -rustupinit="$(cache_path "${file_name}")" -chmod +x "${rustupinit}" -"${rustupinit}" -y --verbose --component rust-analyzer -# shellcheck disable=SC1091 -source "$HOME/.cargo/env" -ln -sf "$(rustup which rust-analyzer)" "$HOME/.cargo/bin/" +PATH=~/.nix-profile/bin/:$PATH +rustup default stable +rustup update +rustup component add rust-analyzer diff --git a/script/check_for_upgrade.sh b/script/check_for_upgrade.sh index aa3d975375..6d0b06c53b 100755 --- a/script/check_for_upgrade.sh +++ b/script/check_for_upgrade.sh @@ -13,7 +13,7 @@ function _update_dots_update() { } function _upgrade_dots() { - /usr/bin/env DOTS="$DOTS" /bin/zsh -c "flock -E 250 -n '$DOTS/script/upgrade.sh.lock' -c '$DOTS/script/upgrade.sh'" + /usr/bin/env DOTS="$DOTS" zsh -c "flock -E 250 -n '$DOTS/script/upgrade.sh.lock' -c '$DOTS/script/upgrade.sh'" if [ $? -eq 250 ]; then printf '\033[0;93m%s\033[0m\n' 'Upgrade already running. Skipping this invocation.' return 1 diff --git a/script/install b/script/install index 2b5096694d..1ce1698219 100755 --- a/script/install +++ b/script/install @@ -30,19 +30,29 @@ trap restore_selinux EXIT source common/perf_stubs.sh -if [[ "$(uname)" == "Linux" && "$(lsb_release -i)" == *"Ubuntu"* ]]; then - source common/apt.sh - apt_update -fi - if [[ "$(uname)" == *"Darwin"* ]] && [[ "$(xcode-select -p)" == *"CommandLineTools"* ]]; then # Full XCode is for example needed to compile pynvim's greenlet printf "Running \e[32mFull XCode install needed\e[0m" exit 1 fi -# No explicit update for homebrew, there are enough update and cleanup -# invocations automatically after a certain time has passed. +if ! [ -f /nix/var/nix/profiles/default/bin/nix ]; then + curl -L https://nixos.org/nix/install | sh -s -- --daemon + # # Check for basic install + # bash -il -c 'nix-shell -p nix-info --run "nix-info -m"' + # # Check for experimental command support + # bash -il -c 'nix run nixpkgs#hello' +fi + +# Instantiate the home-manager flake +# TODO(kaihowl) remove impurity again +bash -il -c 'nix run home-manager/release-24.05 -- --impure switch --flake .#myprofile' +# This will make the nix-env invocations in the install files fail + +if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then + # shellcheck disable=SC1090,SC1091 + . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' +fi # find the installers and run them iteratively # Run zsh install first diff --git a/script/test b/script/test index c55077ceb5..b4f80621d4 100755 --- a/script/test +++ b/script/test @@ -4,6 +4,13 @@ cd "$(dirname "$0")"/.. || exit 1 +# Needed to bring the correct PATH in place such that the /usr/bin/env shebang +# for the test scripts finds a working zsh +if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then + # shellcheck disable=SC1090,SC1091 + . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' +fi + # find all test scripts and run them tests=() while IFS= read -r -d '' test; do diff --git a/script/versions.sh b/script/versions.sh index 894126129e..6edd2be1df 100755 --- a/script/versions.sh +++ b/script/versions.sh @@ -1,6 +1,4 @@ -#!/bin/zsh -i -set -eu -set -o pipefail +#!/bin/bash if [ $# != 1 ]; then echo Missing output file argument @@ -12,13 +10,12 @@ echo "output to $output_file" echo "" > "$output_file" -if [[ "$(uname)" == "Darwin" ]]; then - echo "brew installed:" >> "$output_file" - brew info --installed --json | jq '.[] | .name + "@" + .installed[0].version' | tee -a "$output_file" -elif [[ "$(lsb_release -i)" == *"Ubuntu"* ]]; then - echo "apt installed:" >> "$output_file" - # Not using `apt list --installed` as apt does not have a stable interface - dpkg-query --show | tee -a "$output_file" +# TODO use nix-env reporting + +# Need to have proper PATH +if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then + # shellcheck disable=SC1091 + . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' fi tmp_file=$(mktemp) @@ -27,4 +24,5 @@ nvim --headless "+PlugSnapshot! $tmp_file" +qall { echo "nvim plugins installed:"; cat "$tmp_file"; } >> "$output_file" -{ echo "pip packages installed:"; python3 -m pip list; } >> "$output_file" +# TODO(kaihowl) not needed on generic python, maybe for the virtualenvs created? +# { echo "pip packages installed:"; python3 -m pip list; } >> "$output_file" diff --git a/virtualenvwrapper/workon.zsh b/virtualenvwrapper/workon.zsh index 25bab8d376..5623006b05 100644 --- a/virtualenvwrapper/workon.zsh +++ b/virtualenvwrapper/workon.zsh @@ -1,18 +1,14 @@ export WORKON_HOME=$HOME/.virtualenvs export PROJECT_HOME=$HOME/Devel -# Missing expansion of VIRTUALENVWRAPPER_PYTHON -# This needs to be specific to each platform, i.e., where python3 sits. -# Set this instead in your .zprofile if not set by install.sh automatically. +# Set explicitly, even if we expect this python3 to be the first python3 on the PATH already +export VIRTUALENVWRAPPER_PYTHON=$HOME/.nix-profile/bin/python3 +export VIRTUALENVWRAPPER_VIRTUALENV=$HOME/.nix-profile/bin/virtualenv -macos_virtualenv_scripts=$HOMEBREW_PREFIX/bin -ubuntu_virtualenv_scripts=/usr/share/virtualenvwrapper +nix_virtualenv_scripts=~/.nix-profile/bin lazy_wrapper=virtualenvwrapper_lazy.sh -if [ -f "${macos_virtualenv_scripts}/${lazy_wrapper}" ]; then +if [ -f "${nix_virtualenv_scripts}/${lazy_wrapper}" ]; then # shellcheck disable=SC1090 - source "${macos_virtualenv_scripts}/${lazy_wrapper}" -elif [ -f "${ubuntu_virtualenv_scripts}/${lazy_wrapper}" ]; then - # shellcheck disable=SC1090 - source "${ubuntu_virtualenv_scripts}/${lazy_wrapper}" + source "${nix_virtualenv_scripts}/${lazy_wrapper}" else echo -e "Could not find virtualenvwrapper_lazy" fi diff --git a/zsh/install.sh b/zsh/install.sh index c0efc206c4..0fc56f0d55 100755 --- a/zsh/install.sh +++ b/zsh/install.sh @@ -5,19 +5,6 @@ SCRIPT_DIR=$(unset CDPATH; cd "$(dirname "$0")" > /dev/null; pwd -P) cd "$(dirname "$0")" -if [ "$(uname -s)" = "Darwin" ]; then - source "${SCRIPT_DIR}/../common/brew.sh" - brew_install zsh -elif [[ "$(lsb_release -i)" == *"Ubuntu"* ]]; then - source "${SCRIPT_DIR}/../common/apt.sh" - # Install 'expect' for testing - apt_install zsh expect -fi - -if ! command -v git > /dev/null; then - "${SCRIPT_DIR}/../git/install.sh" -fi - if [ ! -d ~/.powerlevel10k ]; then git clone https://github.com/romkatv/powerlevel10k.git ~/.powerlevel10k --depth=1 fi @@ -43,7 +30,6 @@ if [ ! -d ~/.zsh-z ]; then fi (cd ~/.zsh-z && git pull --rebase) - # Replace `chsh` with a fail-safe profile/exec dance: # When /bin/sh -> /bin/bash or /bin/zsh are the default shells on the system, # starting a login shell with source ~/.bash_profile or ~/.zprofile respectively. diff --git a/zsh/test.sh b/zsh/test.sh index 20fb7dae4d..f59e09af3e 100755 --- a/zsh/test.sh +++ b/zsh/test.sh @@ -1,6 +1,14 @@ #!/usr/bin/env -S zsh -il set -e +echo "Check if zsh is nix controlled" +actual_path=$(realpath "$(which zsh)") +if [[ "${actual_path}" != /nix/store/* ]]; then + echo "Actual Path: $actual_path" + echo Expected zsh to be managed by nix + exit 1 +fi + echo "Test that start up and basic user input to shell work without errors" # This was added after a faulty linter change led to printing the following on all key presses # sh:1: url-quote-magic: function definition file not found diff --git a/zsh/zshrc.symlink b/zsh/zshrc.symlink index e171f645c5..c7a80d5335 100644 --- a/zsh/zshrc.symlink +++ b/zsh/zshrc.symlink @@ -12,6 +12,10 @@ fi fpath=($DOTS/zsh $fpath) +if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then + . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' +fi + autoload -U start-ssh-and-add-identity start-ssh-and-add-identity