Chris Stryczynski

Software Developer / Consultant

What is the purpose of the Nix store database?

Posted on: 20/06/2019

So I asked the question on the #nixos IRC:

21:03 < chrisq2> Hopefully a quick question, what is the Nix database 
                 responsible for? What is it's purpose? 
21:04 < MichaelRaskin> It keeps track of what paths are actually valid, and 
                       what are their dependency relations

Sooo if we copy the database and open it up:

cp /nix/var/nix/db/db.sqlite .
sqlite3 db.sqlite '.schema'
CREATE TABLE ValidPaths (
    id               integer primary key autoincrement not null,
    path             text unique not null,
    hash             text not null,
    registrationTime integer not null,
    deriver          text,
    narSize          integer,
    ultimate         integer, -- null implies "false"
    s
igs             text, -- space-separated
    ca               text -- if not null, an assertion that the path is content-addressed; see ValidPathInfo
);
CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE Refs (
    referrer  integer not null,
    reference integer not null,
    primary key (referrer, reference),
    foreign key (referrer) references ValidPaths(id) on delete cascade,
    foreign key (reference) references ValidPaths(id) on delete restrict
);
CREATE INDEX IndexReferrer on Refs(referrer);
CREATE INDEX IndexReference on Refs(reference);
CREATE TRIGGER DeleteSelfRefs before delete on ValidPaths
  begin
    delete from Refs where referrer = old.id and reference = old.id;
  end;
CREATE TABLE DerivationOutputs (
    drv  integer not null,
    id   text not null, -- symbolic output id, usually "out"
    path text not null,
    primary key (drv, id),
    foreign key (drv) references ValidPaths(id) on delete cascade
);
CREATE INDEX IndexDerivationOutputs on DerivationOutputs(path);

Oohh so thats how nix keeps track of it’s dependencies. Presumably!

Comments

No comments, yet!

Submit a comment