371 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
Raphael Borun Das Gupta cc6290d072 dockerTools.buildLayeredImage: fix configureFlags syntax in nixosTests
The string added to `configureFlags` for building `hello`
for nixosTests example
«layered image with files owned by a user other than root»
had a leading space, leading to error

	configure flags: --disable-dependency-tracking --prefix=/nix/store/kwdkh22lfr3irggg076jpydbk1556iax-hello-2.12.3 \ --program-prefix=layeredImageWithFakeRootCommands-
	configure: error: invalid variable name: ' --program-prefix'

when running `./configure` for that custom `hello`, making
`nixosTests.allDrivers.docker-tools` fail.
2026-05-16 16:10:41 +02:00
Gaetan Lepage a3ef615c63 dockerTools.buildLayeredImage: propagate streamImage's passthru 2026-04-13 16:46:52 +00:00
Philip Taron d22bc0f6f5 treewide: remove nobody/nogroup [part 1] (#509391) 2026-04-13 14:51:20 +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
Jonathan GAYVALLET 23f0f8cacf dockerTools: fix failing etc test case 2026-04-12 18:53:25 +02:00
Jo 8fb7372c5a treewide: move env variable(s) into env for structuredAttrs (F-G) (#490354) 2026-02-19 12:39:03 +00:00
Jo 8154ebbe01 flatten-references-graph: rename from flattenReferencesGraph (#488299) 2026-02-18 10:57:35 +00:00
Stefan Frijters 8730ce7b0e tarsum: move env variable(s) into env for structuredAttrs 2026-02-14 12:25:19 +01:00
Tom Herbers e9cfcb3b5d maintainers: drop offline 2026-02-11 11:42:06 +01:00
quantenzitrone 3b7c31d1e4 flatten-references-graph: rename from flattenReferencesGraph
to fit package naming conventions
2026-02-10 17:00:20 +01:00
Joel Holdsworth 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 Hensing 7648a2676b dockerTools: Replace bashInteractive with bash (#453912) 2026-01-06 11:59:22 +00:00
Ihar Hrachyshka 567e8dfd8e treewide: clean up 'meta = with' pattern
This commit was created by a combination of scripts and tools:
- an ast-grep script to prefix things in meta with `lib.`,
- a modified nixf-diagnose / nixf combination to remove unused `with
lib;`, and
- regular nixfmt.

Co-authored-by: Wolfgang Walther <walther@technowledgy.de>
2025-12-10 18:09:49 +01:00
Sandro Jäckel 6ff3098d3b tarsum: fix module path to tarsum 2025-12-08 16:39:20 +01:00
Aleksana 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 Holdsworth 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 Holdsworth 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 Holdsworth 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
Maximilian Bosch 7d443d378b nixos/oci-containers: support rootless containers & healthchecks
Closes #259770
Closes #207050

The motivation for the former is to not execute the container as root,
so you don't have to `sudo -i` to perform podman management tasks.

The idea behind healthchecks is to be able to keep the unit in the
activating state until the container is healthy, only then then unit is
marked as active.

The following changes were necessary:

* Move the ctr-id into `/run/${containerName}` to make podman can
  actually write to it since it's now in its RuntimeDirectory.

* Make `sdnotify` option configurable (`healthy` for healthchecks that
  must pass, default remains `conmon`).

* Set Delegate=yes for `sdnotify=healthy` to make sure a rootless
  container can actually talk to sd_notify[1].

* Add a warning that lingering must be enabled to have a `systemd --user`
  instance running which is required for the cgroup support to work
  properly.

* Added a testcase for rootless containers with both conmon and
  healthchecks.

[1] https://github.com/containers/podman/discussions/20573#discussioncomment-7612481
2025-02-27 11:08:33 +01: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] 96dd0fdefd Merge master into staging-next 2024-12-13 18:04:38 +00:00
Jörg Thalheim 3dc8ff155b build-support: fix nix-prefetch-* on macOS (#358685) 2024-12-13 14:23:56 +01:00
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
Silvan Mosberger 84d4f874c2 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev 78e9caf153
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:23:58 +01:00
github-actions[bot] ceb62729d2 Merge master into staging-next 2024-12-09 18:05:05 +00:00
Jörg Thalheim ff8576f191 dockerTools.pullImage: accept hash parameter (#342400) 2024-12-09 15:32:15 +01:00
nicoo 5720f42c32 nix-prefetch-docker: provide hash in SRI format 2024-12-09 14:28:25 +01:00
nicoo 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 Thalheim 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 266283bec3 build-support/docker: use runCommand in make-layers.nix 2024-11-29 21:59:36 +00:00
Jonathan del Strother 6cb8c5ec01 build-support: Simplify tmpdir creation with coreutils
macOS 10.12 doesn't have a usable --tmpdir flag on the builtin mktemp, but we can
make use of coreutil's mktemp instead.
2024-11-25 09:41:02 +00:00
Jonathan del Strother 0c3d16a7d5 build-support: fix nix-prefetch-* on macOS
Since nix 2.20, `nix-store --add-fixed` doesn't accept paths where the
parent directory is a symlink. On macOS, /tmp is a symlink to
/private/tmp, which causes a "'/tmp' is a symlink" error:

```
$ nix run github:nixos/nixpkgs/24.11-beta#nix-prefetch-git -- --url https://github.com/IFTTT/polo.git --rev 316aa2ac210a45a7fc400ab921831493d5dd21b8 --hash sha256
Initialized empty Git repository in /private/tmp/git-checkout-tmp-1Bf9bIv7/polo-316aa2a/.git/
remote: Enumerating objects: 51, done.
remote: Counting objects: 100% (51/51), done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 51 (delta 8), reused 19 (delta 5), pack-reused 0 (from 0)
Unpacking objects: 100% (51/51), 19.57 KiB | 541.00 KiB/s, done.
From https://github.com/IFTTT/polo
 * branch            HEAD       -> FETCH_HEAD
Switched to a new branch 'fetchgit'
removing `.git'...
error: path '/tmp' is a symlink
```

Avoid this by resolving /tmp to a real directory in all the prefetch scripts
2024-11-25 09:32:14 +00:00
Adrian Gierakowski 6cecfd8ad7 docker-tool: fix maxLayers assert 2024-11-11 18:45:13 +00:00
Adrian Gierakowski 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
WxNzEMof 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