It has been long since I have published the last blog post. I promised to write about using ox-hugo but haven’t done it yet (sorry Kaushal Modi), and I also have a stack of some other procrastinated tasks in the FOSS world. There was a notable change in my life, even though I am doubtful if it is in a positive direction, but I now appear to have some spare time for following my interest.

During the Black Friday, I purchased a Chromebook. It runs Chrome OS, which now supports Android and Linux applications. As I use Emacs, I installed it onto the machine. Its setup workflow is slightly different from that of a typical Linux desktop, so I will document the procedure in this post.

Why Chrome OS

I have known Chromebooks for several years, but I have never used it before. They were known as cheap laptop computers which were nearly useless without internet connection. I simply never seriously considered getting one. I liked to use Linux even as a desktop operating system, and a lightweight DE/WM doesn’t require much power, so a cheap computer sufficed. I used to buy a used ThinkPad1 with Windows preinstalled and install Linux onto it. It worked well, but its whole setup process could not be easy, and I was often left with issues relating to Linux drivers, especially for Bluetooth2.

Meanwhile, I started using another consumer operating system: Android. It is based on Linux but runs on mobile devices, typically smart phones. Due to its convenience, I came to use such devices quite often.

It made things more complicated. Now I use two operating systems, two distinct sets of applications, and two or more physical devices. While some tasks are easier on a lightweight touch-screen device, other tasks are unarguably more efficient on a classic computer with a keyboard. It is not easy to integrate workflow across the two platforms, especially if two physical devices are involved in a single task, and it is hard to maintain multiple devices with different ecosystems.

Recently, Chrome OS has been actively being developed. It now supports Android applications and even has a beta support for Linux containers. The active development is not limited to software aspects. Pixelbook, a flagship series of Chromebooks made by Google, appeared last year, and other manufacturers also started selling “power horse” Chromebooks this fall. I gained an interest in Chrome OS devices when HP Chromebook x2 was announced. After doing research on products for months, I finally got a new machine with Chrome OS. It’s the lowest model of Pixelbook. As the operating system is integrated with the hardware, it has a flawless out-of-box experience. In the upcoming months, I want to learn to exploit the platform. I may or may not write blog posts on it, but I really expect the platform to change my (digital) life, and I hope this post will be useful to someone.

Activating support for Linux applications

The Linux support for Chrome OS is called Crostini. Chrome OS runs a virtual machine, and the VM runs LXD containers. This article shows the following picture to illustrate the ecosystem:

You can activate this feature in the settings of Chrome OS. Note that the support for Linux containers is not available for all Chromebooks3. It is only available in some models, but Google Pixelbook and all high-end Chromebooks (and Pixel Slate) released in this fall seem to support it.

Installing the latest version of Emacs

The default Linux distribution installed on Chrome OS is Debian. It is one of the most popular Linux distributions and considered reliable. However, as of writing this post, the Emacs package available from its stable repository is still 24.5. My Emacs configuration requires 26.1, the current latest released version, so I considered installing it in either of the following ways:

  • Install Emacs 26.1 using another package manager (or build it from source).
  • Add a Linux container of another distribution with the latest Emacs version and make the container the default, as done in this article.

Since this is my first experience with Chrome OS and Crostini, I chose the former option which seemed much easier.

Nix and NixOS

Before the Chromebook arrived, I was trying out NixOS, a Linux distribution with a purely functional package manager called Nix. I was a user of Arch Linux for a long time and then its derived distribution Manjaro for several months, but I felt unconfident with my fragile, unreproducible setup. The idea behind NixOS is that its entire deployment is configured declaratively and also allows rollback. With home-manager, Nix even supports declarative configuration of the user environment, which is classically tracked in the form of a “dotfiles” repository. This is an interesting ecosystem, both for development and for production (which means DevOps).

Nix can also be used as a distribution-agnostic package manager. That is, you can use Nix to build and install Linux packages on any distribution (or even on Windows). It allows both declarative and interactive usage. This is useful for first trying out a program and then making it part of your configuration.

To install the Nix package manager on your non-NixOS distribution, simply run the following command:

curl | sh

The Nix environment is activated by loading a configuration file created by the installer:

. ~/.nix-profile/etc/profile.d/

Actually, the line is added to your ~/.profile by the installer, so you don’t have to type the command every time your open a terminal.

Note that you have to be using a POSIX-compliant shell (typically bash or zsh) to activate the Nix environment. Fish and xonsh are not supposed to work with it. For this reason, I have stopped using fish and plan to use zsh again.

Using Nix to install Emacs

Nixpkgs, the official package collection/repository of the Nix package manager, already contains Emacs 26.1. You can install the latest version of Emacs using Nix interactively:

nix-env -i emacs

You may want to install extra tools as well:

nix-env -i git

You need to install your own Emacs configuration, e.g.:

git clone ~/.emacs.d

Now you can start Emacs by typing emacs on a Linux terminal window on Chrome OS.

Creating a desktop file

It is bothersome to open a terminal and type emacs every time you start Emacs. You usually don’t have to start Emacs many times, but you don’t want to open the terminal window.

Chrome OS well integrates with Linux apps. If you install an application on Crostini using the standard package manager of Debian, it is available in “Linux apps” groups in the application launcher of Chrome OS. Applications installed by Nix, however, are not available in the launcher out of the box.

Fortunately, you can add a custom icon to the launcher by creating a desktop file. I just copied a desktop file of Emacs 24.5 in /usr/share/applications installed by apt to ~/.local/share/applications and adapted it as follows:

[Desktop Entry]
Name=GNU Emacs 26.1 (GUI)
GenericName=Text Editor
Comment=GNU Emacs is an extensible, customizable text editor - and more
Exec=/home/akirakomamura/.nix-profile/bin/emacs-26.1 %F

After I ran Chrome OS for a while, the icon became available in the launcher group. I don’t exactly understand what Chrome OS does, but it seems to be somehow detecting desktop files in the home directory.

You can also pin the icon on shelf (which would be called a panel on Linux). This will be convenient for starting Emacs instantly (if not yet) and also for setting a fixed position of the Emacs icon.

In fact, this screenshot is wrong, since the default font is not installed yet. I will write about that in an upcoming post.

Wrapping up

I have been using Emacs on the Chromebook for several days. When the operating system is in desktop mode, it works just as in Linux. It is rendered like other graphical applications, and the text size is sane, even if the monitor has a high pixel density, e.g. 2400x1600 on the machine. Despite the fact that the container is running on a VM, its performance is excellent on Pixelbook, at least for Org mode.

Of course, the platform should not be limited to using Org mode. I got the device to gain more opportunities for reading books, writing code, and other learning activities. In upcoming posts, I will write about declarative configuration of Linux applications through Nix in such a way that can be integrated with Chrome OS. I used Nix simply as a distribution-agnostic package manager this time, but its virtue is that it can be used to specify an entire system declaratively. By combining Chrome OS, which is now evolving into a maintenance-free container platform for consumer devices, and Nix, a declarative deployment tool for Linux, computers will have less states, while enhancing their capabilities. Emacs is the primary front-end to the Linux part, and it is “ready”, as shown in this post.

  1. My previous laptop computer was made by a less-known Chinese brand named Hasee. Is their service unavailable now? [return]
  2. Actually, Bluetooth support is still unstable on Chrome OS, and I am unsatisfied with the status. [return]
  3. Some Chrome OS devices are not going to get Crostini support. [return]