kotatsuyaki’s site

NixOS Quirks and Solutions

Published on

This page accumulates all the problems I encountered during the migration from Gentoo to NixOS, along with the solutions I found.

Install packages from both stable and unstable channels

Unlike other distros, its 100% safe to mix packages from different channels in one system.

$ sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
$ sudo nix-channel --update nixos-unstable

Now in the configuration file, import <nixos-unstable> and use it as one would do for the default channel:

{ config, pkgs, ... }:

let
  unstable = import <nixos-unstable> { };
in
{
  environment.systemPackages = with pkgs; [
    unstable.neovim
  ];
}

Overriding the DNS server

The first option I found was networking.nameservers, but adding

{
  networking.nameservers = [ "8.8.8.8" "8.8.4.4" ];
}

to the config didn’t work for me, because it generates resolv.conf with the Google nameservers appended after the local DNS server, which is not what I wanted:

# Generated by resolvconf
nameserver 192.168.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4
options edns0

It turned out that since NixOS defaults to using NetworkManager under the hood, networking.networkmanager.insertNameservers is the correct option, since it says “a list of name servers that should be inserted before the ones configured in NetworkManager or received by DHCP”. Apply it like this.

{
  networking.networkmanager.insertNameservers = [ "8.8.8.8" "8.8.4.4" ];
}

Running AppImage

Some applications are packaged in the AppImage format, which claims to be Linux apps that run anywhere. However due to the weird (in a good sense) way Nix works, linkers and dynamic libraries that are normally assumed to be present at certain paths are missing, causing troubles when one tries to execute an AppImage file.

I’ve found two solutions to this so far:

  1. Use appimage-run. Install it (locally or globally) and , for example, do

    $ appimage-run Netron-5.0.1.AppImage
  2. Create a derivation using appimageTools. Beware that this is still an unstable API.

Accessing executable installed from shell.nix via Emacs TRAMP

This must be the least supported configuration in the world.

These three combined together created a hassle, since if I install python-language-server from my project’s shell.nix, my Emacs can’t see the pyls executable via TRAMP. No matter how I poked around the tramp-remote-path variable, (executable-find "pyls" "/ssh:hostname:") always returns nil.

The only dirty solution I found is to symlink the LSP server executable to the project’s root directory:

$ ln -s $(which pyls) pyls

Searching options from commandline

$ man configuration.nix

If network connection is available, then just go to https://search.nixos.org/options for them.