Nix and NixOS

The purpose of this page is to document how to use NixOS to create an environment ready for iDempiere. The Nix, Nixpkgs, and NixOS manuals along with the wiki are excellent resources for explaining how Nix/NixOS works.

NixOS is a Linux distro built on top of NixPkgs. NixPkgs uses the Nix language to define how to build packages. Reference: john.codes

Videos to learn Nix:

Important docs:

Repositories:

Installing NixOS

I have not installed NixOS on bare metal yet. All NixOS experimentation has been with Incus and AWS.

Installing NIX (not NixOS)

Nix is both an application and an OS (NixOS). This section describes how to install the Nix application (language and NixPkgs) into an existing linux installation (PopOS in my case).

Installing Nix on a Mac:

Installing Package Using Nix

When using the nix package manager, you can install a package using nix profile. Here is an example:

nix profile install nixpkgs#typst

Important References for Common Concepts

Other Details Worth Referencing

First Working Example with nix-shell

Summary: used Nix to create a nix-shell that installs (only inside the shell) all the tools I typically use to create and manage a database. Since I am using Nix (the application) and not NixOS, I do not want to install postgresql (psql) as a service. Instead, I simply want it available when I am using this particular shell in this particular directory.

The result of the below steps is an almost completely self contained instance of psql. Here are some things to be aware of:

Steps:

shell.nix:

let
    nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-23.11";
    pkgs = import nixpkgs { config = {}; overlays = []; };
  in
 pkgs.mkShellNoCC {
    packages = with pkgs; [
      cowsay
      lolcat
      man
      neovim
      git
      tree
      tmux
      fd
      wget
      sysstat
      curl
      rsync
      zip
      unzip
      pkg-config
      gcc
      cmake
      jc
      jq
      jdk17_headless
      maven
      postgresql
      starship
    ];
 #note: the below variables are available in the shell without needing to export
  GREETING = "Hello, Nix!";
  EDITOR = "vim";
  VISUAL = "vim";
 shellHook = ''
      echo $GREETING | cowsay | lolcat
      source /home/cb/chuboe-system-configurator/.my_bash  # my personal bash adds
      alias vim='nvim'
      alias vi='nvim'
      alias sudo='/usr/bin/sudo' #needed since we do not want to re-install sudo and the -pure removes all previous references
  eval "$(starship init bash)"
 '';
 # https://mgdm.net/weblog/postgresql-in-a-nix-shell/
 }

First Working Example with NixOS

This section has evolved into this repo: Chuboe Nix Repo

The rest of this section is kept for reference just in case...

Notes about this example:

Here are the details:

environment.systemPackages = with pkgs; [
     #neovim #see below package for neovim - instead of here
     jdk17_headless
     maven
     postgresql
   ];

# Define a user account. Don't forget to set a password with ‘passwd’.
   users.users.cbn01 = {
     isNormalUser = true;
     description = "cbn01";
     extraGroups = [ "networkmanager" "wheel" ];
     packages = with pkgs; [
     #  firefox
     #  thunderbird
     ];
   };

environment.shellAliases = {
     "vim" = "nvim";
   };

environment.etc."inputrc" = {
   text = pkgs.lib.mkDefault( pkgs.lib.mkAfter ''
       "\e[A": history-search-backward            # arrow up
       "\e[B": history-search-forward             # arrow down
       '');
   };

programs.neovim = {
       enable = true;
     defaultEditor = true;
   };
services.postgresql = {
     settings = {
       listen_addresses = "*";
     };
     enable = true;
     enableTCPIP = true;
     authentication = pkgs.lib.mkOverride 10 ''
 local all       all     trust
 host all all      ::1/128      scram-sha-256
 host all postgres 127.0.0.1/32 scram-sha-256
     '';
   };

# Enable the OpenSSH daemon.
  services.openssh.enable = true;
# Open ports in the firewall.
  networking.firewall.allowedTCPPorts = [ 22 80 443 ];
# networking.firewall.allowedUDPPorts = [ … ];
# Or disable the firewall altogether.
# networking.firewall.enable = false;

Wireguard

Configuring wireguard (assuming you get a wireguard config file) is as easy as the following instructions. If you have multiple vpns, you simply un-comment the one you want to use and nixos-rebuild.

  1. Including the following in your config:
    1. networking.wg-quick.interfaces.wg-zito.configFile = "/home/cb/rsync_remote/vpn/customer/custvpn.conf";
  2. Reloading your environment:
    1. sudo nixos-rebuild switch