Nixpkgs: systemd installation of docker is incomplete.

Created on 4 Oct 2019  路  5Comments  路  Source: NixOS/nixpkgs

It is difficult to get docker working with systemd. When installing docker from nixpkgs (on Ubuntu) it installs docker.service but not docker.socket (a dependency of docker.service), and the ExecStart path in the .service file is wrong. Starting dockerd manually works as expected.

To Reproduce
On a mult-user nix system, I install docker, link the systemd files, and start the service

> sudo -i nix-env -i docker
> sudo su
root> systemctl link /root/.nix-profile/etc/systemd/system/*
root> [ctrl-d]
> sudo systemctl start docker
Failed to start docker.service: Unit docker.socket not found.

Expected behavior
Aside from a running dockerd after that last command, I would expect the directory structure, post nix-env -i to be:

 /root/.nix-profile/etc/systemd/system/
                                 | - docker.service
                                 | - docker.socket

Instead, I get:

 /root/.nix-profile/etc/systemd/system/
                                 | - docker.service

Additional context

I'm working on a fix and will submit a pull request if I am able. In the meanwhile, here is what I've discovered so far...

The relevant section of nixpkgs/docker is line 149

  install -Dm644 ./components/engine/contrib/init/systemd/docker.service $out/etc/systemd/system/docker.service

There are both files, .service and .socket, at the docker-ce source. So I imagine the fix is something along the lines of adding the following.

  install -Dm644 ./components/engine/contrib/init/systemd/docker.socket $out/etc/systemd/system/docker.socket

Manually copying the file to /etc/systemd/system/docker.socket uncovers another error, however. The ExecStart path of docker.service was never patched.

ExecStart=/usr/bin/dockerd -H fd://

To fix this I had to copy the docker.service file from the store and put it at /etc/systemd/system/docker.service--replacing the symlink. Then I pasted the appropriate store path to dockerd in the ExecStart entry and everything worked.

Additional Suggestion
I imagine there's good reason that the missing file isn't included. Pure speculation, but probably because the socket file is left up to the NixOS side of the house. It was really hard for me to get to this point of understanding what was going on here and how to get this working. I really love nix but issues like this make me hesitate recommending it as a cross platform solution.

To make nixpkgs a more powerful cross-platform solution (in this case), my first suggestion is to include an attribute in the docker derivation, withSystemd. It would build on the docker derivation by additionally handling the part where the systemd files are initialized. Similarly, others could include withSystemV-debian, etc. Is this an appropriate approach? I feel like I could implement something like this, but would want to know if it's appropriate first.

Next, my understanding is that nix doesn't really want to mess with peoples configurations. That's fine, but it should be made explicit at install time that the user is expected to complete the installation (by creating the appropriate links, systemctl enable, ... or whatever the case may be). Perhaps there's a way to echo a message from nix-env that doesn't get lost in all the build output noise?

Finally, it'd be great if we could leverage--for non-NixOS--the config and options from NixOS. There's scattered information out there, but I haven't had great success. But this is going a lot wider in scope than this bug report. Thanks for reading!

Metadata

>nix run nixpkgs.nix-info -c nix-info -m
[1 copied, 0.0 MiB DL]
 - system: `"x86_64-linux"`
 - host os: `Linux 4.15.0-65-generic, Ubuntu, 18.04.3 LTS (Bionic Beaver)`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.2.2`
 - channels(tcook): `""`
 - channels(root): `"nixpkgs-20.03pre194957.bef773ed53f"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
bug non-nixos

Most helpful comment

I unable migrate a coworker from apt to nix because of this today.

Perhaps if I can create an overlay that adds the suggested fix they'll still be interested.

All 5 comments

The following fixed my problem. These lines are inserted after line 149 in docker/default.nix

substituteInPlace $out/etc/systemd/system/docker.service \
      --replace "ExecStart=/usr/bin/dockerd" "ExecStart=$out/bin/dockerd"
install -Dm644 ./components/engine/contrib/init/systemd/docker.socket $out/etc/systemd/system/docker.socket

Is this something people usually submit a pull request for?

I don't see any harm shipping the socket unit file in the package directly.

Probably means we will have to change the docker NixOS module to not define this itself though. Instead you just set systemd.packages = [ pkgs.docker ]; in the docker module on NixOS and I think stuff should then work.

Could you send a PR for at least the package fix? And I can then give you pointers on how to do the module fix too.

I unable migrate a coworker from apt to nix because of this today.

Perhaps if I can create an overlay that adds the suggested fix they'll still be interested.

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

Hi. Just wanted to chime in and say this issue is still relevant as a non-nixos user.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

copumpkin picture copumpkin  路  3Comments

spacekitteh picture spacekitteh  路  3Comments

ghost picture ghost  路  3Comments

ayyess picture ayyess  路  3Comments

sid-kap picture sid-kap  路  3Comments