nixos/docker-rootless: add option to autoprune on schedule #445757
Looks like I did quite something wrong, at least not everything went red. Lets see.
please, check out the docs on title conventions (they're the same for both commits and PRs). specifically for modules (and you're editing a NixOS module) the format is nixos/MODULE: CHANGES
you got the commit right, rename the PR
if you look closely, you'll see that there's no with lib; in this scope. prepend lib. to every mkOption and types that you've added
startAt = lib.optional cfg.autoPrune.enable cfg.autoPrune.dates;
systemd.user.timers.docker-prune = lib.mkIf cfg.autoPrune.enable {
forgot a couple more
@acid-bong Thank you a lot for your help! I am pretty overwhelmed by how this is supposed to work, I tried reading through all guides, but surely missed some points. Also I am not quite sure how to run such a build locally, so I am relying on the CI Jobs, but since I am not yet well trained on reading the logs, it took me a while. Therefore your hints and help is really appreciated!
Regarding the lib, I am wondering if it wouldn't be better to align the normal docker and docker rootless module? But this might be another pull request for someone with more experience than I have.
I am wondering if it wouldn't be better to align the normal docker and docker rootless module? But this might be another pull request for someone with more experience than I have.
yeah, it's also unrelated to this PR's scope
add utils to the top args
I am relying on the CI Jobs
these errors are still detectable with a language server (nil, nixd) or a linter
@acid-bong Again thank you, I got a language server configured and those stupid mistakes shouldn't happen again. This looks a lot more green right now, great!
As @acid-bong mentioned, the correct PR title would be "nixos/docker-rootless: add option to autoprune on schedule". This would also be the title for the commit in the PR.
Also, one thing I'm noticing is that most of this code is duplicated from the docker.nix module. Is there a way we could maybe reuse some of the code?
@limwa Thank you for the hints! As I stated above, reusing code feels like the way to go here, however I don't know how to do it. If you give me some pointers, I'd be happy to try, though.
@limwa Thank you for the hints! As I stated above, reusing code feels like the way to go here, however I don't know how to do it. If you give me some pointers, I'd be happy to try, though.
Hi, I asked about that on the NixOS/Nixpkgs Contributions matrix chat, but got no response. I have some clues on how that could be done, but since it would be the first time it is done, as far as I am aware, I think it's okay to leave it as-is.
> @limwa Thank you for the hints! As I stated above, reusing code feels like the way to go here, however I don't know how to do it. If you give me some pointers, I'd be happy to try, though.
> Hi, I asked about that on the NixOS/Nixpkgs Contributions matrix chat, but got no response. I have some clues on how that could be done, but since it would be the first time it is done, as far as I am aware, I think it's okay to leave it as-is.
Thank you for the effort to investigate! :)
environment.DOCKER_HOST = "unix://%t/docker.sock";
By default the service is connecting to /var/run/docker.sock because nowhere it is specified to use the rootless socket
unitConfig.ConditionUser = "!root";
unitConfig.X-StopOnRemoval = false;
The rootless daemon never runs for root but this job doesn't have that restriction. Root also has a user manager
systemd.user.timers.docker-prune = lib.mkIf cfg.autoPrune.enable {
unitConfig.ConditionUser = "!root";
same as above
Have you tested your changes with docker-rootless on your machine?
I can remember doing it, but I was even more a beginner than I am now, so lets redo that exercise now!
Since I am running into an error that is fixed by that line I probably did not tested it properly back in the day. I am sorry for the overhead I created for you, @aaravrav, by not doing proper testing on my own in the first place. That's usually not my style.
Thank you @aaravrav for the effort to test this one. I took all your suggestions and tested it on my maschine, where the service successfully cleaned up my docker images just fine. If you don't mind I'd appreciate your approval here! :)
Approved these changes.
Approved these changes.
small nit pick:
The allVolumes option is missing. "docker.nix" has autoPrune.allVolumes.{enable,flags}
I think this PR copies an older version of the "rootful" options.
i reordered the commits and squashed one to reduce the amount of changes.
aaravrav
georgkrause
The
dockermodule already has an option to enable an auto-prune systemd service. However, docker rootless did not had this option, yet. When I switched, one of my hosts run full, so I think this is a valuable addition. This is my first contribution, so please let me know if I did something wrong so I can fix it.<!--
^ Please summarise the changes you have done and explain why they are necessary here ^
For package updates please link to a changelog or describe changes, this helps your fellow maintainers discover breaking updates.
For new packages please briefly describe the package or provide a link to its homepage.
-->
Things done
<!-- Please check what applies. Note that these are not hard requirements but merely serve as information for reviewers. -->
- [x] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- [ ] [NixOS tests] in [nixos/tests].
- [ ] [Package tests] at
passthru.tests.- [ ] Tests in [lib/tests] or [pkgs/test] for functions and "core" functionality.
nixpkgs-reviewon this PR. See [nixpkgs-review usage]../result/bin/.- [ ] Package update: when the change is major or breaking.
- [ ] Module addition: when adding a new NixOS module.
- [ ] Module update: when the change is significant.
[NixOS tests]: https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests
[Package tests]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests
[nixpkgs-review usage]: https://github.com/Mic92/nixpkgs-review#usage
[CONTRIBUTING.md]: https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md
[lib/tests]: https://github.com/NixOS/nixpkgs/blob/master/lib/tests
[maintainers/README.md]: https://github.com/NixOS/nixpkgs/blob/master/maintainers/README.md
[nixos/tests]: https://github.com/NixOS/nixpkgs/blob/master/nixos/tests
[pkgs/README.md]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md
[pkgs/test]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/test
---
Add a :+1: [reaction] to [pull requests you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc