Skip to content

Commit

Permalink
add nixos-wsl config
Browse files Browse the repository at this point in the history
  • Loading branch information
0x77dev committed Jan 11, 2025
1 parent 0b98e4d commit 203cfd5
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/0x77dev/land/build.yaml)
[![Cachix Cache](https://img.shields.io/badge/cachix-land-blue.svg)](https://app.cachix.org/cache/land)
![Maintenance](https://img.shields.io/maintenance/yes/2025)
![Maintenance](https://img.shields.io/maintenance/yes/2025)

My homelab and dotfiles managed with Nix. This repository contains declarative configurations for my machines.

## Overview

This repository uses [Nix](https://nixos.org/) to manage:

- macOS machines (via nix-darwin)
- NixOS systems
- Home Manager configurations
Expand All @@ -17,6 +18,7 @@ This repository uses [Nix](https://nixos.org/) to manage:

1. Install Nix following the [official instructions](https://nixos.org/download.html)
2. Apply configuration:

- For macOS:
```shell
nix run nix-darwin --experimental-features 'nix-command flakes' -- switch --refresh --flake github:0x77dev/land#<hostname>
Expand All @@ -29,6 +31,27 @@ This repository uses [Nix](https://nixos.org/) to manage:
```shell
nix run home-manager --experimental-features 'nix-command flakes' -- switch --refresh --experimental-features 'nix-command flakes' --flake github:0x77dev/land#<username>@<hostname> -b backup
```
- For WSL:

```shell
# Build the tarball
sudo nix run --experimental-features 'nix-command flakes' github:0x77dev/land#nixosConfigurations.wsl.config.system.build.tarballBuilder
```

```powershell
# Import the tarball
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\WSL-Land"
wsl.exe --import Land "$env:USERPROFILE\WSL-Land" nixos-wsl.tar.gz --version 2
```

```powershell
# Set the default user
wsl.exe -d Land -u mykhailo
# Run the WSL instance
wsl.exe -d Land
# Optional: Set NixOS as the default WSL distribution
wsl.exe -s Land
```

## Structure

Expand Down
6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
nixos-generators.nixosModules.all-formats
];
};
wsl = mkNixosConfig {
system = "x86_64-linux";
modules = [
./systems/nixos/wsl/configuration.nix
];
};
};

darwinConfigurations = {
Expand Down
99 changes: 99 additions & 0 deletions systems/nixos/wsl/configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{ pkgs, ... }: {
environment = {
systemPackages = [
pkgs.wget
pkgs.curl
pkgs.git
pkgs.nix-ld
pkgs.cudatoolkit
pkgs.linuxPackages.nvidia_x11
pkgs.libGLU
pkgs.libGL
pkgs.xorg.libXi
pkgs.xorg.libXmu
pkgs.freeglut
pkgs.xorg.libXext
pkgs.xorg.libX11
pkgs.xorg.libXv
pkgs.xorg.libXrandr
pkgs.zlib
pkgs.ncurses5
pkgs.binutils
pkgs.fish
];

variables = {
LD_LIBRARY_PATH = "/usr/lib/wsl/lib:${pkgs.linuxPackages.nvidia_x11}/lib:${pkgs.ncurses5}/lib";
CUDA_PATH = "${pkgs.cudatoolkit}";
EXTRA_LDFLAGS = "-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib";
EXTRA_CCFLAGS = "-I/usr/include";
};
};

programs.nix-ld = {
enable = true;
package = pkgs.nix-ld;
};

vscode-remote-workaround.enable = true;

nixpkgs.config = {
allowUnfree = true;
cudaSupport = true;
};

nix = {
package = pkgs.nix;
settings = {
experimental-features = [ "nix-command" "flakes" ];

# User permissions
trusted-users = [ "root" "mykhailo" ];
trusted-substituters = [ "root" "mykhailo" ];

# Binary caches
substituters = [
"https://cache.nixos.org"
"https://nix-community.cachix.org"
"https://devenv.cachix.org"
"https://land.cachix.org"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
"land.cachix.org-1:9KPti8Xi0UJ7eQof7b8VUzSYU5piFy6WVQ8MDTLOqEA="
];

# Build optimization
max-jobs = "auto";
cores = 0; # Use all available cores
system-features = [ "big-parallel" "benchmark" ];
keep-outputs = true;
keep-derivations = true;
builders-use-substitutes = true; # Allow builders to use substitutes
connect-timeout = 5; # Reduce connection timeout
download-speed = 0; # No limit on download speed
narinfo-cache-negative-ttl = 0; # Don't cache negative lookups
};

# Garbage collection
gc = {
automatic = true;
options = "--delete-older-than 14d";
};

# Store optimization
optimise = {
automatic = true;
};
};

users.users.mykhailo = {
isNormalUser = true;
description = "Mykhailo Marynenko";
extraGroups = [ "wheel" "networkmanager" ];
shell = pkgs.fish;
openssh.authorizedKeys.keys = builtins.fromJSON (builtins.readFile ../../../helpers/openssh-authorized-keys.json);
};
}

0 comments on commit 203cfd5

Please sign in to comment.