Hi, I’m Matt and I’m one of those masochists who uses a chromebook as their personal development machine (not work though, I’m not that crazy). A cool thing about Chrome OS’s Linux support is that you can swap the default, boring Debian container for any LXC image. Here’s an archwiki page on how to swap it to Arch!

A not-so-cool thing about that LXC setup is that there isn’t a NixOS LXC image available 😢. Instead, I set up an Arch Linux container with Nix and Home Manager. Best of both worlds I guess? Here’s how to do it.

What we’re setting up

In these instructions, I’ll be setting up nix and home-manager. This setup doesn’t let you configure system-level things in nix like in NixOS, but you can configure things for your user using home-manager. If you set up nix-direnv in your home-manager config, you can add nix configurations for specific directories.

This should work for any Arch Linux install, not just my weird LXC image.

Let’s go!

  1. Install nix

    sudo pacman -S nix
    
  2. Enable and start nix-daemon

    sudo systemctl enable nix-daemon
    sudo systemctl start nix-daemon
    
  3. Add your user to the nix-users group

    sudo gpasswd -a <user> nix-users
    
  4. Log out and back in again for the group change to take effect

  5. Add nixpkgs and home-manager channels

    nix-channel --add https://nixos.org/channels/nixpkgs-unstable
    nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
    nix-channel --update
    
  6. Install home-manager

    export NIX_PATH=$HOME/.nix-defexpr/channels:/nix/var/nix/profiles/per-user/root/channels${NIX_PATH:+:$NIX_PATH}
    nix-shell '<home-manager>' -A install
    
  7. Take a look at ~/.config/nixpkgs/home.nix, make any desired changes, then run

    home-manager switch
    

And that should be it! Enjoy!

A nix shell running ‘cat /etc/os-release | cowsay’

For more info…

These instructions are basically a condensed version of these two pages: