Cascade Of Insights

Personal Site of Adam Gordon Bell - Software Engineer

Using Custom Packages in NixOs Configuration File

Here is a problem we encountered with NixOS:

The nix-channel we were on didn’t have the latest version of something we needed. This happened recently when my coworker upgraded to Postgres 9.5 from 9.4 but the PostGIS version in nixpkgs hadn’t been updated to a 9.5 compatible version.

Upgrading Nix Package PostGIS:

same steps apply for any package

Including package in configuration.nix:

If this package were a stand-alone program, we could have installed it from our forked pkgs. However, this package is referenced in a service that is configured globally in NixOS so we needed to be able to reference our forked package repo in our configuration.nix file.

If we were on the unstable channel the package would have eventually shown up, when our pull request was merged in and when the channel is updated from Github. However, we couldn’t wait for that.

Referencing our fork of nixpkgs in our configuration.nix :

We created a reference to our forked packages using a let expression in our configuration.nix file. This allowed us to globally reference packages both from the channel we are subscribed and from our custompkgs fork.

Using a let expression, we pulled in our fork of nixpkgs:

{ config, pkgs, ... }:

let custompkgs = import /usr/local/nixpkgs/default.nix {}; in
{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];
    ....
...
  services.postgresql = {
        enable = true;
        extraPlugins = [ (custompkgs.postgis.override { postgresql = pkgs.postgresql95; }).v_2_2_1 ];
    };
...