Code Monkey home page Code Monkey logo

nixos-wsl-starter's Introduction

nixos-wsl-starter

This repository is intended to be a sane, batteries-included starter template for running a JeezyVim-powered NixOS development environment on WSL.

If you don't want to dig into NixOS too much right now, the only file you need to concern yourself with is home.nix. This is where you can add and remove binaries to your global $PATH.

Go to https://search.nixos.org to find the correct package names, though usually they will be what you expect them to be in other package managers.

unstable-packages is for packages that you want to always keep at the latest released versions, and stable-packages is for packages that you want to track with the current release of NixOS (currently 24.05).

If you want to update the versions of the available unstable-packages, run nix flake update to pull the latest version of the Nixpkgs repository and then apply the changes.

Make sure to look at all the FIXME notices in the various files which are intended to direct you to places where you may want to make configuration tweaks.

If you found this starter template useful, please consider sponsoring and subscribing to my YouTube channel.

What Is Included

This starter is a lightly-opinionated take on a productive terminal-driven development environment based on my own preferences. However, it is trivial to customize to your liking both by removing and adding tools that you prefer.

  • The default editor is JeezyVim
  • win32yank is used to ensure perfect bi-directional copying and pasting to and from Windows GUI applications and LunarVim running in WSL
  • The default shell is fish
  • Native docker (ie. Linux, not Windows) is enabled by default
  • The prompt is Starship
  • fzf, lsd, zoxide, and broot are integrated into fish by default
    • These can all be disabled easily by setting enable = false in home.nix, or just removing the lines all together
  • direnv is integrated into fish by default
  • git config is generated in home.nix with options provided to enable private HTTPS clones with secret tokens
  • fish config is generated in home.nix and includes git aliases, useful WSL aliases

win32yank

There have been some recent changes in WSL2 that make running win32yank within WSL2 very slow. You should install this on Windows by running scoop install win32yank or compiling it from source, and then adding it to your $PATH:

{
    programs.fish = {
      interactiveShellInit = ''
        fish_add_path --append /mnt/c/Users/<Your Windows Username>/scoop/apps/win32yank/0.1.1
      '';
    };
}

Quickstart

Watch the walkthrough video

  • Get the latest release
  • Install it (tweak the command to your desired paths):
wsl --import NixOS .\NixOS\ .\nixos-wsl.tar.gz --version 2
  • Enter the distro:
wsl -d NixOS
  • Get a copy of this repo (you'll probably want to fork it eventually):
git clone https://github.com/LGUG2Z/nixos-wsl-starter.git /tmp/configuration
cd /tmp/configuration
  • Change the username to your desired username in flake.nix with nvim (or whichever editor you prefer)
  • Install win32yank with scoop and add it to your $PATH in NixOS
  • Apply the configuration and shutdown the WSL2 VM
sudo nixos-rebuild switch --flake /tmp/configuration && sudo shutdown -h now
  • Reconnect to the WSL2 VM
wsl -d NixOS
  • cd ~ and then pwd should now show /home/<YOUR_USERNAME>
  • Move the configuration to your new home directory
mv /tmp/configuration ~/configuration
  • Go through all the FIXME: notices in ~/configuration and make changes wherever you want
  • Apply the configuration
sudo nixos-rebuild switch --flake ~/configuration

Note: If developing in Rust, you'll still be managing your toolchains and components like rust-analyzer with rustup!

Project Layout

In order to keep the template as approachable as possible for new NixOS users, this project uses a flat layout without any nesting or modularization.

  • flake.nix is where dependencies are specified
    • nixpkgs is the current release of NixOS
    • nixpkgs-unstable is the current trunk branch of NixOS (ie. all the latest packages)
    • home-manager is used to manage everything related to your home directory (dotfiles etc.)
    • nur is the community-maintained Nix User Repositories for packages that may not be available in the NixOS repository
    • nixos-wsl exposes important WSL-specific configuration options
    • nix-index-database tells you how to install a package when you run a command which requires a binary not in the $PATH
  • wsl.nix is where the VM is configured
    • The hostname is set here
    • The default shell is set here
    • User groups are set here
    • WSL configuration options are set here
    • NixOS options are set here
  • home.nix is where packages, dotfiles, terminal tools, environment variables and aliases are configured

nixos-wsl-starter's People

Contributors

backwardspy avatar lgug2z avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nixos-wsl-starter's Issues

failed to use VSCode WSL

After I uncommented the vscode-remote-workaround block, it still doesn't work with the vscode wsl.

VSCode WSL Extension Log

image

Starting server: /home/nixos/.vscode-server/bin/d037ac076cee195194f93ce6fe2bdfe2969cc82d/bin/code-server --host=127.0.0.1 --port=0 --connection-token=1057041771-2303584977-2822485713-267384198 --use-host-proxy --without-browser-env-var --disable-websocket-compression --accept-server-license-terms --disable-telemetry --telemetry-level=off

WSL Version

WSL 版本: 2.0.4.0
内核版本: 5.15.123.1-1
WSLg 版本: 1.0.58
MSRDC 版本: 1.2.4485
Direct3D 版本: 1.608.2-61064218
DXCore 版本: 10.0.25880.1000-230602-1350.main
Windows 版本: 10.0.22621.2506

( 版本 means version, 内核 means kernel)

git.sr.ht down

In case anyone is trying to follow this wonderful guide, during the initial rebuild process of switching to the flake.. It makes calls to https://git.sr.ht which are currently failing.

This is due to the service being down temporarily due to a DDoS attack against SourceHut.

I thought it was a me issue until researching into potential causes of the problem.

This is NOT due to anything directly related to this repo and its code. I'm supplying this as an FYI in case someone somehow ends up in the situation I was in a few moments ago. Figured I'd share!

Reference:

https://status.sr.ht/

Fonts not correctly set

Hi,
I am quite new to NixOS, but I noticed that after following the instructions the fonts are not correctly set - the icons for example for folders and files when using ls are not displayed correctly (just squares). There might be a step I am missing?

WSL integration with distro 'NixOS' not working in Docker desktop

Hi, first I want to thank you for this GREAT project to let me get started NixOS. I have configure almost everything well with no pains. but there is still a problem I can't figure it out. that is Docker Desktop.

I am using win11 and wsl2, I've enabled docker and docker desktop in wsl.nix and switched NixOS to the default distro of wsl2, but I founded docker desktop cannot started correctly, here is the screenshot of the error:
image

I also checked the status of docker-desktop-proxy, here is the output:

nixos in ~
❯ sudo systemctl status docker-desktop-proxy
● docker-desktop-proxy.service - Docker Desktop proxy
     Loaded: loaded (/etc/systemd/system/docker-desktop-proxy.service; enabled; preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Sat 2024-08-03 15:32:51 CST; 7s ago
    Process: 13271 ExecStart=/nix/store/xz7p4371jm2vc5x7b8db72rk2dvkg5g9-unit-script-docker-desktop-proxy-start/bin/docker-desktop-proxy-start (code=exited, status=1/FAILURE)
   Main PID: 13271 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out

here is main parts in wsl.nix about docker and docker desktop

  users.users.${username} = {
    isNormalUser = true;
    # FIXME: change your shell here if you don't want fish
    shell = pkgs.fish;
    extraGroups = [
      "wheel"
      # FIXME: uncomment the next line if you want to run docker without sudo
      "docker"
    ];
  };
  # ......
  wsl = {
    enable = true;
    wslConf.automount.root = "/mnt";
    wslConf.interop.appendWindowsPath = false;
    wslConf.network.generateHosts = false;
    defaultUser = username;
    startMenuLaunchers = true;

    # Enable integration with Docker Desktop (needs to be installed)
    docker-desktop.enable = true;
  };

  virtualisation.docker = {
    enable = true;
    enableOnBoot = true;
    autoPrune.enable = true;
  };

I reboot several times and the problem persists. I google for a while but I didn't find any clues. Is there anything I misconfigured?

Unable to provide interactive input from shell

Hi @LGUG2Z ,

Thanks for this nice update. I just updated to the latest release. There seems to be some issue with the shell like I cannot enter interactive input from the shell. Currently I have a flake.nix which points to a private repo in GitLab and requires me to input username and password but I cannot enter anything in the shell. The shell just gets stuck on the below mentioned command:

Username for 'https://gitlab.com':

I didn't have this issue in the earlier version i.e. nixos-wsl-starter(23.11) which was based on zsh and Lvim. So I tried to test by changing all the configuration for the shell back to zsh and Lvim and it seems to work as I can provide the username and password.

I might be missing some configuration for fish and JeezyVim.

Any suggestion ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.