From e4cbcab81c44367eb4680c58a4802de8830ef6a6 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 18 Sep 2023 18:53:40 +0200 Subject: [PATCH] Use a systemd mount directly for the nix store Allows the LazyUnmount option and avoids the stage1 hack with /nix//store. --- m/module/shared-nix-store.nix | 50 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/m/module/shared-nix-store.nix b/m/module/shared-nix-store.nix index 72eab92..95df035 100644 --- a/m/module/shared-nix-store.nix +++ b/m/module/shared-nix-store.nix @@ -38,37 +38,27 @@ # Mount an overlay in /nix/store using as lower layer the NFS store and upper # layer the disk nix store. The destination is still the nix store in # /nix/store (confusing). We need rw access, as the daemon need to write the - # lock files to build derivations locally. - # HACK: Use /nix//store to prevent the overlay to be mounted on boot, see: - # https://github.com/NixOS/nixpkgs/blob/17a46d09ac123d0da3a26855bf3af7db01f9c751/nixos/lib/utils.nix#L14 - fileSystems."/nix//store" = { - device = "overlay"; - fsType = "overlay"; - options = [ + # lock files to build derivations locally. Use a systemd mount unit directly + # so we can specify the LazyUmount option and we avoid having it mounted + # in the stage1 before systemd. + systemd.mounts = [ + { + what = "overlay"; + type = "overlay"; + where = "/nix/store"; # We need the local-fs.target to be ready, so the network interfaces can # be configured to the network.target is reached. So make this a netdev # mount. - "_netdev" - "lowerdir=/mnt/hut-nix-store,upperdir=/nix/store,workdir=/mnt/nix-work" - "x-systemd.requires-mounts-for=/nix/store" - # We need to wait for the NFS mount - "x-systemd.requires-mounts-for=/mnt/hut-nix-store" - ]; - depends = [ "/nix/store" "/mnt/hut-nix-store" "/mnt/nix-work" ]; - }; - - # Maybe we should move it to a systemd mount, so we avoid the /nix//store - # hack. Example (not tested): - # systemd.mounts = [ - # { - # what = "overlay"; - # type = "overlay"; - # where = "/nix/store"; - # options = "lowerdir=/mnt/hut-nix-store,upperdir=/nix/store,workdir=/mnt/nix-work"; - # description = "Overlay nix store mount"; - # requires = [ "hut-nix-store.mount" ]; - # after = [ "mnt-hut\\x2dnix\\x2dstore.mount" ]; - # before = [ "nix-daemon.service" ]; - # } - # ]; + options = "_netdev,lowerdir=/mnt/hut-nix-store,upperdir=/nix/store,workdir=/mnt/nix-work"; + description = "Overlay /nix/store mount"; + mountConfig = { + LazyUnmount = true; + }; + unitConfig = { + # We need to wait for the NFS mount + RequiresMountsFor = "/nix/store /mnt/hut-nix-store"; + Before = "remote-fs.target"; + }; + } + ]; }