Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages for reading sqlite databases #121

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
watch_file devshell.nix

if nix flake metadata &>/dev/null; then
use flake
else
use nix
fi
66 changes: 33 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
name: CI

on:
push:
branches:
- main
pull_request:
push:
branches:
- main
pull_request:

jobs:
fixtures:
name: fixtures-up-to-date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
install_url: https://releases.nixos.org/nix/nix-2.12.1/install
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Build fixtures
run: bash -c 'cd test/testdata && ./build-fixtures.go'
- name: Diff fixtures
run: git diff --exit-code test/testdata
fixtures:
name: fixtures-up-to-date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
install_url: https://releases.nixos.org/nix/nix-2.12.1/install
- uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Build fixtures
run: bash -c 'cd test/testdata && ./build-fixtures.go'
- name: Diff fixtures
run: git diff --exit-code test/testdata

build:
strategy:
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
go: [ '1.20', '1.21' ]
runs-on: ${{ matrix.os }}
build:
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
go: ["1.20", "1.21"]
runs-on: ${{ matrix.os }}

name: Build (Go ${{ matrix.go }}, OS ${{ matrix.os }})
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- name: go test -race -bench='.+' -v ./...
run: go test -race -bench='.+' -v ./...
name: Build (Go ${{ matrix.go }}, OS ${{ matrix.os }})
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- name: go test -race -bench='.+' -v ./...
run: go test -race -bench='.+' -v ./...
62 changes: 31 additions & 31 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:
push:
tags:
- v*
branches:
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.61.0
golangci:
name: lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.61.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --timeout=10m
# Optional: golangci-lint command line arguments.
args: --timeout=10m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true
# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
74 changes: 37 additions & 37 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
linters:
enable:
- errname
- exhaustive
- gci
- gochecknoglobals
- gochecknoinits
- goconst
- godot
- gofumpt
- goheader
- goimports
- gosec
- importas
- ireturn
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- prealloc
- predeclared
- revive
- rowserrcheck
- stylecheck
- tagliatelle
- tenv
- testpackage
- unconvert
- unparam
- wastedassign
- whitespace
- wsl
enable:
- errname
- exhaustive
- gci
- gochecknoglobals
- gochecknoinits
- goconst
- godot
- gofumpt
- goheader
- goimports
- gosec
- importas
- ireturn
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- prealloc
- predeclared
- revive
- rowserrcheck
- stylecheck
- tagliatelle
- tenv
- testpackage
- unconvert
- unparam
- wastedassign
- whitespace
- wsl
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,80 @@
# go-nix - Nix experiments written in go

*STATUS*: experimental
_STATUS_: experimental

This repository holds a bunch of experiments written in Go.

## `cmd/gonix`

A command line entrypoint called `gonix`, currently implementing the nar
{cat,dump-path,ls} commands.

They're not meant to be 100% compatible, but are documented in the `--help`
output.

## `pkg/derivation`

A parser for Nix `.drv` files.
Functions to calculate derivation paths and output hashes.

## `pkg/derivation/store`

A Structure to hold derivation graphs.

## `pkg/hash`

Methods to serialize and deserialize some of the hashes used in nix code and
`.narinfo` files.

## `pkg/nar`

A Nix ARchive (NAR) file Reader and Writer, with an interface similar to
`archive/tar` from the stdlib, as well as a `DumpPath` method, which
will assemble a NAR representation of a local file system path.

## `pkg/nar/ls`

A parser for .ls files (providing an index for .nar files)

## `pkg/nar/narinfo`

A parser and generator for `.narinfo` files.

## `pkg/nixbase32`

An implementation of the slightly odd "base32" encoding that's used in Nix,
providing some of the functions in `encoding/base32.Encoding`.

## `pkg/storepath`

A parser and regexes for Nix Store Paths.

## `pkg/storepath/references`

A Nix Store path reference scanner.

## `pkg/sqlite`

A collection of interfaces and utilities for writing to and querying various `sqlite` databases that Nix uses.

[sqlc]: https://github.com/sqlc-dev/sqlc

## `pkg/sqlite/binary_cache_v6`

[SQLC] generated code for querying the Nar Info Disk Cache, typically located at `$XDG_CACHE_HOME/nix/binary-cache-v6.sqlite`.

## `pkg/sqlite/eval_cache_v5`

[SQLC] generated code for querying an instance of the Eval Cache, typically located at `$XDG_CACHE_HOME/nix/eval-cache-v5/*.sqlite`.

## `pkg/sqlite/fetcher_cache_v2`

[SQLC] generated code for querying the fetcher cache, typically located in `$XDG_CACHE_HOME/nix/fetcher-cache-v2.sqlite`.

## `pkg/sqlite/nix_v10`

[SQLC] generated code for querying the main Nix database, typically located in `/nix/var/nix/db.sqlite`.

## `pkg/wire`

Methods to parse and produce fields used in the low-level Nix wire protocol.
26 changes: 26 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file provides backward compatibility to nix < 2.4 clients
{
system ? builtins.currentSystem,
}:
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);

root = lock.nodes.${lock.root};
inherit (lock.nodes.${root.inputs.flake-compat}.locked)
owner
repo
rev
narHash
;

flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};

flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.defaultNix
22 changes: 22 additions & 0 deletions devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
perSystem,
pkgs,
...
}:
pkgs.mkShell {
env.GOROOT = "${pkgs.go}/share/go";

packages =
(with pkgs; [
delve
pprof
go
gotools
golangci-lint
lazysql
sqlc
])
++ (with perSystem; [
gomod2nix.default
]);
}
Loading
Loading