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

feat(nix): Nix support via flake #28

Merged
merged 4 commits into from
Nov 10, 2023
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
23 changes: 23 additions & 0 deletions .github/workflows/test-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test Nix Flake build

on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-23.05
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- run: nix build . --show-trace

- run: nix flake check
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ sources
grimd
grimd.log
grimd.toml
.DS_Store
.DS_Store

result
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,15 @@ Forked from [looterz/grimd](https://github.com/looterz/grimd)
go install github.com/cottand/grimd@latest
```

You can also download one of the [releases](https://github.com/cottand/grimd/releases)
or [docker images](https://github.com/cottand/grimd/pkgs/container/grimd). Detailed guides and resources can be found on
the [wiki](https://github.com/cottand/grimd/wiki).
You can also
- download one of the binary [releases](https://github.com/cottand/grimd/releases)
- use the [Docker image](https://github.com/cottand/grimd/pkgs/container/grimd)
- `docker run -d -p 53:53/udp -p 53:53/tcp -p 8080:8080/tcp ghcr.io/cottand/grimd`
- use [Docker compose YML](https://raw.githubusercontent.com/cottand/grimd/master/docker-compose.yml)
- use the [Nix flake](https://github.com/Cottand/grimd/tree/master/flake.nix)
- `nix run github:cottand/grimd`

# Docker Installation

To quickly get grimd up and running with docker, run

```
docker run -d -p 53:53/udp -p 53:53/tcp -p 8080:8080/tcp ghcr.io/cottand/grimd:latest
```

Alternatively, download
the [docker-compose.yml](https://raw.githubusercontent.com/cottand/grimd/master/docker-compose.yml) file and launch it
using docker-compose.

```
docker-compose up -d
```
Detailed guides and resources can be found on the [wiki](https://github.com/cottand/grimd/wiki).

# Configuration

Expand All @@ -69,7 +59,7 @@ Usage of grimd:

# Building

Requires golang 1.20 or higher, you build grimd like any other golang application, for example to build for linux x64
Requires golang 1.21 or higher, you build grimd like any other golang application, for example to build for linux x64

```shell
env GOOS=linux GOARCH=amd64 go build -v github.com/cottand/grimd
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
description = "Grimd, a fast dns proxy, built to black-hole internet advertisements and malware servers";


inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils, ... }:
(flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; }; in {

# Build & packaging
## use with `nix build`
packages = rec {
grimd = pkgs.buildGo121Module {
inherit system;
vendorSha256 = "sha256-5dIZzqaw88lKuh1JHJurRZCPgrNzDHK/53bXKNGQBvQ=";
pname = "grimd";
version = "0.0.1-test";
src = ./.;
};
default = grimd;
};


# Dev environment
## use with `nix develop`
devShells = rec {
grimd = pkgs.mkShell {
packages = [ pkgs.fish pkgs.go_1_21 ];
# Note that `shellHook` still uses bash syntax. This starts fish, then exists the bash shell when fish exits.
shellHook = "fish && exit";
};
default = grimd;
};


# App
## use with `nix run`
apps = rec {
grimd = flake-utils.lib.mkApp { drv = self.packages.${system}.grimd; };
default = grimd;
};

}));
}
1 change: 1 addition & 0 deletions grimd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func TestDohIntegration(t *testing.T) {

// TestDohAsProxy checks that DoH works for non-custom records
func TestDohAsProxy(t *testing.T) {
t.Skip("This test is impure in that it speaks to the internet - disabled by default for reproducibility")
dohBind := "localhost:8181"
integrationTest(func(c *Config) {
c.DnsOverHttpServer.Bind = dohBind
Expand Down
4 changes: 0 additions & 4 deletions shell.nix

This file was deleted.

Loading