I have a nix shell which I use for cross compiling software to another system. After being able to compile locally I try to create a docker container from my nix shell to allow the ci (in my company we use https://concourse-ci.org/) to compile it every time I change the code.
However it seems as if it doesn’t create the same environment as in my shell (In the shell I can compile and it the container it complaints about missing binaries which I’m trying to add than if I can find out where they are)
My setup is
nix/env.nix whith shared content
{ pkgs, rust, target ? null }:
let
baseDeps = with pkgs; [
libusb1
];
winDeps = with pkgs.pkgsCross.mingwW64; [
windows.mcfgthreads
windows.pthreads
buildPackages.gcc
buildPackages.binutils
];
in
{
nativeBuildInputs = [
rust
pkgs.pkg-config
pkgs.cmake
# these I added because the container
# complains of not having them while nix-shell does not
pkgs.coreutils-full
pkgs.bashInteractive
pkgs.gnugrep
pkgs.stdenv
pkgs.gnutar
pkgs.gzip
pkgs.curl
pkgs.wget
pkgs.cacert.out
pkgs.findutils
pkgs.buildPackages.gcc
pkgs.binutils
];
buildInputs = if
builtins.isNull target
then
baseDeps ++ [ pkgs.libudev0-shim ]
else
baseDeps ++ winDeps;
# Here we can put Environment Variables
CXXFLAGS="-I${pkgs.libusb1.dev}/include/libusb-1.0/";
MCFGTHREAD_DLL = if
builtins.isNull target
then
null
else
"${pkgs.pkgsCross.mingwW64.windows.mcfgthreads}/bin/";
}
shell.nix to create the shell for cross compiling
let
sources = import ./nix/sources.nix;
target = "x86_64-pc-windows-gnu";
rust = import ./nix/rust.nix { inherit sources; target = target; };
pkgs = import sources.nixpkgs {};
in
let
enviroment = import ./nix/env.nix { pkgs=pkgs; rust=rust; target=target; };
in
pkgs.pkgsCross.mingwW64.mkShell enviroment
docker-win.nix to create the same environment in a docker container
there are some other files in the nix folder to setup rust and pinning (with niv).
Does anybody know how to adjust my docker-win.nix file to create the same environment as in nix-shell? I would love to be able to put something like pkgs.pkgsCross.mingwW64.mkShell in my container but have not found a way.
I haven’t made much progress with this so far (partly because I did not have much time). The best I’ve found to address this issue is this https://github.com/teamniteo/nix-docker-base. I think you can use a nix expression there and export it in a docker container.
There are probably simpler answers since I haven’t tried to do this exact thing, but if nothing else you may be able to pull on how existing projects accomplish it:
mach-nix, which has functions for both generating shells and docker containers: