nixos/nix-optimise: be smarter about when we run the store optimiser
We might be inside a NixOS container on a non-NixOS host, so instead of not
running at all inside a container, check if the nix-daemon socket is writable as
it will tell us if the store is managed from here or outside.
Fixes #63578
commit897834f0159fd3180430cfa88ebd70a772238ceb
authorPeter Hoeg <peter@hoeg.com>
dateMon 1 Jul 2019, 18:05 (7 years ago)
parent20b993e
nixos/modules/services/misc/nix-optimise.nix+2−2
@@ -40,8 +40,8 @@ in
4040
4141 systemd.services.nix-optimise =
4242 { description = "Nix Store Optimiser";
43− # No point running it inside a nixos-container. It should be on the host instead.
44− unitConfig.ConditionVirtualization = "!container";
43+ # No point this if the nix daemon (and thus the nix store) is outside
44+ unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket";
4545 serviceConfig.ExecStart = "${config.nix.package}/bin/nix-store --optimise";
4646 startAt = optionals cfg.automatic cfg.dates;
4747 };
nixos/modules/virtualisation/container-config.nix+1
@@ -7,6 +7,7 @@ with lib;
77 config = mkIf config.boot.isContainer {
88
99 # Disable some features that are not useful in a container.
10+ nix.optimise.automatic = mkDefault false; # the store is host managed
1011 services.udisks2.enable = mkDefault false;
1112 powerManagement.enable = mkDefault false;
1213