Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .Xresources
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,3 @@ URxvt*scrollColor: S_base02
!! scroll back in things like 'less'
!!URxvt.secondaryScreen: 1
!!URxvt.secondaryScroll: 0







15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.0
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
home.nix

# haskell settings
*xmonad.errors
*xmonad.state
Expand All @@ -23,3 +21,9 @@ cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*

# Nix
result
result-*
.direnv
.envrc
36 changes: 35 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.4.0
hooks:
- id: check-yaml
- id: check-toml
- id: check-json
exclude: '.*/coc-settings\.json'
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: detect-private-key
- id: no-commit-to-branch
args: [--branch, master, --branch, main]

- repo: https://github.com/nix-community/nixpkgs-fmt
rev: v1.3.0
hooks:
- id: nixpkgs-fmt

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.5
hooks:
- id: shellcheck
args: [--severity=warning]
exclude: '.*/zsh-themes/.*'

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.5.3
hooks:
- id: commitizen
stages: [commit-msg]

#- repo: local
# hooks:
# - id: nix-flake-check
# name: Nix flake check
# entry: nix flake check
# language: system
# pass_filenames: false
# files: '\.nix$'
#
8 changes: 8 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Disable warning about sourcing non-constant files (like ~/.xprofile)
disable=SC1090

# Disable warning about ShellCheck only supporting sh/bash/dash/ksh
disable=SC1071

# Disable warning about POSIX sh source undefined (we know our environment)
disable=SC3046
Empty file modified .xprofile
100755 → 100644
Empty file.
71 changes: 53 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
# Andrew Wright's Dotfiles/Nix Config

