hnix-store-db: Nix store database support

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

Implementation of the Nix store database


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.1
Change log CHANGELOG.md
Dependencies attoparsec, base (>=4.12 && <5), bytestring, data-default-class, esqueleto (>=3.5.10 && <3.7), fast-logger, hnix-store-core (>=0.8), hnix-store-db, microlens, monad-logger, persistent (>=2.14.5 && <2.18), persistent-sqlite (>=2.13.1 && <2.14), template-haskell, text, time, transformers, unliftio-core [details]
License Apache-2.0
Copyright 2023 Sorki
Author Sorki
Maintainer srk@48.io
Category Nix
Home page https://github.com/haskell-nix/hnix-store
Uploaded by srk at 2025-09-16T15:03:27Z

Modules

[Index] [Quick Jump]

Flags

Automatic Flags
NameDescriptionDefault
build-bench

Build db-bench executable

Disabled
build-readme

Build README.lhs example

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for hnix-store-db-0.1.0.1

[back to package description]

hnix-store-db

Nix SQLite database implementation.

Only read-only functionality provided for database schema version 10.

API

The interface is experimental and might change wildly.

Example

This example is runnable via cabal run db-readme.

{-# LANGUAGE OverloadedStrings #-}

import Data.Default.Class (Default(def))

import qualified Control.Monad
import qualified Control.Monad.IO.Class

import qualified Database.Esqueleto.Experimental

import qualified System.Nix.StorePath
import qualified System.Nix.Store.DB.Run
import qualified System.Nix.Store.DB.Schema

import System.Nix.Store.DB.Query

main :: IO ()
main = do
  System.Nix.Store.DB.Run.runSystemSqlite $ do
    (paths, refs, drvOuts) <- queryEverything

    Control.Monad.IO.Class.liftIO $ do
      putStrLn $ "Stats: "
      let stat name v = putStrLn $ "- " ++ name ++ ": " ++ show (length v)
      stat "ValidPath(s)" paths
      stat "Ref(s)" refs
      stat "DerivationOutput(s)" drvOuts

    maybeValidPath <- queryOneValidDerivationEntity
    case maybeValidPath of
      Nothing -> pure ()
      Just validPathEntity -> do
        let pth =
              System.Nix.Store.DB.Schema.validPathPath
              $ Database.Esqueleto.Experimental.entityVal validPathEntity

        (same, samePath, references, referrers, validDerivers, outputs) <- (,,,,,)
          <$> queryPathInfo pth
          <*> queryPathFromHashPart def (System.Nix.StorePath.storePathHash pth)
          <*> queryReferences validPathEntity
          <*> queryReferrers pth
          <*> queryValidDerivers pth
          <*> queryDerivationOutputs validPathEntity

        Control.Monad.unless (same == Just (Database.Esqueleto.Experimental.entityVal validPathEntity))
          $ error "queryPathInfo failed to roundtrip"
        Control.Monad.unless (samePath == Just pth)
          $ error "queryPathFromHashPart failed to roundtrip"

        Control.Monad.IO.Class.liftIO $ do
          putStrLn $ "References: "
          print references
          putStrLn $ "Referrers: "
          print referrers
          putStrLn $ "Valid derivers: "
          print validDerivers
          putStrLn $ "Derivation outputs: "
          print outputs

    pure ()