Skip to content

0xADD1E/nixos-crostini

 
 

Repository files navigation

nixos-crostini: NixOS in ChromeOS

This repository provides configuration and modules to build NixOS containers/images for Crostini (Linux on ChromeOS). The resulting guest supports:

  • clipboard sharing,
  • handling of URIs, URLs, etc,
  • file sharing,
  • X/Wayland forwarding, so that the guest can run GUI applications,
  • port forwarding from guest to host.

See this blog post for more details about LXC support and this one for Baguette support.

Quick start

  1. Install Nix.
  2. Run nix flake init -t github:aldur/nixos-crostini from a new directory (or simply clone this repository).
  3. Edit ./configuration.nix with your username; later on, pick the same when configuring Linux on ChromeOS.

Now build a container image or a VM image.

LXC containers

Crostini runs LXC containers in a VM called termina. This repository provides a Flake output and an NixOS module to build a custom LXC container from your configuration.

LXC: Quick start

# Build the container image and its metadata:
$ nix build .#lxc-image-and-metadata
$ ls result
image.tar.xz  metadata.tar.xz

That's it! See this blog post for a few ways on how to deploy the image on the Chromebook.

LXC: NixOS module

You can also integrate the crostini.nix module in your Nix configuration. If you are using flakes:

  1. Add this flake as an input.
  2. Add inputs.nixos-crostini.nixosModules.crostini to your modules.

Here is a very minimal example:

{
  # Here is the input.
  inputs.nixos-crostini.url = "github:aldur/nixos-crostini";

  # Optional:
  inputs.nixos-crostini.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, nixos-crostini }: {
    # Change to your hostname.
    nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
      modules = [
        ./configuration.nix

        # Here is where it gets added to the modules.
        nixos-crostini.nixosModules.default
      ];
    };

    # Change <system> to  "x86_64-linux", "aarch64-linux"
    # This will allow you to build the image.
    packages."<system>".lxc-image-and-metadata = nixos-crostini.packages."<system>".default;
  };
}

Baguette images

ChromeOS >= 141 provides experimental support for containerless Crostini (aka Baguette). This repository can build Baguette images that provide the same features of LXC containers (clipboard sharing, URIs handling, X/Wayland forwarding, etc) but allow more flexibility/freedom (e.g., to run Kubernetes without KVM).

Baguette: Quick start

# Build the image
$ nix build .#baguette-zimage
$ ls result
baguette_rootfs.img.zst

Tip

This CI pipeline builds Baguette images and uploads them as GitHub workflow artifacts. If you fork this repository and commit a change to ./configuration.nix with your username, the CI will build a Baguette NixOS image with your changes.

Copy baguette_rootfs.img.zst to the Chromebook "Downloads" directory. Open crosh (Ctrl + Alt + t), configure the VM, and launch the image:

vmc create --vm-type BAGUETTE \
  --size 15G \
  --source /home/chronos/user/MyFiles/Downloads/baguette_rootfs.img.zst \
  baguette

vmc start --vm-type BAGUETTE baguette

[aldur@baguette-nixos:~]$

Open new shell sessions with vsh baguette penguin.

This blog post shows further ways to configure, run, and customize a Baguette NixOS image.

Baguette: NixOS module

This flake's nixosModules.baguette module allows building the image through the output nixosConfigurations.baguette-nixos.config.system.build.btrfsImageCompressed.

To adjust the size of the resulting disk image, set virtualisation.diskImageSize (in MiB). You will need enough space to fit your NixOS configuration.

About

NixOS in ChromeOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Nix 95.3%
  • Shell 4.7%