saolof
March 10, 2023, 2:15pm
1
Hi! in a dockerfile, adding files to the container from the local directory is straightforward. How do I do this with nix? Also, how would I include a local shell file as the entrypoint of the build docker image?
https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-dockerTools
To include files, assign them to the copyToRoot attribute.
For some good examples see also:
# Examples of using the docker tools to build packages.
#
# This file defines several docker images. In order to use an image,
# build its derivation with `nix-build`, and then load the result with
# `docker load`. For example:
#
# $ nix-build '<nixpkgs>' -A dockerTools.examples.redis
# $ docker load < result
{ pkgs, buildImage, buildLayeredImage, fakeNss, pullImage, shadowSetup, buildImageWithNixDb, pkgsCross, streamNixShellImage }:
let
nixosLib = import ../../../nixos/lib {
# Experimental features need testing too, but there's no point in warning
# about it, so we enable the feature flag.
featureFlags.minimalModules = {};
};
evalMinimalConfig = module: nixosLib.evalModules { modules = [ module ]; };
in
This file has been truncated. show original
saolof
March 15, 2023, 8:16am
3
The issue ended up being that the documentation for the nix language has a big gap between teaching basic syntax and teaching actual use of the standard library. Utility functions like builtins.readFile are very difficult to find
For OP or anyone else, you can use copyToRoot and a derivation to copy files to a docker image.
Hi All,
I’ve only been using Nix for a short amount of time, so far enjoying the ride. However today I’m stuck and no amount of googling/reading gives me the answer I’m looking for.
I’m trying to create a config file and copy it to the Docker image. I’m tried a few things and none seem to work. When I log in to the container the supervisord.conf file doesn’t exist. I’m sure I’m doing something silly but any pointers would be helpful.
{ pkgs ? import <nixpkgs> {}, pkgsLinux ? import <nixpkgs> …