FROM nixos/nix
RUN nix-shell --packages bash && bash
docker build ends in exception The command '/bin/sh -c nix-shell --packages bash && bash' returned a non-zero code: 127. The only way to run bash I could figured out is to use absolte path:
FROM nixos/nix
RUN nix-shell --packages bash && `nix-build --no-out-link '<nixpkgs>' -A bash.out`/bin/bash
I’ll be grateful if anyone could explain why nix-shell -p bash in Docker doesn’t add bash as usual to $PATH.
nix-shell -p bash will create an environment with bash in PATH, and then exit it, such that && bash can be executed.
To actually run a command within the environment, you need to use --run or --cmd depending on the required semantics. One allows for interactive input, the other doesn’t.
Thank you, @austin. I don’t think nix-env is appropriate in my case because the only demand for bash and some other tools is to build gearmand on NixOS docker image. Not sure the image I proposed is the best way to do that but it works.
@palik why are you building gearmand within a docker container? Is this a requirement of the gearman tooling/testing system?
This will leave you with a pretty fat docker image that contains all the build tools for gearman which will never be used again but (due to the way docker layers work) will be transferred along with gearmand everywhere this docker file is deployed
I second @NobbZ it would be better to create a derivation to build gearmand within Nix and create a docker image that contains only gearmand. If you contribute your derivation to nixpkgs, you can even have nixery.dev build and serve you an optimised docker image.