My (expanding) list of usage notes for Nix and NixOS

nixos draft

Warning: This post is a draft and is to be considered unfinished. The content might be of poor quality, might not have been tested, or can even be misleading!
Revision history

String interpolation

Use variable as map/object key

  customUser = "stigok";
in {
  users.extraUsers = {
    ${customUser} = {
      systemUser = true;
      description = "This is a user called ${customUser}";

Check a file for syntax errors

$ nix-instantiate --parse <file>
$ nix-instantiate --parse myfile.nix

Pass function arguments with nix-instantiate

$ nix-instantiate --arg config <val1> --arg nixpkgs <val2> myfile.nix
$ nix-instantiate --arg config '{}' --arg pkgs '<nixpkgs>' --eval postgresql.nix

Reference: slack1256 #nixos @ Freenode

Install a package for current user

$ nix-env -iA nixos.thunderbird

This will make the package available for the current logged in user only, except when logged in as root, which will make it available for everyone.



If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom)