nlewo / nix2container

An archive-less dockerTools.buildImage implementation
Apache License 2.0
501 stars 45 forks source link

How to use an existing `devShell` with `nix2docker`? #136

Open arichtman opened 3 months ago

arichtman commented 3 months ago

Hi - thanks so much for the work on nix2docker.

I was wondering if there was a good way to use an existing derivation, namely one made by mkShell. I'm able to pass the derivation to copyToRoot, but it doesn't seem to symlink anything to /bin, nor put it on $PATH. I can do it clunkily by interpolating the Nix store location, but this seems like a hack?

{
  description = "A third-party-build container image";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/6132b0f6e344ce2fe34fc051b72fb46e34f668e0";
    nix2container = {
      url = "github:nlewo/nix2container/20aad300c925639d5d6cbe30013c8357ce9f2a2e";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs = {nixpkgs, nix2container, self, ... }:
let
  pkgs = import nixpkgs {
    system = "x86_64-linux";
  };
in
rec {
  packages = {
    n2c-image = nix2container.packages.${pkgs.system}.nix2container.buildImage {
      name = "nix-image";
      tag = "n2c";
      copyToRoot = devShell;
      config = {
        Cmd = ["${pkgs.hello}/bin/hello"];
      };
    };
  };
    devShell = pkgs.mkShell {
      buildInputs = [ pkgs.hello ];
  };
};
}