I use [nix](https://nixos.org/nix/) and [home manager](https://github.com/rycee/home-manager) to manage my applications and dotfiles.
I use [nix](https://nixos.org/nix/) and [home manager](https://github.com/rycee/home-manager) with flakes to manage my applications and dotfiles.

I use `zsh` as my main shell, customized using `oh-my-zsh`.

![Terminal.app](https://raw.github.com/aywrite/nix-config/master/terminal.png)

## Installation

This repository contains user configuration deployed using the helpful tool [Home Manager](https://github.com/rycee/home-manager). The organisation of my nix files are based on [Hugo Reeves' blog post](https://hugoreeves.com/posts/2019/nix-home). In order to setup a new home space, simply add a home.nix file similar to this one.
This repository contains user configuration deployed using [Home Manager](https://github.com/rycee/home-manager) with Nix flakes. The configuration is organized into modular components that can be mixed and matched for different machines and roles.

```nix
{ config, pkgs, ... }:
### Quick Start

{
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
1. Clone and install:
```bash
curl -L https://raw.githubusercontent.com/aywrite/nix-config/master/install.sh | bash
```

2. Switch to your configuration:
```bash
cd ~/.config/nixpkgs

# For WSL:
home-manager switch --flake .#awright-wsl

imports = [
./machine/t460.nix
./user/awright-personal.nix
./role/xmonad-laptop.nix
];
}
# For XPS 13 with Sway:
home-manager switch --flake .#awright-xps13

# For Work MacBook:
home-manager switch --flake .#awright-work-mbp
```

- **Programs** contains default setting for various programs & tools.
- **Machines** contains configuration specific to a given machine.
- **Users** contains configuration specific to a given user, think git config etc.
- **Roles** contains the bulk of the configuration and sets up most user space tools, think neovim and your terminal.
## Configuration Structure

The configuration is organized into several directories:

- **programs/**: Contains default settings for various programs & tools
- **machines/**: Machine-specific configurations (hardware, display, etc.)
- **users/**: User-specific configurations (git config, personal preferences)
- **roles/**: Role-based configurations that set up specific environments:
- `ubuntu-wsl.nix`: Configuration for WSL environment
- `sway-laptop.nix`: Configuration for Sway window manager on laptops
- `darwin-laptop.nix`: Configuration for macOS environments

### Base Configuration
All machine configurations inherit from a base configuration in `home.nix` which sets up core Home Manager settings. Machine-specific configurations then add their own modules and roles on top of this base.

### Available Profiles

1. **WSL Profile** (`awright-wsl`):
- Base configuration
- Personal user settings
- WSL-specific adaptations

2. **XPS 13 Profile** (`awright-xps13`):
- Base configuration
- Personal user settings
- Sway window manager setup
- Laptop-specific configurations

3. **Work MacBook Profile** (`awright-work-mbp`):
- Base configuration
- Work user settings
- macOS-specific adaptations
- Work-related tools and configurations

## Customize

Expand All @@ -38,7 +73,7 @@ The dotfiles can be easily extended to suit additional local requirements by usi

#### `~/.zsh.local`

If the `~/.zsh.local` file exists, it will be automatically sourced. This allows the use of environment variables to store secrets without checking them in. In the future I might use something like git-crypt to check in encrypted secrets instead.
If the `~/.zsh.local` file exists, it will be automatically sourced. This allows the use of environment variables to store secrets without checking them in.

## Acknowledgements

Expand Down
115 changes: 83 additions & 32 deletions bin/free-some-space.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,98 @@ set -o errexit
set -o nounset
set -o pipefail

INITIAL_ROOT=$(df -h)
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# debian packages
if command -v apt; then
sudo apt autoremove
sudo apt-get autoclean
fi
# Function to print colored messages
log() {
echo -e "${BLUE}==>${NC} $1"
}

# pacman packages
if command -v paccache; then
sudo paccache -r
fi
if command -v pacman; then
sudo pacman -Sc
fi
success() {
echo -e "${GREEN}==>${NC} $1"
}

# yay cache (aur only)
if command -v yay; then
yay -Sc --aur
fi
error() {
echo -e "${RED}==>${NC} $1"
}

# docker
if command -v docker; then
docker system prune
fi
# Function to get size in megabytes
get_size() {
df -BM "$1" | awk 'NR==2 {sub(/M$/,"",$4); print $4}'
}

# Function to run command if it exists
run_if_exists() {
local cmd=$1
shift
if command -v "$cmd" >/dev/null 2>&1; then
log "Running $cmd cleanup..."
"$@"
fi
}

# Store initial space
SPACE_BEFORE=$(get_size "/")
log "Initial free space: ${SPACE_BEFORE}M"

# nix/nixos
if command -v nix; then
nix-collect-garbage --delete-older-than 30d
nix optimise-store
# Debian/Ubuntu package cleanup
run_if_exists apt \
bash -c 'sudo apt autoremove -y && sudo apt-get autoclean -y'

# Arch Linux package cleanup
run_if_exists paccache \
sudo paccache -r
run_if_exists pacman \
sudo pacman -Sc --noconfirm

# AUR package cleanup
run_if_exists yay \
yay -Sc --aur --noconfirm

# Docker cleanup
if command -v docker >/dev/null 2>&1; then
log "Cleaning Docker..."
docker system prune -f
# Remove dangling volumes
docker volume prune -f
# Remove unused images
docker image prune -a -f --filter "until=720h"
fi

# yarn
if command -v yarn; then
yarn cache clean
# Nix cleanup
if command -v nix >/dev/null 2>&1; then
log "Cleaning Nix store..."
# Remove old generations
nix-collect-garbage --delete-older-than 30d
# Remove all unused paths
nix-store --gc
# Optimize store
nix store optimise
# Clean old roots
rm -f ~/.local/state/nix/profiles/home-manager*-link
fi

# Node.js package managers cleanup
run_if_exists yarn \
yarn cache clean
run_if_exists npm \
npm cache clean --force
run_if_exists pnpm \
pnpm store prune

# logs
if command -v journalctl; then
run_if_exists journalctl \
journalctl --vacuum-time=30d
fi

# Report usage changes
diff <(echo "$INITIAL_ROOT") <(df -h) | colordiff
# Final space check
SPACE_AFTER=$(get_size "/")
SPACE_SAVED=$(echo "$SPACE_AFTER $SPACE_BEFORE" | awk '{printf "%d", $1 - $2}')

success "Cleanup complete!"
success "Free space before: ${SPACE_BEFORE}M"
success "Free space after: ${SPACE_AFTER}M"
success "Space saved: ${SPACE_SAVED}M"
7 changes: 3 additions & 4 deletions bin/screenctl
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash
gen_list() {
for cfg_script in ~/.screenlayout/*.sh; do
echo $(basename $cfg_script)
echo "$(basename "$cfg_script")"
done
}

if [[ -z "$@" ]]; then
if [[ -z "$*" ]]; then
gen_list
else
~/.reset_screen.sh
bash ~/.screenlayout/$@
bash ~/.screenlayout/"$*"
fi

Loading
Loading