Compare commits

...

14 Commits

Author SHA1 Message Date
a3498dc0e9 docs: add troubleshooting tip for slow docker.service startup 2025-04-02 19:32:28 +03:00
01cadad79b fix: exclude etc directory and wezterm config while copying files from host to wsl 2025-03-27 22:52:48 +03:00
84a04c010b docs: some enchantments 2025-03-27 22:40:08 +03:00
ee9e8205a3 docs: correct terminology 2025-03-27 22:21:05 +03:00
c4d6a4b030 feat: update install script with user/distro name options, update docs 2025-03-27 22:18:29 +03:00
2e531d6e25 feat: powershell install script 2025-03-27 21:37:13 +03:00
721e12bc2d docs: add dos2unix utility, convert wsl.conf to unix format 2025-03-27 20:55:14 +03:00
d091aa7b67 feat: add drag window with CTRL + SHIFT + Left Mouse Button 2025-03-25 23:09:33 +03:00
b00df259dc docs: some additions and rewrites 2025-03-25 20:32:50 +03:00
c260fe3453 Merge remote-tracking branch 'refs/remotes/origin/master' 2025-03-25 18:49:46 +03:00
5137c7aaee docs: update key bindings 2025-03-25 18:49:02 +03:00
3f162167f9 fix: ensure fish is launched as login shell in first window
The SSH agent wasn't properly initializing in the first tmux window becausefish wasn't being launched as a login shell. This caused the condition status is-login to fail, preventing wsl2-ssh-agent from running.
2025-03-25 18:35:49 +03:00
8727f750e2 docs: add tip about $PATH modification with fish 2025-03-25 18:22:13 +03:00
1039d9e81e fix: ssh-agent bridge 2025-03-25 18:21:56 +03:00
5 changed files with 333 additions and 79 deletions

186
Install.ps1 Normal file
View File

@ -0,0 +1,186 @@
param (
[Parameter(Mandatory=$false)]
[string]$DistroName = "Arch",
[Parameter(Mandatory=$false)]
[string]$Username = "user"
)
Write-Host "===== WSL2 Arch Linux Setup Script =====" -ForegroundColor Cyan
Write-Host "Distribution: $DistroName" -ForegroundColor Yellow
Write-Host "Username: $Username" -ForegroundColor Yellow
Write-Host ""
# Check if the specified distro exists
$wslDistros = (wsl --list) -replace "`0", "" | ForEach-Object { $_.Trim() }
$distroExists = $false
foreach ($line in $wslDistros) {
if ($line -match $DistroName) {
$distroExists = $true
break
}
}
if (-not $distroExists) {
Write-Error "Distribution '$DistroName' not found. Please check the name or import it first."
exit 1
}
# Path to current repository
$RepoPath = Get-Location
# Function to replace placeholder values in configuration files
function Update-ConfigFile {
param (
[string]$SourcePath,
[string]$DestinationPath,
[hashtable]$Replacements
)
if (-not (Test-Path $SourcePath)) {
Write-Warning "Source file not found: $SourcePath"
return
}
$content = Get-Content -Path $SourcePath -Raw
foreach ($key in $Replacements.Keys) {
$content = $content -replace $key, $Replacements[$key]
}
Set-Content -Path $DestinationPath -Value $content -Force
Write-Host "Updated configuration in: $DestinationPath" -ForegroundColor Green
}
Write-Host "Step 1: Initial Setup..." -ForegroundColor Green
wsl -d $DistroName -u root bash -c "/usr/lib/wsl/first-setup.sh"
wsl -d $DistroName -u root bash -c "pacman -Syu --noconfirm"
wsl -d $DistroName -u root bash -c "pacman -S --noconfirm sudo git vim neovim openssh wget binutils less debugedit fakeroot fastfetch starship exa fish tmux htop python base-devel go dos2unix"
Write-Host "Step 2: User Configuration..." -ForegroundColor Green
# Set root password
Write-Host "Setting root password..." -ForegroundColor Yellow
wsl -d $DistroName -u root bash -c "passwd"
# Configure locale
Write-Host "Configuring locale..." -ForegroundColor Yellow
wsl -d $DistroName -u root bash -c "echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen"
# Create user if doesn't exist
Write-Host "Setting up user $Username..." -ForegroundColor Yellow
wsl -d $DistroName -u root bash -c "id -u $Username >/dev/null 2>&1 || useradd -m $Username"
# Set user password
Write-Host "Setting password for $Username..." -ForegroundColor Yellow
wsl -d $DistroName -u root bash -c "passwd $Username"
# Configure sudo
Write-Host "Configuring sudo access..." -ForegroundColor Yellow
wsl -d $DistroName -u root bash -c "echo '$Username ALL=(ALL) ALL' > /etc/sudoers.d/$Username"
# Configure WSL default user
Write-Host "Configuring WSL default user..." -ForegroundColor Yellow
$wslConfReplacements = @{
"default=user" = "default=$Username"
}
$tempWslConf = Join-Path $env:TEMP "wsl.conf"
Update-ConfigFile -SourcePath "$RepoPath\wsl\etc\wsl.conf" -DestinationPath $tempWslConf -Replacements $wslConfReplacements
Copy-Item -Path $tempWslConf -Destination "\\wsl$\$DistroName\etc\wsl.conf" -Force
wsl -d $DistroName -u root bash -c "dos2unix /etc/wsl.conf"
Write-Host "Step 3: AUR helper and SSH bridge setup..." -ForegroundColor Green
# Clone and install paru
wsl -d $DistroName -u $Username bash -c "cd /tmp && git clone https://aur.archlinux.org/paru-bin.git && cd paru-bin && makepkg -si --noconfirm"
# Install wsl2-ssh-agent
wsl -d $DistroName -u $Username bash -c "paru -S --noconfirm wsl2-ssh-agent"
# Create .ssh directory
wsl -d $DistroName -u $Username bash -c "mkdir -p ~/.ssh"
Write-Host "Step 4: Copying and updating configuration files..." -ForegroundColor Green
# Create temp directory for modified configs
$tempConfigDir = Join-Path $env:TEMP "wsl-configs"
if (Test-Path $tempConfigDir) {
Remove-Item -Path $tempConfigDir -Recurse -Force
}
New-Item -Path $tempConfigDir -ItemType Directory -Force | Out-Null
# Process and copy WezTerm config to Windows home directory only (not WSL)
$weztermSourcePath = "$RepoPath\windows\.wezterm.lua"
if (Test-Path $weztermSourcePath) {
$weztermTempPath = Join-Path $env:TEMP ".wezterm.lua.temp"
$weztermReplacements = @{
'default_domain = "WSL:Arch"' = "default_domain = `"WSL:$DistroName`""
}
Update-ConfigFile -SourcePath $weztermSourcePath -DestinationPath $weztermTempPath -Replacements $weztermReplacements
Copy-Item -Path $weztermTempPath -Destination "$HOME\.wezterm.lua" -Force
Remove-Item -Path $weztermTempPath -Force
Write-Host "Updated WezTerm configuration in Windows home directory" -ForegroundColor Green
}
# Process and copy all WSL configuration files to temp directory
Get-ChildItem -Path "$RepoPath\wsl" -Recurse -File | Where-Object {
# Exclude etc directory at any level and Windows-specific files
$_.FullName -notmatch "\\etc\\" -and $_.Name -ne ".wezterm.lua"
} | ForEach-Object {
$relativePath = $_.FullName.Substring("$RepoPath\wsl".Length)
$destPath = Join-Path $tempConfigDir $relativePath
$destDir = Split-Path -Parent $destPath
if (-not (Test-Path $destDir)) {
New-Item -Path $destDir -ItemType Directory -Force | Out-Null
}
# Check and replace content if needed based on file type/path
$content = Get-Content -Path $_.FullName -Raw -ErrorAction SilentlyContinue
$needsReplacement = $false
# Check if content contains references to default user or distro name
if ($content -match "user" -or $content -match "Arch") {
$needsReplacement = $true
# Replace username in configuration files
$content = $content -replace "\buser\b", $Username
# Replace distro name in configuration files
$content = $content -replace "\bArch\b", $DistroName
}
if ($needsReplacement) {
Set-Content -Path $destPath -Value $content -Force
Write-Host "Updated configuration in: $relativePath" -ForegroundColor Green
} else {
Copy-Item -Path $_.FullName -Destination $destPath -Force
}
}
# Now copy everything to WSL
Write-Host "Copying updated configuration files to WSL..." -ForegroundColor Yellow
Get-ChildItem -Path $tempConfigDir | ForEach-Object {
Copy-Item -Path $_.FullName -Destination "\\wsl$\$DistroName\home\$Username" -Recurse -Force
}
# Convert line endings for all copied files
Write-Host "Converting line endings for configuration files..." -ForegroundColor Yellow
wsl -d $DistroName -u $Username bash -c "find ~/ -type f -not -path '*/\.git/*' -exec dos2unix {} \; 2>/dev/null || true"
# Fix permissions for configuration files
Write-Host "Setting correct permissions for configuration files..." -ForegroundColor Yellow
$chownCmd = "chown -R " + $Username + ":" + $Username + " /home/" + $Username + "/"
wsl -d $DistroName -u root bash -c $chownCmd
wsl -d $DistroName -u root bash -c "chmod -R 755 /home/$Username/.config/"
wsl -d $DistroName -u root bash -c "chmod 700 /home/$Username/.ssh/ 2>/dev/null || true"
Write-Host "Step 5: Tmux configuration..." -ForegroundColor Green
# Install Tmux Plugin Manager
wsl -d $DistroName -u $Username bash -c "git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm"
Write-Host "Restarting WSL to apply changes..." -ForegroundColor Yellow
wsl --shutdown
Write-Host "===== Setup Complete! =====" -ForegroundColor Cyan
Write-Host "You can now launch your WSL instance with: wsl -d $DistroName" -ForegroundColor Green
Write-Host "Remember to install Tmux plugins by pressing Ctrl+Space, Shift+I when in Tmux" -ForegroundColor Green
Write-Host "Edit tmux.conf (~/.config/tmux/tmux.conf) to specify which disk will be displayed in the status bar." -ForegroundColor Green
Write-Host "The recommended way to use this WSL setup is through WezTerm. After all configurations are complete, launch WezTerm and you should see tmux running with 3 panes automatically." -ForegroundColor Green

207
README.md
View File

@ -1,12 +1,20 @@
# WSL2 Arch Linux Development Environment
My Arch Linux development environment optimized for WSL2, designed for daily workflow. This setup combines essential tools and configurations to create a powerful yet minimalist development workspace, making it perfect for both casual coding sessions and intensive development work.
My minimal setup for Arch Linux development environment optimized for WSL2, designed for daily workflow. This setup combines essential tools and configurations to create a powerful yet minimalist development workspace.
###### Mirror on my [<img src="https://git.zeldon.ru/assets/img/logo.svg" align="center" width="25" height="25"/> Git](https://git.zeldon.ru/zeldon/dotfiles-wsl2)
⚠️ If you encounter an issue with slow startup of `docker.service`, the simplest solution is to disable `systemd-networkd-wait-online`:
```bash
sudo systemctl disable systemd-networkd-wait-online
```
> See: https://github.com/yuk7/ArchWSL/issues/356
## Features
<img src="./.meta/screenshots/wall.png" alt="Rice Showcase" align="right" width="600px">
<img src="./.meta/screenshots/wall.png" alt="Rice Showcase" align="right" width="580px">
### Core Components
@ -29,7 +37,7 @@ My Arch Linux development environment optimized for WSL2, designed for daily wor
### Software Requirements
- Windows 10 version 2004 (build 19041) or higher / Windows 11
- Windows Subsystem for Linux (WSL2) component enabled
- Windows Subsystem for Linux (WSL2) component enabled _*(WSL1 is **not** supported)*_
- Virtual Machine Platform feature enabled
- Windows Terminal (optional but recommended for initial setup)
- Git for Windows
@ -46,7 +54,7 @@ winget install wezterm
git clone https://github.com/xzeldon/dotfiles-wsl2
cd dotfiles-wsl2
# Copy Windows configs
# Copy Windows configs (THIS WILL OVERWRITE FILES IF THEY EXIST!)
Copy-Item -Path ".\windows\*" -Destination $HOME -Force -Recurse
```
@ -74,92 +82,127 @@ wsl --import Arch D:\wsl\Arch "D:\Downloads\archlinux-latest.wsl"
### 3. System Configuration
<details>
<summary><b>Initial Setup</b></summary>
#### Automatic Setup Script (Recommended)
```bash
# Run first-time setup
/usr/lib/wsl/first-setup.sh
The repository includes an automated setup script that performs all the configuration steps described in the manual setup.
# Update system
pacman -Syu
```powershell
# Run the setup script with default values (Distribution: "Arch", Username: "user")
.\Install.ps1
# Install dependencies
pacman -S sudo git vim neovim wget binutils less debugedit fakeroot \
fastfetch starship exa fish tmux htop python
# Or specify your own distribution name and username
.\Install.ps1 -DistroName "YourDistroName" -Username "yourusername"
```
</details>
#### ⚠️ Important Notes About Automatic Setup
<details>
<summary><b>User Configuration</b></summary>
- **Configuration Overwriting**: The script will overwrite the WezTerm configuration file in your Windows home directory. If you have a custom WezTerm setup, make sure to back it up before running the script.
- **Error Handling**: The script does not comprehensively handle all possible errors. If something goes wrong (e.g., incorrect password confirmation, package installation failures), the script will continue execution regardless.
- **Network Requirements**: A stable internet connection is required. Using VPNs or proxies is not recommended due to WSL networking limitations.
- **User Interaction**: You will need to enter passwords for the root and user accounts during script execution.
```bash
# Set root user password
passwd
After the script completes:
# Configure locale
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
1. Start your WSL distribution: `wsl -d YourDistroName`
2. Open tmux and install plugins by pressing `Ctrl+Space` followed by `Shift+I`
3. Edit [tmux.conf](./wsl/.config/tmux/tmux.conf) to specify which disk will be displayed in the status bar.
4. The recommended way to use this WSL setup is through WezTerm. After all configurations are complete, launch WezTerm and you should see tmux running with 3 panes automatically.
# Create user
useradd -m user
# Set user password
passwd user
#### Manual Setup
# Configure sudo
echo "user ALL=(ALL) ALL" >> /etc/sudoers.d/user
> ⚠️ Note: Throughout this guide, we'll use:
>
> - Distribution name: `Arch` (if you choose a different name, update it in WezTerm config under `default_domain = "WSL:Arch"`)
> - Username: `user` (if you want a different username, update relevant configs like `./wsl/etc/wsl.conf`)
# Configure WSL default user
# 1. Copy WSL configuration file from host to guest
# (From Windows PowerShell, assuming you're in the repo directory and Arch is a WSL distribution name, from 2.2)
cp .\wsl\etc\wsl.conf \\wsl$\Arch\etc\wsl.conf
If you prefer a manual setup or need more control over the installation process, follow these steps:
# 2. Restart WSL for changes to take effect
# (Run this in PowerShell on Windows)
wsl --shutdown
```
1. **Initial System Setup**
</details>
```bash
# Run first-time setup
/usr/lib/wsl/first-setup.sh
<details>
<summary><b>Development Tools</b></summary>
# Update system
pacman -Syu
```bash
# Install AUR helper
git clone https://aur.archlinux.org/paru-bin.git
cd paru-bin
makepkg -si
# Install agent for ssh bridge (see: https://wiki.archlinux.org/title/Install_Arch_Linux_on_WSL#Bridge_the_ssh-agent_service_from_Windows)
paru -S wsl2-ssh-agent
```
### Copy Configuration Files
You need to copy all configuration files from the repository to your WSL environment:
1. From Windows PowerShell:
```powershell
# Assuming you're in the repo directory and Arch is a WSL distribution name, from 2.2
cp -r .\wsl\* \\wsl$\Arch\home\user\
# Install dependencies
pacman -S sudo git vim neovim openssh wget binutils less debugedit fakeroot \
fastfetch starship exa fish tmux htop python base-devel go dos2unix
```
</details>
2. **User Configuration**
### 4. Final Setup
```bash
# Set root user password
passwd
```bash
# Install Tmux Plugin Manager
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
# Configure locale
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
# Start tmux and install plugins
tmux attach # Then press Ctrl+Space, Shift+I
```
# Create user
useradd -m user
> Tip: edit [tmux.conf](./wsl/.config/tmux/tmux.conf) to change disk in status bar
# Set user password
passwd user
# Configure sudo
echo "user ALL=(ALL) ALL" >> /etc/sudoers.d/user
```
3. **WSL Configuration**
```bash
# On Windows (PowerShell):
# Assuming:
# - You're in the repository root directory
# - Your WSL distribution is named "Arch" (from section 2.2)
# Copy WSL configuration file from host to guest
cp .\wsl\etc\wsl.conf \\wsl.localhost\Arch\etc\wsl.conf
# In WSL (Arch Linux):
# Convert line endings from Windows (CRLF) to Unix (LF) format
dos2unix /etc/wsl.conf
# On Windows (PowerShell):
# Restart WSL to apply changes
wsl --shutdown
```
4. **AUR Helper and SSH Bridge Setup**
```bash
# Install AUR helper
git clone https://aur.archlinux.org/paru-bin.git
cd paru-bin
makepkg -si
# Install agent for ssh bridge
# (see: https://wiki.archlinux.org/title/Install_Arch_Linux_on_WSL#Bridge_the_ssh-agent_service_from_Windows)
paru -S wsl2-ssh-agent
# Create .ssh directory (this does not exist by default, but is required for wsl2-ssh-agent)
mkdir ~/.ssh
```
5. **Copy Configuration Files**
```powershell
# From Windows PowerShell:
# Assuming you're in the repo directory, `Arch` is your WSL distribution name and username is `user`
Copy-Item -Path .\wsl\* -Destination \\wsl.localhost\Arch\home\user -Recurse -Force -Exclude "etc"
```
6. **Tmux Setup**
```bash
# Install Tmux Plugin Manager
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
# Start tmux and install plugins
tmux # Then press Ctrl+Space, Shift+I
```
## Configuration
@ -180,12 +223,26 @@ tmux attach # Then press Ctrl+Space, Shift+I
### Key Bindings
| Binding | Action |
| ------------------ | ----------------------- |
| `Ctrl + Space` | Tmux prefix |
| `Prefix + I` | Install Tmux plugins |
| `Ctrl + Shift + Q` | Close WezTerm window |
| `Ctrl + Shift + M` | Minimize WezTerm window |
#### Tmux
| Binding | Action |
| -------------- | ---------------------------- |
| `Ctrl + Space` | Tmux prefix |
| `Prefix + I` | Install Tmux plugins |
| `Prefix + c` | Create new pane |
| `Prefix + %` | Create new pane vertically |
| `Prefix + "` | Create new pane horizontally |
| `Prefix + x` | Kill current pane |
#### WezTerm
| Binding | Action |
| ---------------------------------- | ----------------------- |
| `Ctrl + Shift + Q` | Close WezTerm window |
| `Ctrl + Shift + M` | Minimize WezTerm window |
| `Ctrl + Shift + Left Mouse Button` | Drag to move mode |
> Tip: use `fish_add_path /some/path/bin` to add directories to $PATH. See: https://fishshell.com/docs/current/cmds/fish_add_path.html
## License

View File

@ -38,7 +38,7 @@ return {
window_close_confirmation = "NeverPrompt",
-- Startup program
default_domain = "WSL:arch",
default_domain = "WSL:Arch",
-- Remap keys
keys = {
@ -47,5 +47,14 @@ return {
mods = "CTRL",
action = wezterm.action.CloseCurrentTab { confirm = false },
},
},
-- Drag window
mouse_bindings = {
{
event = { Drag = { streak = 1, button = 'Left' } },
mods = 'CTRL',
action = wezterm.action.StartWindowDrag,
},
}
}

View File

@ -21,6 +21,8 @@ if status is-interactive
end
# Configure ssh-agent for WSL, see: https://github.com/mame/wsl2-ssh-agent
set -x SSH_AUTH_SOCK /home/user/.ssh/wsl2-ssh-agent.sock
if status is-login
/usr/sbin/wsl2-ssh-agent | source
end
starship init fish | source
starship init fish | source

View File

@ -61,7 +61,7 @@ set-window-option -g window-status-current-style bg=default
# Create a single default session - because a session is created here, tmux
# should be started with "tmux attach" rather than "tmux new"
new -d -s1 -nfish 'fish'
new -d -s1 -nfish 'fish -l'
set -t1:1 monitor-activity on
set -t1:1 aggressive-resize on
neww -d