How to build configuration

I would like to build my home-manager configuration for CI purposes. It’s basically a ~/.config/nixpkgs/configuration.nix file with content something like this:

{ lib, pkgs, ... }:

{
  programs.home-manager.enable = true;
  programs.home-manager.path = https://github.com/rycee/home-manager/archive/master.tar.gz

  home.packages = with pkgs; [
    htop
  ];
}

so it’s a function that takes at least a lib and pkgs, but somewhere in the imports there might be configuration and others as well. How can I build this file with nix build?

Answering to myself. I read through the home-manager shell script and was able to scrape this out of it:

nix build -I home-manager=https://github.com/rycee/home-manager/archive/master.tar.gz -f "<home-manager/home-manager/home-manager.nix>" --argstr confPath "$PWD/home.nix" --argstr confAttr ""

which builds the derivation.

Taking this further, I can take any home-manager module and have something like this in the travis configuration:

env:
  - CHANNEL=18.09
  - CHANNEL=19.03
script:
  - nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-$CHANNEL.tar.gz -I home-manager=https://github.com/rycee/home-manager/archive/master.tar.gz -f "<home-manager/home-manager/home-manager.nix>" --argstr confPath "$PWD/modules/programs/asd/test.nix" --argstr confAttr ""

with a simple test.nix:

{ lib, pkgs, ... }:

{
  programs.home-manager.enable = true;
  imports = [
    ./default.nix
  ];
  programs.asd.enable = true;
}
3 Likes