summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-01 16:46:01 +0200
committerLudovic Courtès <ludo@gnu.org>2015-05-11 17:13:24 +0200
commita98fa2d9e2b06e2561330c5ef845ffaf131e95ac (patch)
treed79d47cccbd5f41e2127735fed4c48e29d87eeae /nix
parent4ab4b0c109734bd6e265ca5f1b6415c31c03ab11 (diff)
downloadguix-a98fa2d9e2b06e2561330c5ef845ffaf131e95ac.tar.gz
Allow regular files as GC roots
If a root is a regular file, then its name must denote a store
path. For instance, the existence of the file

  /nix/var/nix/gcroots/per-user/eelco/hydra-roots/wzc3cy1wwwd6d0dgxpa77ijr1yp50s6v-libxml2-2.7.7

would cause

  /nix/store/wzc3cy1wwwd6d0dgxpa77ijr1yp50s6v-libxml2-2.7.7

to be a root.

This is useful because it involves less I/O (no need for a readlink()
call) and takes up less disk space (the symlink target typically takes
up a full disk block, while directory entries are packed more
efficiently). This is particularly important for hydra.nixos.org,
which has hundreds of thousands of roots, and where reading the roots
can take 25 minutes.
Diffstat (limited to 'nix')
-rw-r--r--nix/libstore/gc.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
index f90edac1cd..e7285fb7dd 100644
--- a/nix/libstore/gc.cc
+++ b/nix/libstore/gc.cc
@@ -328,6 +328,12 @@ static void findRoots(StoreAPI & store, const Path & path, Roots & roots)
             }
         }
 
+        else if (S_ISREG(st.st_mode)) {
+            Path storePath = settings.nixStore + "/" + baseNameOf(path);
+            if (store.isValidPath(storePath))
+                roots[path] = storePath;
+        }
+
     }
 
     catch (SysError & e) {