Skip to content

Commit 0327d78

Browse files
authored
Merge pull request #121 from brianmcgee/feat/db
Packages for reading sqlite databases
2 parents 1cfc79e + a8075fa commit 0327d78

38 files changed

+1818
-111
lines changed

.envrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
watch_file devshell.nix
2+
3+
if nix flake metadata &>/dev/null; then
4+
use flake
5+
else
6+
use nix
7+
fi

.github/workflows/ci.yml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
name: CI
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
88

99
jobs:
10-
fixtures:
11-
name: fixtures-up-to-date
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v3
15-
- uses: cachix/install-nix-action@v22
16-
with:
17-
install_url: https://releases.nixos.org/nix/nix-2.12.1/install
18-
- uses: actions/setup-go@v4
19-
with:
20-
go-version: '1.21'
21-
- name: Build fixtures
22-
run: bash -c 'cd test/testdata && ./build-fixtures.go'
23-
- name: Diff fixtures
24-
run: git diff --exit-code test/testdata
10+
fixtures:
11+
name: fixtures-up-to-date
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: cachix/install-nix-action@v22
16+
with:
17+
install_url: https://releases.nixos.org/nix/nix-2.12.1/install
18+
- uses: actions/setup-go@v4
19+
with:
20+
go-version: "1.21"
21+
- name: Build fixtures
22+
run: bash -c 'cd test/testdata && ./build-fixtures.go'
23+
- name: Diff fixtures
24+
run: git diff --exit-code test/testdata
2525

26-
build:
27-
strategy:
28-
matrix:
29-
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
30-
go: [ '1.20', '1.21' ]
31-
runs-on: ${{ matrix.os }}
26+
build:
27+
strategy:
28+
matrix:
29+
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
30+
go: ["1.20", "1.21"]
31+
runs-on: ${{ matrix.os }}
3232

33-
name: Build (Go ${{ matrix.go }}, OS ${{ matrix.os }})
34-
steps:
35-
- uses: actions/checkout@v3
36-
- uses: actions/setup-go@v4
37-
with:
38-
go-version: ${{ matrix.go }}
39-
- name: go test -race -bench='.+' -v ./...
40-
run: go test -race -bench='.+' -v ./...
33+
name: Build (Go ${{ matrix.go }}, OS ${{ matrix.os }})
34+
steps:
35+
- uses: actions/checkout@v3
36+
- uses: actions/setup-go@v4
37+
with:
38+
go-version: ${{ matrix.go }}
39+
- name: go test -race -bench='.+' -v ./...
40+
run: go test -race -bench='.+' -v ./...
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
name: golangci-lint
22
on:
3-
push:
4-
tags:
5-
- v*
6-
branches:
7-
- main
8-
pull_request:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- main
8+
pull_request:
99
permissions:
10-
contents: read
11-
# Optional: allow read access to pull request. Use with `only-new-issues` option.
12-
# pull-requests: read
10+
contents: read
11+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
12+
# pull-requests: read
1313
jobs:
14-
golangci:
15-
name: lint
16-
runs-on: ubuntu-22.04
17-
steps:
18-
- uses: actions/checkout@v3
19-
- name: golangci-lint
20-
uses: golangci/golangci-lint-action@v3
21-
with:
22-
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
23-
version: v1.61.0
14+
golangci:
15+
name: lint
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: golangci-lint
20+
uses: golangci/golangci-lint-action@v3
21+
with:
22+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
23+
version: v1.61.0
2424

25-
# Optional: working directory, useful for monorepos
26-
# working-directory: somedir
25+
# Optional: working directory, useful for monorepos
26+
# working-directory: somedir
2727

28-
# Optional: golangci-lint command line arguments.
29-
args: --timeout=10m
28+
# Optional: golangci-lint command line arguments.
29+
args: --timeout=10m
3030

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

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

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

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

.golangci.yml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
linters:
2-
enable:
3-
- errname
4-
- exhaustive
5-
- gci
6-
- gochecknoglobals
7-
- gochecknoinits
8-
- goconst
9-
- godot
10-
- gofumpt
11-
- goheader
12-
- goimports
13-
- gosec
14-
- importas
15-
- ireturn
16-
- lll
17-
- makezero
18-
- misspell
19-
- nakedret
20-
- nestif
21-
- nilerr
22-
- nilnil
23-
- nlreturn
24-
- noctx
25-
- nolintlint
26-
- prealloc
27-
- predeclared
28-
- revive
29-
- rowserrcheck
30-
- stylecheck
31-
- tagliatelle
32-
- tenv
33-
- testpackage
34-
- unconvert
35-
- unparam
36-
- wastedassign
37-
- whitespace
38-
- wsl
2+
enable:
3+
- errname
4+
- exhaustive
5+
- gci
6+
- gochecknoglobals
7+
- gochecknoinits
8+
- goconst
9+
- godot
10+
- gofumpt
11+
- goheader
12+
- goimports
13+
- gosec
14+
- importas
15+
- ireturn
16+
- lll
17+
- makezero
18+
- misspell
19+
- nakedret
20+
- nestif
21+
- nilerr
22+
- nilnil
23+
- nlreturn
24+
- noctx
25+
- nolintlint
26+
- prealloc
27+
- predeclared
28+
- revive
29+
- rowserrcheck
30+
- stylecheck
31+
- tagliatelle
32+
- tenv
33+
- testpackage
34+
- unconvert
35+
- unparam
36+
- wastedassign
37+
- whitespace
38+
- wsl

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,80 @@
11
# go-nix - Nix experiments written in go
22

