about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.dir-locals.el4
-rw-r--r--.envrc7
-rw-r--r--.gitignore29
-rw-r--r--.golangci.yaml21
-rw-r--r--LICENSE19
-rw-r--r--README.md1
-rw-r--r--ci.nix14
-rw-r--r--default.nix21
-rw-r--r--go.mod3
-rwxr-xr-xjustfile12
-rw-r--r--npins/default.nix80
-rw-r--r--npins/sources.json29
-rw-r--r--shell.nix22
13 files changed, 262 insertions, 0 deletions
diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 0000000..f943f69
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,4 @@
+;;; Directory Local Variables            -*- no-byte-compile: t -*-
+;;; For more information see (info "(emacs) Directory Variables")
+
+((go-ts-mode . ((apheleia-formatter . golines)))))
diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..a75b02f
--- /dev/null
+++ b/.envrc
@@ -0,0 +1,7 @@
+layout go
+if type -P lorri &>/dev/null; then
+  eval "$(lorri direnv)"
+else
+  echo 'while direnv evaluated .envrc, could not find the command "lorri" [https://github.com/nix-community/lorri]'
+  use nix
+fi
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3da4605
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,29 @@
+# Created by https://www.toptal.com/developers/gitignore/api/go
+# Edit at https://www.toptal.com/developers/gitignore?templates=go
+
+### Go ###
+# If you prefer the allow list template instead of the deny list, see community template:
+# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
+#
+# Binaries for programs and plugins
+*.exe
+*.exe~
+*.dll
+*.so
+*.dylib
+
+# Test binary, built with `go test -c`
+*.test
+
+# Output of the go coverage tool, specifically when used with LiteIDE
+*.out
+
+# Dependency directories (remove the comment below to include it)
+vendor/
+
+# Go workspace file
+go.work
+
+# End of https://www.toptal.com/developers/gitignore/api/go
+/.pre-commit-config.yaml
+/result
diff --git a/.golangci.yaml b/.golangci.yaml
new file mode 100644
index 0000000..1a9f243
--- /dev/null
+++ b/.golangci.yaml
@@ -0,0 +1,21 @@
+---
+# yamllint disable-line rule:line-length
+# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
+linters:
+  fast: false
+  enable:
+    - gocritic
+    - godox
+    - gosec
+    - grouper
+    - lll
+    - nilerr
+    - nlreturn
+    - noctx
+    - nosprintfhostport
+    - paralleltest
+    - prealloc
+    - reassign
+    - revive
+    - sloglint
+    - unconvert
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..edbe912
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2024 Alan Pearce <alan@alanpearce.eu>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9d632e5
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# x
diff --git a/ci.nix b/ci.nix
new file mode 100644
index 0000000..897b78a
--- /dev/null
+++ b/ci.nix
@@ -0,0 +1,14 @@
+{ pkgs ? (
+    let
+      sources = import ./npins;
+    in
+    import sources.nixpkgs { }
+  )
+}:
+pkgs.mkShell {
+  packages = with pkgs; [
+    go
+    templ
+    just
+  ];
+}
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..779ea74
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,21 @@
+let
+  sources = import ./npins;
+
+  pkgs = import sources.nixpkgs { };
+  pre-commit-hooks = import sources.pre-commit-hooks;
+in
+{
+  pre-commit-check = pre-commit-hooks.run {
+    src = ./.;
+    hooks = {
+      go-mod-tidy = {
+        enable = true;
+        name = "go-mod-tidy";
+        description = "Run `go mod tidy`";
+        types_or = [ "go" "go-mod" ];
+        entry = "${pkgs.go}/bin/go mod tidy";
+        pass_filenames = false;
+      };
+    };
+  };
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..d3ed86a
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module go.alanpearce.eu/x
+
+go 1.22.3
diff --git a/justfile b/justfile
new file mode 100755
index 0000000..fc55d00
--- /dev/null
+++ b/justfile
@@ -0,0 +1,12 @@
+#!/usr/bin/env cached-nix-shell
+#!nix-shell ci.nix -i "just --justfile"
+
+default:
+	@just --list --justfile {{ justfile() }} --unsorted
+
+check-licenses:
+	go-licenses check ./...
+
+update-all:
+	npins update
+	go get -u all
diff --git a/npins/default.nix b/npins/default.nix
new file mode 100644
index 0000000..5e7d086
--- /dev/null
+++ b/npins/default.nix
@@ -0,0 +1,80 @@
+# Generated by npins. Do not modify; will be overwritten regularly
+let
+  data = builtins.fromJSON (builtins.readFile ./sources.json);
+  version = data.version;
+
+  mkSource =
+    spec:
+    assert spec ? type;
+    let
+      path =
+        if spec.type == "Git" then
+          mkGitSource spec
+        else if spec.type == "GitRelease" then
+          mkGitSource spec
+        else if spec.type == "PyPi" then
+          mkPyPiSource spec
+        else if spec.type == "Channel" then
+          mkChannelSource spec
+        else
+          builtins.throw "Unknown source type ${spec.type}";
+    in
+    spec // { outPath = path; };
+
+  mkGitSource =
+    {
+      repository,
+      revision,
+      url ? null,
+      hash,
+      branch ? null,
+      ...
+    }:
+    assert repository ? type;
+    # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
+    # In the latter case, there we will always be an url to the tarball
+    if url != null then
+      (builtins.fetchTarball {
+        inherit url;
+        sha256 = hash; # FIXME: check nix version & use SRI hashes
+      })
+    else
+      assert repository.type == "Git";
+      let
+        urlToName =
+          url: rev:
+          let
+            matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url;
+
+            short = builtins.substring 0 7 rev;
+
+            appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
+          in
+          "${if matched == null then "source" else builtins.head matched}${appendShort}";
+        name = urlToName repository.url revision;
+      in
+      builtins.fetchGit {
+        url = repository.url;
+        rev = revision;
+        inherit name;
+        # hash = hash;
+      };
+
+  mkPyPiSource =
+    { url, hash, ... }:
+    builtins.fetchurl {
+      inherit url;
+      sha256 = hash;
+    };
+
+  mkChannelSource =
+    { url, hash, ... }:
+    builtins.fetchTarball {
+      inherit url;
+      sha256 = hash;
+    };
+in
+if version == 3 then
+  builtins.mapAttrs (_: mkSource) data.pins
+else
+  throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
diff --git a/npins/sources.json b/npins/sources.json
new file mode 100644
index 0000000..46dcce1
--- /dev/null
+++ b/npins/sources.json
@@ -0,0 +1,29 @@
+{
+  "pins": {
+    "nixpkgs": {
+      "type": "Git",
+      "repository": {
+        "type": "GitHub",
+        "owner": "NixOS",
+        "repo": "nixpkgs"
+      },
+      "branch": "nixpkgs-unstable",
+      "revision": "9c513fc6fb75142f6aec6b7545cb8af2236b80f5",
+      "url": "https://github.com/NixOS/nixpkgs/archive/9c513fc6fb75142f6aec6b7545cb8af2236b80f5.tar.gz",
+      "hash": "1wigq25g54b74badivmb5svcis96fb6mginj0grk1s4rxmp33vbf"
+    },
+    "pre-commit-hooks": {
+      "type": "Git",
+      "repository": {
+        "type": "GitHub",
+        "owner": "cachix",
+        "repo": "pre-commit-hooks.nix"
+      },
+      "branch": "master",
+      "revision": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07",
+      "url": "https://github.com/cachix/pre-commit-hooks.nix/archive/0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07.tar.gz",
+      "hash": "0bmgc731c5rvky6qxc4f6gvgyiic8dna5dv3j19kya86idf7wn0p"
+    }
+  },
+  "version": 3
+}
\ No newline at end of file
diff --git a/shell.nix b/shell.nix
new file mode 100644
index 0000000..8f89178
--- /dev/null
+++ b/shell.nix
@@ -0,0 +1,22 @@
+{ pkgs ? (
+    let
+      sources = import ./npins;
+    in
+    import sources.nixpkgs { }
+  )
+}:
+let
+  inherit (import ./.) pre-commit-check;
+in
+pkgs.mkShell {
+  inherit (pre-commit-check) shellHook;
+  packages = with pkgs; [
+    go
+    npins
+    gopls
+    go-licenses
+    gotools
+    templ
+    just
+  ];
+}