From 894ae1f30e1bdbeabf0b891f17134565036a5554 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Thu, 25 Jul 2024 16:26:04 +0200 Subject: [PATCH] replace Makefile with a Nix package --- Makefile | 57 ----------------------------------------------------- default.nix | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 57 deletions(-) delete mode 100644 Makefile create mode 100644 default.nix diff --git a/Makefile b/Makefile deleted file mode 100644 index c39e025..0000000 --- a/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -PREFIX ?= /usr/local -GOFLAGS = -tags='fts5,libsqlite3' -ldflags="-s -w -X main.compiledOn=$(SOURCE_DATE_EPOCH)" - -.PHONY: all -all: bin/magneticod bin/magneticow - -bin/magneticod: - go install $(GOFLAGS) ./cmd/magneticod - -bin/magneticow: - # TODO: minify /data/* files! - go install $(GOFLAGS) ./cmd/magneticow - -.PHONY: vet -vet: - go vet ./... - -.PHONY: check -check: - go test $(GOFLAGS) ./... - -.PHONY: install -install: bin/magneticod bin/magneticow - install -m 555 -Dt "$(PREFIX)/bin/" bin/magnetico{w,d} - -.PHONY: format -format: - gofmt -w ./cmd/ - gofmt -w ./pkg/ - -# Formatting Errors -# Since gofmt returns zero even if there are files to be formatted, we use: -# -# ! gofmt -d ${GOPATH}/path/ 2>&1 | read -# -# to return 1 if there are files to be formatted, and 0 if not. -# https://groups.google.com/forum/#!topic/Golang-Nuts/pdrN4zleUio -# -# How can I use Bash syntax in Makefile targets? -# Because `read` is a bash command. -# https://stackoverflow.com/a/589300/4466589 -# -# How to ignore bindata.go -# Due to irrational insistence of some Go developers, gofmt, like many -# other tools of Go ecosystem, does not have flags for common scenarios -# such as ignoring certain files by pattern etc. Thus we use `go list` -# and grep together to achieve the desired result. -# -# The original query is this: -# gofmt -l $(go list -f $'{{range .GoFiles}}{{$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) -# -# The original query is then escaped for Makefile (by repeating dollar signs $ -> $$). -.PHONY: check-formatting -check-formatting: SHELL:=/bin/bash # HERE: this is setting the shell for check-formatting only -check-formatting: - ! gofmt -l $$(go list -f $$'{{range .GoFiles}}{{$$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) 2>&1 | tee /dev/fd/2 | read - ! gofmt -l $$(go list -f $$'{{range .GoFiles}}{{$$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) 2>&1 | tee /dev/fd/2 | read diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..98e23d8 --- /dev/null +++ b/default.nix @@ -0,0 +1,35 @@ +let + + nixpkgs = builtins.fetchTarball + { url = "https://github.com/NixOS/nixpkgs/archive/f12ee5f64c6a.tar.gz"; + sha256 = "14afxk35w3kbqimxcp39ngv9cqpc24glss1727ymk4napfg5v7hm"; + }; + + pkgs = import { }; + + magnetico = { lib, buildGoModule, nixosTests, sqlite }: + buildGoModule { + pname = "magnetico"; + version = "0.12.1"; + + src = lib.cleanSource ./.; + + vendorHash = "sha256-jIVMQtPCq9RYaYsH4LSZJFspH6TpCbgzHN0GX8cM/CI="; + + buildInputs = [ sqlite ]; + + tags = [ "fts5" "libsqlite3" ]; + ldflags = [ "-s" "-w" ]; + + passthru.tests = { inherit (nixosTests) magnetico; }; + + meta = with lib; { + description = "Autonomous (self-hosted) BitTorrent DHT search engine suite"; + homepage = "https://maxwell.ydns.eu/git/rnhmjoj/magnetico"; + license = licenses.agpl3Only; + badPlatforms = platforms.darwin; + maintainers = with maintainers; [ rnhmjoj ]; + }; + }; + +in pkgs.callPackage magnetico { }