261 Commits
Author SHA1 Message Date
Jörg Thalheim 5dd3a57308 dockerTools: fix streamLayeredImage wrapper shebang when cross compiling
The streamLayeredImage wrapper invokes the image streamer at build time on
the build platform. It was built with makeWrapper, which bakes
targetPackages.runtimeShell into the shebang. Under cross compilation that
is the host shell, so the wrapper is not executable on the builder and
crashes (e.g. a Linux image built on a Darwin builder segfaults the
streamer).

This was fixed by switching to pkgsBuildBuild.makeWrapper (build == host == target)
so the shebang points at the build-platform shell.
2026-06-28 10:31:29 +02:00
Eman Resu f5c31ce008 build-support/docker: remove throwIf usage 2026-05-26 14:22:40 -04:00
Eman Resu 58bc1fec6f build-support/docker: remove assertMsg usage 2026-05-26 14:14:40 -04:00
Gaetan Lepage a3ef615c63 dockerTools.buildLayeredImage: propagate streamImage's passthru 2026-04-13 16:46:52 +00:00
rnhmjoj 577b32b084 treewide: remove nobody/nogroup from examples
The nobody/nogroup pair of should only ever be used by NFS to map remote
uid/guids that are missing locally. Every other use is an abuse and
generally a security concern.

Specifically, they're NOT some special user/group that can be used to
run programs without giving them any privileges. In fact, the opposite
is true: the more programs you run as nobody/nogroup the more valuable
files and resources become accessible to "nobody" and consequently
exposed to a potentially compromised program.

