diff --git a/.github/workflows/test-nix.yml b/.github/workflows/test-nix.yml new file mode 100644 index 0000000..8f00c62 --- /dev/null +++ b/.github/workflows/test-nix.yml @@ -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 diff --git a/.gitignore b/.gitignore index 91aa98d..8694f09 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ sources grimd grimd.log grimd.toml -.DS_Store \ No newline at end of file +.DS_Store + +result \ No newline at end of file diff --git a/README.md b/README.md index cfda02e..3d3a49f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7bdd046 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1699099776, + "narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f1e01f7 --- /dev/null +++ b/flake.nix @@ -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; + }; + + })); +} diff --git a/grimd_test.go b/grimd_test.go index 0c2c317..bfcd33a 100644 --- a/grimd_test.go +++ b/grimd_test.go @@ -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 diff --git a/shell.nix b/shell.nix deleted file mode 100644 index e9017fe..0000000 --- a/shell.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ pkgs ? import (builtins.fetchTarball "https://api.github.com/repos/nixos/nixpkgs/tarball/nixos-unstable") {} }: - pkgs.mkShell { - nativeBuildInputs = with pkgs; [ go_1_21 ]; -}