This repository provides configuration and modules to build NixOS images/containers 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,
- notification forwarding from guest to ChromeOS.
See this blog post for more details about LXC support and this one for Baguette support.
- Install Nix.
- Enable flake support:
export NIX_CONFIG="experimental-features = nix-command flakes". - Run
nix flake init -t github:aldur/nixos-crostinifrom a new directory (or simply clone this repository). - Edit
./configuration.nixwith your username; later on, pick the same when configuring Linux on ChromeOS.
Now build a VM image or container image.
ChromeOS >= 143 supports containerless Crostini (aka Baguette), providing more flexibility than legacy LXC containers.
Tip
This CI pipeline builds Baguette images for both ARM64 and x86_64 and
uploads them as GitHub workflow artifacts, that you can download to avoid
building the image yourself. 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.
# Build the image
$ nix build .#baguette-zimage
$ ls result
baguette_rootfs.img.zstCopy 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.
To add baguette support to your NixOS existing configuration:
- Add this flake as an input.
- Add
inputs.nixos-crostini.nixosModules.baguetteto 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 }: {
# This allows you to rebuild while running inside Baguette.
# Change to your hostname.
nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
modules = [
# This is your configuration.
./configuration.nix
# This is where you add the `baguette` module
nixos-crostini.nixosModules.baguette
];
};
# Change <system> to "x86_64-linux", "aarch64-linux"
# This will allow you to build the image from another host.
packages."<system>".baguette-zimage = self.nixosConfigurations.hostname.config.system.build.btrfsImageCompressed;
};
}To build an image from another host, you can build .#baguette-zimage. If you
need to adjust the size of the resulting disk image, set
virtualisation.diskImageSize (in MiB). You will need enough space to fit your
NixOS configuration.
This repository can also build legacy LXC containers for Crostini to run in
the termina VM.
# Build the container image and its metadata:
$ nix build .#lxc-image-and-metadata
$ ls result
image.tar.xz metadata.tar.xzThat's it! See this blog post for a few ways on how to deploy the image on the Chromebook.
You can also integrate the nixosModules.crostini module in your Nix
configuration. If you are using flakes:
- Add this flake as an input.
- Add
inputs.nixos-crostini.nixosModules.crostinito 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 }: {
# This allows you to rebuild while running inside the LXC container.
# Change to your hostname.
nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
modules = [
# This is your configuration.
./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 from another host.
packages."<system>".lxc-image-and-metadata = nixos-crostini.packages."<system>".default;
};
}