8000 GitHub - aldur/nixos-crostini: NixOS in ChromeOS · GitHub
[go: up one dir, main page]

Skip to content

About

NixOS in ChromeOS

Resources

Stars

16 stars

Watchers

3 watching

Forks

Repository files navigation

nixos-crostini: NixOS in ChromeOS

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.

See the module reference for configuration options. The documentation build reads the option declarations directly from the modules.

Quick start

  1. Install Nix.
  2. Enable flake support: export NIX_CONFIG="experimental-features = nix-command flakes".
  3. Run the steps below from a new directory. Replace YOUR-USERNAME with the username you will pick when configuring Linux on ChromeOS.
# The template of this repository. Or simply clone it.
nix flake init -t github:aldur/nixos-crostini
# Your username, in configuration.nix.
sed -i 's/\baldur\b/YOUR-USERNAME/' configuration.nix
nix flake check --no-build

Now build a VM image or container image.

Baguette images

ChromeOS >= 143 supports containerless Crostini (aka Baguette), providing more flexibility than legacy LXC containers.

Baguette: Quick start

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.zst

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.

For a read-only base and a separate state disk, see the ephemeral root guide.

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

Baguette: NixOS module

To add baguette support to your NixOS existing configuration:

  1. Add this flake as an input.
  2. Add inputs.nixos-crostini.nixosModules.baguette to your modules.
  3. Enable crostini.enable for your user:
users.users.aldur = {
  isNormalUser = true;
  crostini.enable = true;
};

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.

LXC containers

This repository can also build legacy LXC containers for Crostini to run in the termina VM.

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 nixosModules.crostini 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 }: {
    # 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;
  };
}

About

NixOS in ChromeOS

Resources

Stars

16 stars

Watchers

3 watching

Forks

Used by

Contributors

Languages

0