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
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.dockerTools.buildImage {
name = "rust-mingw";
tag = "latest";
contents = enviroment.buildInputs ++ enviroment.nativeBuildInputs;
config = {
Env = builtins.attrValues
(builtins.mapAttrs
(name: value: "${name}=${value}")
(builtins.removeAttrs enviroment ["buildInputs" "nativeBuildInputs" ]));
};
}
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.
Any help is highly appreciated