mirror of
https://github.com/xzeldon/dotfiles-wsl2.git
synced 2025-04-20 14:35:47 +03:00
Compare commits
No commits in common. "84a04c010b8a1a98e3ca4e4309e9ec2ac97308d9" and "721e12bc2d54a8bb951fa584e6ef22d910488b98" have entirely different histories.
84a04c010b
...
721e12bc2d
182
Install.ps1
182
Install.ps1
@ -1,182 +0,0 @@
|
|||||||
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 if it exists
|
|
||||||
$weztermSourcePath = "$RepoPath\windows\.wezterm.lua"
|
|
||||||
if (Test-Path $weztermSourcePath) {
|
|
||||||
$weztermDestPath = Join-Path $tempConfigDir ".wezterm.lua"
|
|
||||||
$weztermReplacements = @{
|
|
||||||
'default_domain = "WSL:Arch"' = "default_domain = `"WSL:$DistroName`""
|
|
||||||
}
|
|
||||||
Update-ConfigFile -SourcePath $weztermSourcePath -DestinationPath $weztermDestPath -Replacements $weztermReplacements
|
|
||||||
Copy-Item -Path $weztermDestPath -Destination "$HOME\.wezterm.lua" -Force
|
|
||||||
}
|
|
||||||
|
|
||||||
# Process and copy all other configuration files from the repository to WSL
|
|
||||||
# First copy to temp directory with replacements
|
|
||||||
Get-ChildItem -Path "$RepoPath\wsl" -Exclude "etc" -Recurse -File | 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
|
|
97
README.md
97
README.md
@ -6,7 +6,7 @@ My minimal setup for Arch Linux development environment optimized for WSL2, desi
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
<img src="./.meta/screenshots/wall.png" alt="Rice Showcase" align="right" width="580px">
|
<img src="./.meta/screenshots/wall.png" alt="Rice Showcase" align="right" width="600px">
|
||||||
|
|
||||||
### Core Components
|
### Core Components
|
||||||
|
|
||||||
@ -29,13 +29,18 @@ My minimal setup for Arch Linux development environment optimized for WSL2, desi
|
|||||||
### Software Requirements
|
### Software Requirements
|
||||||
|
|
||||||
- Windows 10 version 2004 (build 19041) or higher / Windows 11
|
- Windows 10 version 2004 (build 19041) or higher / Windows 11
|
||||||
- Windows Subsystem for Linux (WSL2) component enabled _*(WSL1 is **not** supported)*_
|
- Windows Subsystem for Linux (WSL2) component enabled
|
||||||
- Virtual Machine Platform feature enabled
|
- Virtual Machine Platform feature enabled
|
||||||
- Windows Terminal (optional but recommended for initial setup)
|
- Windows Terminal (optional but recommended for initial setup)
|
||||||
- Git for Windows
|
- Git for Windows
|
||||||
|
|
||||||
> Note: WSL2 is configured to use up to 16GB of RAM in this setup (can be adjusted in [.wslconfig](./windows/.wslconfig))
|
> Note: WSL2 is configured to use up to 16GB of RAM in this setup (can be adjusted in [.wslconfig](./windows/.wslconfig))
|
||||||
|
|
||||||
|
> 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`)
|
||||||
|
|
||||||
### 1. Windows Host Setup
|
### 1. Windows Host Setup
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
@ -46,7 +51,7 @@ winget install wezterm
|
|||||||
git clone https://github.com/xzeldon/dotfiles-wsl2
|
git clone https://github.com/xzeldon/dotfiles-wsl2
|
||||||
cd dotfiles-wsl2
|
cd dotfiles-wsl2
|
||||||
|
|
||||||
# Copy Windows configs (THIS WILL OVERWRITE FILES IF THEY EXIST!)
|
# Copy Windows configs (THIS OVERWRITE IF FILES EXISTS!)
|
||||||
Copy-Item -Path ".\windows\*" -Destination $HOME -Force -Recurse
|
Copy-Item -Path ".\windows\*" -Destination $HOME -Force -Recurse
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -74,41 +79,8 @@ wsl --import Arch D:\wsl\Arch "D:\Downloads\archlinux-latest.wsl"
|
|||||||
|
|
||||||
### 3. System Configuration
|
### 3. System Configuration
|
||||||
|
|
||||||
#### Automatic Setup Script (Recommended)
|
<details>
|
||||||
|
<summary><b>Initial Setup</b></summary>
|
||||||
The repository includes an automated setup script that performs all the configuration steps described in the manual setup.
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# Run the setup script with default values (Distribution: "Arch", Username: "user")
|
|
||||||
.\Install.ps1
|
|
||||||
|
|
||||||
# Or specify your own distribution name and username
|
|
||||||
.\Install.ps1 -DistroName "YourDistroName" -Username "yourusername"
|
|
||||||
```
|
|
||||||
|
|
||||||
#### ⚠️ Important Notes About Automatic Setup
|
|
||||||
|
|
||||||
- **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.
|
|
||||||
|
|
||||||
After the script completes:
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
#### Manual Setup
|
|
||||||
|
|
||||||
> ⚠️ 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`)
|
|
||||||
|
|
||||||
If you prefer a manual setup or need more control over the installation process, follow these steps:
|
|
||||||
|
|
||||||
1. **Initial System Setup**
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Run first-time setup
|
# Run first-time setup
|
||||||
@ -122,7 +94,10 @@ If you prefer a manual setup or need more control over the installation process,
|
|||||||
fastfetch starship exa fish tmux htop python base-devel go dos2unix
|
fastfetch starship exa fish tmux htop python base-devel go dos2unix
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **User Configuration**
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>User Configuration</b></summary>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Set root user password
|
# Set root user password
|
||||||
@ -134,17 +109,14 @@ If you prefer a manual setup or need more control over the installation process,
|
|||||||
|
|
||||||
# Create user
|
# Create user
|
||||||
useradd -m user
|
useradd -m user
|
||||||
|
|
||||||
# Set user password
|
# Set user password
|
||||||
passwd user
|
passwd user
|
||||||
|
|
||||||
# Configure sudo
|
# Configure sudo
|
||||||
echo "user ALL=(ALL) ALL" >> /etc/sudoers.d/user
|
echo "user ALL=(ALL) ALL" >> /etc/sudoers.d/user
|
||||||
```
|
|
||||||
|
|
||||||
3. **WSL Configuration**
|
# Configure WSL default user
|
||||||
|
|
||||||
```bash
|
|
||||||
# On Windows (PowerShell):
|
# On Windows (PowerShell):
|
||||||
# Assuming:
|
# Assuming:
|
||||||
# - You're in the repository root directory
|
# - You're in the repository root directory
|
||||||
@ -161,7 +133,10 @@ If you prefer a manual setup or need more control over the installation process,
|
|||||||
wsl --shutdown
|
wsl --shutdown
|
||||||
```
|
```
|
||||||
|
|
||||||
4. **AUR Helper and SSH Bridge Setup**
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Aur helper and ssh bridge</b></summary>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Install AUR helper
|
# Install AUR helper
|
||||||
@ -169,23 +144,31 @@ If you prefer a manual setup or need more control over the installation process,
|
|||||||
cd paru-bin
|
cd paru-bin
|
||||||
makepkg -si
|
makepkg -si
|
||||||
|
|
||||||
# Install agent for ssh bridge
|
# Install agent for ssh bridge (see: https://wiki.archlinux.org/title/Install_Arch_Linux_on_WSL#Bridge_the_ssh-agent_service_from_Windows)
|
||||||
# (see: https://wiki.archlinux.org/title/Install_Arch_Linux_on_WSL#Bridge_the_ssh-agent_service_from_Windows)
|
|
||||||
paru -S wsl2-ssh-agent
|
paru -S wsl2-ssh-agent
|
||||||
|
|
||||||
# Create .ssh directory (this does not exist by default, but is required for wsl2-ssh-agent)
|
# Create .ssh directory (this not exists by default, but required for wsl2-ssh-agent)
|
||||||
mkdir ~/.ssh
|
mkdir ~/.ssh
|
||||||
```
|
```
|
||||||
|
|
||||||
5. **Copy Configuration Files**
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Copy Configuration Files</b></summary>
|
||||||
|
|
||||||
|
You need to copy all configuration files from the repository to your WSL environment:
|
||||||
|
|
||||||
|
From powershell:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
# From Windows PowerShell:
|
# Assuming you're in the repo directory, `Arch` is a WSL distribution name (from 2.2) and arch username is `user`
|
||||||
# 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"
|
Copy-Item -Path .\wsl\* -Destination \\wsl.localhost\Arch\home\user -Recurse -Force -Exclude "etc"
|
||||||
```
|
```
|
||||||
|
|
||||||
6. **Tmux Setup**
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Tmux configuration</b></summary>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Install Tmux Plugin Manager
|
# Install Tmux Plugin Manager
|
||||||
@ -195,6 +178,10 @@ If you prefer a manual setup or need more control over the installation process,
|
|||||||
tmux # Then press Ctrl+Space, Shift+I
|
tmux # Then press Ctrl+Space, Shift+I
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
> Tip: edit [tmux.conf](./wsl/.config/tmux/tmux.conf) to change disk in status bar
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
### File Structure
|
### File Structure
|
||||||
@ -217,12 +204,12 @@ If you prefer a manual setup or need more control over the installation process,
|
|||||||
#### Tmux
|
#### Tmux
|
||||||
|
|
||||||
| Binding | Action |
|
| Binding | Action |
|
||||||
| -------------- | ---------------------------- |
|
| -------------- | ------------------------------ |
|
||||||
| `Ctrl + Space` | Tmux prefix |
|
| `Ctrl + Space` | Tmux prefix |
|
||||||
| `Prefix + I` | Install Tmux plugins |
|
| `Prefix + I` | Install Tmux plugins |
|
||||||
| `Prefix + c` | Create new pane |
|
| `Prefix + c` | Create new window |
|
||||||
| `Prefix + %` | Create new pane vertically |
|
| `Prefix + %` | Create new window vertically |
|
||||||
| `Prefix + "` | Create new pane horizontally |
|
| `Prefix + "` | Create new window horizontally |
|
||||||
| `Prefix + x` | Kill current pane |
|
| `Prefix + x` | Kill current pane |
|
||||||
|
|
||||||
#### WezTerm
|
#### WezTerm
|
||||||
|
Loading…
x
Reference in New Issue
Block a user