3-
*STATUS*: experimental
3+
_STATUS_: experimental
44

55
This repository holds a bunch of experiments written in Go.
66

77
## `cmd/gonix`
8+
89
A command line entrypoint called `gonix`, currently implementing the nar
910
{cat,dump-path,ls} commands.
1011

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

1415
## `pkg/derivation`
16+
1517
A parser for Nix `.drv` files.
1618
Functions to calculate derivation paths and output hashes.
1719

1820
## `pkg/derivation/store`
21+
1922
A Structure to hold derivation graphs.
2023

2124
## `pkg/hash`
25+
2226
Methods to serialize and deserialize some of the hashes used in nix code and
2327
`.narinfo` files.
2428

2529
## `pkg/nar`
30+
2631
A Nix ARchive (NAR) file Reader and Writer, with an interface similar to
2732
`archive/tar` from the stdlib, as well as a `DumpPath` method, which
2833
will assemble a NAR representation of a local file system path.
2934

3035
## `pkg/nar/ls`
36+
3137
A parser for .ls files (providing an index for .nar files)
3238

3339
## `pkg/nar/narinfo`
40+
3441
A parser and generator for `.narinfo` files.
3542

3643
## `pkg/nixbase32`
44+
3745
An implementation of the slightly odd "base32" encoding that's used in Nix,
3846
providing some of the functions in `encoding/base32.Encoding`.
3947

4048
## `pkg/storepath`
49+
4150
A parser and regexes for Nix Store Paths.
4251

4352
## `pkg/storepath/references`
53+
4454
A Nix Store path reference scanner.
4555

56+
## `pkg/sqlite`
57+
58+
A collection of interfaces and utilities for writing to and querying various `sqlite` databases that Nix uses.
59+
60+
[sqlc]: https://github.com/sqlc-dev/sqlc
61+
62+
## `pkg/sqlite/binary_cache_v6`
63+
64+
[SQLC] generated code for querying the Nar Info Disk Cache, typically located at `$XDG_CACHE_HOME/nix/binary-cache-v6.sqlite`.
65+
66+
## `pkg/sqlite/eval_cache_v5`
67+
68+
[SQLC] generated code for querying an instance of the Eval Cache, typically located at `$XDG_CACHE_HOME/nix/eval-cache-v5/*.sqlite`.
69+
70+
## `pkg/sqlite/fetcher_cache_v2`
71+
72+
[SQLC] generated code for querying the fetcher cache, typically located in `$XDG_CACHE_HOME/nix/fetcher-cache-v2.sqlite`.
73+
74+
## `pkg/sqlite/nix_v10`
75+
76+
[SQLC] generated code for querying the main Nix database, typically located in `/nix/var/nix/db.sqlite`.
77+
4678
## `pkg/wire`
79+
4780
Methods to parse and produce fields used in the low-level Nix wire protocol.

default.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This file provides backward compatibility to nix < 2.4 clients
2+
{
3+
system ? builtins.currentSystem,
4+
}:
5+
let
6+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
7+
8+
root = lock.nodes.${lock.root};
9+
inherit (lock.nodes.${root.inputs.flake-compat}.locked)
10+
owner
11+
repo
12+
rev
13+
narHash
14+
;
15+
16+
flake-compat = fetchTarball {
17+
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
18+
sha256 = narHash;
19+
};
20+
21+
flake = import flake-compat {
22+
inherit system;
23+
src = ./.;
24+
};
25+
in
26+
flake.defaultNix

devshell.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
perSystem,
3+
pkgs,
4+
...
5+
}:
6+
pkgs.mkShell {
7+
env.GOROOT = "${pkgs.go}/share/go";
8+
9+
packages =
10+
(with pkgs; [
11+
delve
12+
pprof
13+
go
14+
gotools
15+
golangci-lint
16+
lazysql
17+
sqlc
18+
])
19+
++ (with perSystem; [
20+
gomod2nix.default
21+
]);
22+
}

0 commit comments

Comments
 (0)