This removes mentions of nobody/nogroup from documentation and examples.
2026-04-13 10:23:25 +02:00
Joel Holdsworthandcommiterate ef8a5df530 dockerTools: Use lib.getExe and getExe' to get executable paths
Co-authored-by: commiterate <111539270+commiterate@users.noreply.github.com>
Signed-off-by: Joel Holdsworth <joel@airwebreathe.org.uk>
2026-01-07 14:50:14 -08:00
Robert HensingandGitHub 7648a2676b dockerTools: Replace bashInteractive with bash (#453912) 2026-01-06 11:59:22 +00:00
AleksanaandGitHub bb5f1dbead dockerTools: fix throw on invalid compressor (#455854) 2025-11-08 08:09:54 +00:00
Jade Lovelace b7665da7e1 dockerTools: support meta attribute
I want to be able to set descriptions on my docker image derivations
since these can be ingested by various tooling for helpfulness.
2025-10-30 15:53:00 -07:00
h7x4 90b1f66e98 dockerTools: fix throw on invalid compressor 2025-10-26 22:22:20 +09:00
Joel Holdsworthandcommiterate a003bc7c60 dockerTools: Replace bashInteractive with bash
bash has been interactive by default since this PR [1] was merged. This
commit simplifies dockerTools given that there is now no distinction
between bash and bashInteractive.

  * [1] https://github.com/NixOS/nixpkgs/pull/379368

Co-authored-by: commiterate <111539270+commiterate@users.noreply.github.com>
Signed-off-by: Joel Holdsworth <joel@airwebreathe.org.uk>
2025-10-21 09:53:38 -07:00
Joel Holdsworthandcommiterate 43759f5f96 dockerTools: Document streamNixShellImage homeDirectory argument
Co-authored-by: commiterate <111539270+commiterate@users.noreply.github.com>
2025-10-09 11:04:43 -07:00
Joel Holdsworthandcommiterate 3c3e8772c4 dockerTools: Tidied comments
Co-authored-by: commiterate <111539270+commiterate@users.noreply.github.com>
2025-10-09 11:04:41 -07:00
Joel Holdsworth ab13df9c41 dockerTools: Updated streamNixShellImage Nix GitHub links
dockerTools streamNixShellImage implements a facsimile of the
environment created by the Nix build process. In order to keep track of
the Nix features implemented, the streamNixShellImage code has comments
containing hyperlinks indicating the corresponding Nix C++ code in the
GitHub repository.

As Nix 2.32.0 has now been released [1], this patch updates the GitHub
links to correspond to the code in the new version.

[1] https://discourse.nixos.org/t/nix-2-32-0-released/70528
2025-10-09 09:49:50 -07:00
NAHO c8d4dabc43 pkgs: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --type file \
      . \
      pkgs \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2025-10-04 19:02:37 +02:00
Lars Jellema ff214e9d0e build-support/docker: Smarter default layering algorithm 2025-09-07 12:01:02 +02:00
Terje Larsen 6ccf14ba23 dockerTools.streamLayeredImage: fix enableFakechroot
This broke with #417132 where the previous behaviour of suppressing
errors of the export into $NIX_BUILD_TOP/env-vars when dumping env vars.

This error seems to stem from the non-existance of $NIX_BUILD_TOP. This
fix ensures the NIX_BUILD_TOP propagates into the proot environment.
2025-07-30 15:29:37 +02:00
Wolfgang Walther 5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Shogo Takata 00efca8c0c dockerTools: fix build failure when building in vm
Fixes build failure for nixos.tests.docker-tools.
The tar command below the changed line relied on the $out directory
being created but it is not being created after the commit below.
97ed6b4565
2025-05-20 18:46:48 +09:00
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](https://github.com/NixOS/nixpkgs/tree/8616af08d915377bd930395f3b700a0e93d08728/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Wolfgang Walther b88f515135 dockerTools.streamLayeredImage: fix with structuredAttrs
When building with structuredAttrs, two things would happen:
- sourcing stdenv would fail, because $stdenv is not set.
- the error is swallowed because bash is called without -e.

Thus, the build appears to be successful at first, but could fail later
when anything depends on a sourced stdenv.
2024-12-29 18:36:48 +01:00
github-actions[bot]andGitHub ceb62729d2 Merge master into staging-next 2024-12-09 18:05:05 +00:00
Jörg ThalheimandGitHub ff8576f191 dockerTools.pullImage: accept hash parameter (#342400) 2024-12-09 15:32:15 +01:00
nicooandJörg Thalheim d0e6b0e170 dockerTools.pullImage: accept hash parameter 2024-12-09 14:28:24 +01:00
K900 6739ae1174 Merge remote-tracking branch 'origin/staging-next' into staging 2024-12-02 22:43:34 +03:00
Jörg ThalheimandGitHub 1af9e10973 nixos/dockerTools: fixup proot/fakeroot code - exclude also dev (#308603) 2024-12-02 09:46:17 +01:00
Wolfgang Walther 217d3132cf various: remove unused substituteAll imports 2024-12-01 14:25:56 +01:00
Adrian Gierakowski 6cecfd8ad7 docker-tool: fix maxLayers assert 2024-11-11 18:45:13 +00:00
Adrian GierakowskiandSandro 5b4a8db4d9 build-support/docker: customisable layering strategy
Allow customisation of the algorithm used to convert nix references
graph (created from docker image contents) to docker layers.

A collection of building blocks (python functions) is provided, which
use can assembled into a processing pipeline by specifying a list of
operations (and their initial arguments) via a nix list.

Nix references graph if first converted into a python igraph.Graph
object (with each vertex representing a nix path), which is then fed
into the user defined pipeline. Each stage in the pipeline represents a
function call, with initial arguments specified by the user in nix, and
the last argument being the result of the previous stage in the pipeline
(or the initial Graph object). Each step of the pipeline is expected to
produce a data structure consisting of arbitrarily  nested lists/dicts
with Graph objects (representing docker layers) at it's leafs. The
result of the last stage in the pipeline is recursively flattened (with
each dict converted into list of values), until a flat list of Graphs
remains. This is then output as a json array of arrays (each Graph
converted into an array of paths).

This functionality is made available via new `layeringPipeline` argument
to the `streamLayeredImage`/`buildLayeredImage` functions. The default
value of the argument has been chosen to to preserve current layering
behaviour.

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
2024-11-09 16:21:48 +00:00
Tom Bereknyei d0b3364822 dockerTools: set mtime to epoch by default 2024-09-25 00:31:16 -04:00
WxNzEMofandTom Bereknyei 847b4732e4 dockerTools: Allow separately specifying metadata and filesystem timestamps
Setting the image creation timestamp in the image metadata to a
constant date can cause problems with self-hosted container
registries, that need to e.g. prune old images.  This timestamp is
also useful for debugging.

However, it is almost never useful to set the filesystem timestamp to
a constant value.  Doing so not only causes the image to possibly no
longer be reproducible, but also removes any possibility of
deduplicating layers with other images, causing unnecessary storage
space usage.

Therefore, this commit introduces "mtime", a new parameter to
streamLayeredImage, which allows specifying the filesystem timestamps
separately from "created".  For backwards compatibility, "mtime"
defaults to the value of "created".
2024-09-25 00:23:20 -04:00
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00
Matthieu CoudronandGitHub ca1657217d streamLayeredImage: add dynamic tagging of docker image (#329425)
* streamLayeredImage: self-document the script

'podman load' doesn't let me override the name/tag from the image.
This name and tag is dynamic and in a CI environment so I would like to
be able to adjust the tag dynamically.
Since the image is streamed by stream_layered_image.py, there is no need
to stick with the nix-hardcoded image name/tag: the python script can
accept another name

I've added argparse to expose the feature. It has the added benefit of
adding `--help` support to the script, which makes its usage
self-explanatory.

* blackified file
2024-07-29 19:45:58 +02:00
Robert Hensing 412601690e build-support/docker/default.nix: Refer to docs and tests
This removes redundant inline docs, because
- users should consult the better docs in the manual,
- contributors should add to the manual, not the inline comments
2024-07-28 23:19:58 +02:00
Robert Hensing 43df2b50f9 devShellTools.{unstructuredDerivationInputEnv,derivationOutputEnv}: extract 2024-07-28 23:17:18 +02:00
Robert HensingandGitHub c5e5aa7266 Merge pull request #308822 from yorickvP/yorickvp/streamLayeredImage-overridable
dockerTools.streamLayeredImage: add includeNixDB argument, expose conf and streamScript
2024-07-24 16:02:35 +02:00
e18d3b4894 Added an error message when using enableFakechroot on Darwin (#327336)
* Added an error message when using enableFakechroot on Darwin

Co-authored-by: Valentin Gagarin <valentin@gagarin.work>
2024-07-17 10:06:42 +02:00
Robert Hensing 8398e087cd devShellTools.{stringValue -> valueToString} 2024-06-29 17:22:57 +02:00
Robert Hensing 469039098b devShellTools.stringValue: init 2024-06-29 17:21:01 +02:00
Yorick van Pelt 62e9e0f963 dockerTools: add includeNixDB to buildImage and document 2024-05-06 14:57:08 +02:00
Yorick van Pelt c055845069 dockerTools.streamLayeredImage: add includeNixDB argument, expose conf and streamScript 2024-05-03 16:40:48 +02:00
Pavel Valodzka a180a54daa nixos/dockerTools: fixup proot/fakeroot code - exclude also dev
Finish work of commit 4911915512, avoid to arhive also /dev which can fail and never usefull in containers
2024-05-02 22:50:35 +03:00
Robert HensingandGitHub c740c98fc1 Merge pull request #292760 from PigeonF/dockertools-build-layered-compressor
dockerTools: Fix changing compression method for `buildLayeredImage`
2024-04-08 09:24:18 +02:00
Ryan LahfaandGitHub a199cd1dbd Merge pull request #297496 from abryko/docker-tag-discard-closure
dockerTools: discard closure reference in imageTag
2024-03-27 09:29:53 -07:00
Pol DellaieraandGitHub 6522a75f90 Merge pull request #298239 from cdepillabout/layered-img-passthru
dockerTools: add streamed image as passthru to buildLayeredImage
2024-03-23 22:13:18 +01:00
Dennis Gosnell 2e91dc65e4 dockerTools: add streamed image as passthru to buildLayeredImage
This is convenient for debugging the underlying streamed image used by
`dockerTools.buildLayeredImage`.

Here's an example of how you might use this:

```console
$ nix repl ./.
nix-repl> dockerTools.examples.nginx.passthru.stream
«derivation /nix/store/9zczmlp2kraszx4ssmh6fawnlnsa5a4n-stream-nginx-container.drv»
```
2024-03-23 10:33:22 +09:00
Xavier Maillard bc40f51d1a dockerTools: discard closure reference in imageTag 2024-03-20 17:54:09 +01:00
Yueh-Shun Li 67ec1a7d7b dockerTools.buildImage: writeReferencesToFile -> writeClosure 2024-03-19 05:30:54 +08:00
Silvan MosbergerandGitHub aabd5fbfcf Merge pull request #292259 from dawidd6/docker-nix-ssl
dockerTools: set NIX_SSL_CERT_FILE in image
2024-03-12 02:01:08 +01:00
Jonas Fierlings f4871a62d2 dockerTools: Do not pass compressor to streamLayeredImage 2024-03-02 10:18:56 +01:00