Home > Mobile >  Using nix to build a container with a git checkout
Using nix to build a container with a git checkout

Time:09-14

I want to build a nix container that includes both nix packages and just the source from a github repository. I've been looking through a lot of documentation, but am pretty confused about the right syntax to use, or actual API docs for what some of these functions do. I've ended up with the following:

let
  pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/15493135c0af2e5562500ab5225f2bd75b38af09.tar.gz");

  certbot_dns_namecom = fetchGit {
    url = "https://github.com/laonan/certbot-dns-name-com.git";
    ref = "master";
    rev = "cdb98b67e873ee26c9b70593dae23aa19c0df60b";
  };
in rec {

  docker = pkgs.dockerTools.buildImage {
    name = "certbot-namedns";
    contents = [ pkgs.certbot certbot_dns_namecom ];
    config = {
      Cmd = [ "/bin/sh" ];
    };
  };
}

Which gives me the error error: value is a function while a set was expected on the line where docker = pkgs.dockerTools.buildImage.

I'm not even trying to build what's in the git repo, although the repo does contain debian package build information. Is it possible with Nix to checkout the git repo at a certain revision, build the debian package using the repo's pkg-src, and then have that available within the nix container? How would that be written?

CodePudding user response:

just slightly modified version works for me:

{ pkgs ? import <nixpkgs> { }
, pkgsLinux ? import <nixpkgs> { system = "x86_64-linux"; }
}:
let 
certbot_dns_namecom = fetchGit {
    url = "https://github.com/laonan/certbot-dns-name-com.git";
    ref = "master";
    rev = "cdb98b67e873ee26c9b70593dae23aa19c0df60b";
  };
in pkgs.dockerTools.buildImage {
  name = "hello-docker";
  contents = [ pkgs.busybox pkgs.bash pkgs.certbot certbot_dns_namecom ];
  config = {
      Cmd = ["${pkgsLinux.bash}/bin/bash"];
  };
}

The source code has ended up in the /. No debian packaging required. Docs I've used

  • Related