Skip to content

Commit

Permalink
feat: use nix across platforms
Browse files Browse the repository at this point in the history
Fixes #792, #778
  • Loading branch information
kaihowl committed Nov 9, 2024
1 parent 2299fdf commit 615906e
Show file tree
Hide file tree
Showing 33 changed files with 307 additions and 152 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
12 changes: 2 additions & 10 deletions alacritty/install.sh
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions alacritty/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions ccache/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions clangd/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions cmake/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions colors/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 0 additions & 5 deletions common/apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 8 additions & 19 deletions common/python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,27 @@

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
# first place. venv seems to have the most support throughout macOS / Ubuntu.
# 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() {
Expand Down
8 changes: 8 additions & 0 deletions ctags/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions efm/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
64 changes: 64 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 ];
};
};
};
}
5 changes: 3 additions & 2 deletions fzf/bootstrap.zsh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions fzf/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions gdb/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions gdb/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)}')
Expand Down
8 changes: 8 additions & 0 deletions git/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 615906e

Please sign in to comment.