GithubHelp home page GithubHelp logo

glauberporto / nixos-wsl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nix-community/nixos-wsl

0.0 0.0 0.0 100 KB

NixOS on WSL(2) [maintainer=@nzbr]

License: Apache License 2.0

Shell 12.19% Nix 87.81%

nixos-wsl's Introduction

NixOS on WSL
Matrix Chat nixpkgs 22.05 Downloads

A minimal root filesystem for running NixOS on WSL. It can be used with DistroLauncher as install.tar.gz or as input to wsl --import --version 2.

Quick start

First, download the latest release's installer.

Then open up a Terminal, PowerShell or Command Prompt and run:

wsl --import NixOS .\NixOS\ nixos-wsl-installer.tar.gz --version 2

This sets up a new WSL distribution NixOS that is installed under .\NixOS. nixos-wsl-installer.tar.gz is the path to the file you downloaded earlier. You might need to change this path or change to the download directory first.

You can now run NixOS:

wsl -d NixOS

The installer will unpack the file system and subsequently start NixOS. A few warnings about file systems and locales will pop up. You can safely ignore them. After systemd has started, you should be greeted with a bash prompt inside your fresh NixOS installation.

If you want to make NixOS your default distribution, you can do so with

wsl -s NixOS

Building your own system tarball

This requires access to a system that already has Nix installed. Please refer to the Nix installation guide if that's not the case.

If you have a flakes-enabled Nix, you can use the following command to build your own tarball instead of relying on a prebuilt one:

nix build github:nix-community/NixOS-WSL#nixosConfigurations.mysystem.config.system.build.installer

Or, if you want to build with local changes, run inside your checkout:

nix build .#nixosConfigurations.mysystem.config.system.build.installer

Without a flakes-enabled Nix, you can build a tarball using:

nix-build -A nixosConfigurations.mysystem.config.system.build.installer

The resulting installer tarball can then be found under ./result/tarball/nixos-wsl-installer.tar.gz.

You can also build a rootfs tarball without wrapping it in the installer by replacing installer with tarball in the above commands. The rootfs tarball can then be found under ./result/tarball/nixos-wsl-x86_64-linux.tar.gz.

Design

Getting NixOS to run under WSL requires some workarounds:

systemd support

WSL comes with its own (non-substitutable) init system while NixOS uses systemd. Simply starting systemd later on does not work out of the box, because systemd as system instance refuses to start if it is not PID 1. This unfortunate combination is resolved in two ways:

  • the user's default shell is replaced by a wrapper script that acts is init system and then drops to the actual shell
  • systemd is started in its own PID namespace; therefore, it is PID 1. The shell wrapper (see above) enters the systemd namespace before dropping to the shell.

Installer

Usually WSL distributions ship as a tarball of their root file system. These tarballs however, can not contain any hard-links due to the way they are unpacked by WSL, resulting in an "Unspecified Error". By default some Nix-derivations will contain hard-links when they are built. This results in system tarballs that can not be imported into WSL. To circumvent this problem, the rootfs tarball is wrapped in that of a minimal distribution (the installer), that is packaged without any hard-links. When the installer system is started for the first time, it overwrites itself with the contents of the rootfs tarball.

License

Apache License, Version 2.0. See LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html for details.

Further links

nixos-wsl's People

Contributors

nzbr avatar trundle avatar veehaitch avatar k900 avatar supersandro2000 avatar ajgrf avatar ajaxbits avatar fruitiex avatar jamiemagee avatar teofilc avatar erikmcclure avatar hschaeidt avatar mausch avatar willbush avatar github-actions[bot] avatar

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.