From 897834f0159fd3180430cfa88ebd70a772238ceb Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Mon, 1 Jul 2019 18:05:57 +0800 Subject: [PATCH] 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 --- nixos/modules/services/misc/nix-optimise.nix | 4 ++-- nixos/modules/virtualisation/container-config.nix | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/misc/nix-optimise.nix b/nixos/modules/services/misc/nix-optimise.nix index 416529f690e0..e02026d5f76c 100644 --- a/nixos/modules/services/misc/nix-optimise.nix +++ b/nixos/modules/services/misc/nix-optimise.nix @@ -40,8 +40,8 @@ in systemd.services.nix-optimise = { description = "Nix Store Optimiser"; - # No point running it inside a nixos-container. It should be on the host instead. - unitConfig.ConditionVirtualization = "!container"; + # No point this if the nix daemon (and thus the nix store) is outside + unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket"; serviceConfig.ExecStart = "${config.nix.package}/bin/nix-store --optimise"; startAt = optionals cfg.automatic cfg.dates; }; diff --git a/nixos/modules/virtualisation/container-config.nix b/nixos/modules/virtualisation/container-config.nix index 604fb8a75932..f7a37d8c9f3b 100644 --- a/nixos/modules/virtualisation/container-config.nix +++ b/nixos/modules/virtualisation/container-config.nix @@ -7,6 +7,7 @@ with lib; config = mkIf config.boot.isContainer { # Disable some features that are not useful in a container. + nix.optimise.automatic = mkDefault false; # the store is host managed services.udisks2.enable = mkDefault false; powerManagement.enable = mkDefault false;