Installing Nix on Crostini: Difference between revisions

From NixOS Wiki
imported>Benley
m Benley moved page Installing on Crostini to Installing Nix on Crostini: This isn't instructions for installing nixos, just nix itself. New title should be less confusing.
imported>Thiagokokada
General improvements
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:


Once you have Nix installed, there are a few things that need to be done.
Once you have Nix installed, there are a few things that need to be done.


== Home-Manager ==
== Home-Manager ==
Line 16: Line 15:
First we extend the service with new environment variables
First we extend the service with new environment variables


<code>
<syntaxhighlight lang="console">
mkdir -p ~/.config/systemd/user/cros-garcon.service.d/
$ mkdir -p ~/.config/systemd/user/cros-garcon.service.d/
</code>
</syntaxhighlight>


followed by.
followed by.


<pre>
<syntaxhighlight lang="console">
cat > ~/.config/systemd/user/cros-garcon.service.d/override.conf <<EOF
$ cat > ~/.config/systemd/user/cros-garcon.service.d/override.conf <<EOF
[Service]
[Service]
Environment="PATH=%h/.nix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/local/games:/usr/sbin:/usr/bin:/usr/games:/sbin:/bin"
Environment="PATH=%h/.nix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/local/games:/usr/sbin:/usr/bin:/usr/games:/sbin:/bin"
Environment="XDG_DATA_DIRS=%h/.nix-profile/share:%h/.local/share:/usr/local/share:/usr/share"
Environment="XDG_DATA_DIRS=%h/.nix-profile/share:%h/.local/share:%h/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share"
EOF
</syntaxhighlight>
</pre>
 
You can also set this inside your Home-Manager configuration:
 
<syntaxhighlight lang="nix">
{ ... }:
{
    xdg.configFile."systemd/user/cros-garcon.service.d/override.conf".text = ''
      [Service]
      Environment="PATH=%h/.nix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/local/games:/usr/sbin:/usr/bin:/usr/games:/sbin:/bin"
      Environment="XDG_DATA_DIRS=%h/.nix-profile/share:%h/.local/share:%h/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share"
    '';
}
</syntaxhighlight>


Then we need to restart our container. I found restarting the whole laptop to be the easiest and most effective method.
Then we need to restart our container. I found restarting the whole laptop to be the easiest and most effective method.
Line 34: Line 45:
After this, we can simply start adding GUI packages to our home-manager configuration. Alternatively, if we are not using home-manager, then we can directly install packages:
After this, we can simply start adding GUI packages to our home-manager configuration. Alternatively, if we are not using home-manager, then we can directly install packages:


<code>
<syntaxhighlight lang="console">
nix-env -i slack
$ nix-env -i slack
</code>
</syntaxhighlight>


Note: These instructions were adapted from the following post [https://www.reddit.com/r/Crostini/comments/9lazhn/environment_variables_for_launcher_applications/e769u4y/ on Reddit]
Note: These instructions were adapted from the following post [https://www.reddit.com/r/Crostini/comments/9lazhn/environment_variables_for_launcher_applications/e769u4y/ on Reddit]
== Graphical applications ==
Thanks to the usage of VirtGL as the GPU driver, you can easily run applications that depend on OpenGL/Vulkan by using [https://github.com/nix-community/nixGL NixGL]:
<syntaxhighlight lang="console">
$ nix run --impure github:guibou/nixGL -- program
</syntaxhighlight>
If you are setting up it in your Flakes/Home-Manager configuration, you can use:
<syntaxhighlight lang="nix">
{
  outputs = { nixgl, nixpkgs, home-manager, ... }:
  let
    pkgs = import nixpkgs {
      system = "x86_64-linux"; # or "aarch64-linux"
      overlays = [ nixgl.overlay ];
    };
  in
  {
    homeConfigurations.penguin = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
      modules = [
        ({ pkgs, ...}: {
          home.packages = with pkgs; [ nixgl.nixGLMesa ];
        })
      ];
    };
  }
}
</syntaxhighlight>
Using <code>nixgl.nixGLMesa</code> instead of <code>nixgl.auto.nixGLDefault</code> allow usage of pure evaluation.
Afterwards, you can call programs with:
<syntaxhighlight lang="console">
$ nixGLMesa program
</syntaxhighlight>

Latest revision as of 14:12, 4 January 2024

This Wiki page describes the process required to get up and running on Chrome OS within Crostini. This does not talk about Crouton and assumes you have already installed Nix. Guide to Installation.

Once you have Nix installed, there are a few things that need to be done.

Home-Manager

Using Home-manager is pretty straight-forward, and is an easy way to manage Nix and install packages. The documentation on the Github repo is sufficient.

Registering Applications with Chrome OS

This feature of Crostini expects .desktop files to be dropped in the appropriate places. (namely somewhere under $XDG_DATA).

Applications are registered with Chrome OS using a service running within the container called cros-garcon. As it is a simple systemd service, we can easily extend it to look in nix-specific locations.

First we extend the service with new environment variables

$ mkdir -p ~/.config/systemd/user/cros-garcon.service.d/

followed by.

$ cat > ~/.config/systemd/user/cros-garcon.service.d/override.conf <<EOF
[Service]
Environment="PATH=%h/.nix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/local/games:/usr/sbin:/usr/bin:/usr/games:/sbin:/bin"
Environment="XDG_DATA_DIRS=%h/.nix-profile/share:%h/.local/share:%h/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share"

You can also set this inside your Home-Manager configuration:

{ ... }:
{
    xdg.configFile."systemd/user/cros-garcon.service.d/override.conf".text = ''
      [Service]
      Environment="PATH=%h/.nix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/local/games:/usr/sbin:/usr/bin:/usr/games:/sbin:/bin"
      Environment="XDG_DATA_DIRS=%h/.nix-profile/share:%h/.local/share:%h/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share"
    '';
}

Then we need to restart our container. I found restarting the whole laptop to be the easiest and most effective method.

After this, we can simply start adding GUI packages to our home-manager configuration. Alternatively, if we are not using home-manager, then we can directly install packages:

$ nix-env -i slack

Note: These instructions were adapted from the following post on Reddit

Graphical applications

Thanks to the usage of VirtGL as the GPU driver, you can easily run applications that depend on OpenGL/Vulkan by using NixGL:

$ nix run --impure github:guibou/nixGL -- program

If you are setting up it in your Flakes/Home-Manager configuration, you can use:

{
  outputs = { nixgl, nixpkgs, home-manager, ... }:
  let
    pkgs = import nixpkgs {
      system = "x86_64-linux"; # or "aarch64-linux"
      overlays = [ nixgl.overlay ];
    };
  in
  {
    homeConfigurations.penguin = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
      modules = [
        ({ pkgs, ...}: {
          home.packages = with pkgs; [ nixgl.nixGLMesa ];
        })
      ];
    };
  }
}

Using nixgl.nixGLMesa instead of nixgl.auto.nixGLDefault allow usage of pure evaluation.

Afterwards, you can call programs with:

$ nixGLMesa program