about summary refs log tree commit diff stats
path: root/nix
diff options
context:
space:
mode:
Diffstat (limited to 'nix')
-rw-r--r--nix/default.nix101
-rw-r--r--nix/gomod2nix.toml121
2 files changed, 222 insertions, 0 deletions
diff --git a/nix/default.nix b/nix/default.nix
new file mode 100644
index 0000000..095b3f7
--- /dev/null
+++ b/nix/default.nix
@@ -0,0 +1,101 @@
+{ pkgs, self }:
+let
+  version = "unstable";
+  shortSHA = self.shortRev or self.dirtyShortRev;
+  fullSHA = self.rev or self.dirtyRev;
+  mkDocker = type: { server, website }:
+    let
+      PORT = 80;
+    in
+    pkgs.dockerTools.${type} {
+      name = "registry.fly.io/alanpearce-eu";
+      tag = fullSHA;
+      contents = [
+        website
+      ];
+      config = {
+        Cmd = [ "${server}/bin/server" ];
+        Env = [
+          "PRODUCTION=true"
+          "LISTEN_ADDRESS=::"
+          "PORT=${builtins.toString PORT}"
+        ];
+        ExposedPorts = {
+          "${builtins.toString PORT}/tcp" = { };
+        };
+      };
+    };
+  mkDockerStream = mkDocker "streamLayeredImage";
+  mkDockerImage = mkDocker "buildLayeredImage";
+in
+with pkgs; rec {
+  default = server;
+  builder = buildGoApplication {
+    pname = "website-builder";
+    inherit version;
+    CGO_ENABLED = 0;
+    src = with lib.fileset; toSource {
+      root = ./..;
+      fileset = unions [
+        ./../go.mod
+        ./../go.sum
+        ./../cmd/build
+        ./../internal
+      ];
+    };
+    modules = ./gomod2nix.toml;
+    subPackages = [ "cmd/build" ];
+  };
+  website = runCommandLocal "build"
+    {
+      src = with lib.fileset; toSource {
+        root = ./..;
+        fileset = unions [
+          ./../config.toml
+          ./../content
+          ./../static
+          ./../templates
+        ];
+      };
+    } ''
+    ${builder}/bin/build -s $src -d $out
+  '';
+  server = buildGoApplication {
+    pname = "server";
+    inherit version;
+    CGO_ENABLED = 0;
+    src = with lib.fileset; toSource {
+      root = ./..;
+      fileset = unions [
+        ./../go.mod
+        ./../go.sum
+        ./../cmd/server
+        ./../internal
+      ];
+    };
+    modules = ./gomod2nix.toml;
+    subPackages = [ "cmd/server" ];
+    ldflags = [
+      "-s"
+      "-w"
+      "-X"
+      "website/internal/server.CommitSHA=${fullSHA}"
+      "-X"
+      "website/internal/server.ShortSHA=${shortSHA}"
+    ];
+  };
+  docker-stream = mkDockerStream { inherit server website; };
+  docker-stream-aarch64-linux = mkDockerStream {
+    inherit website; server = (self.packages.aarch64-linux.server);
+  };
+  docker-stream-x86_64-linux = mkDockerStream {
+    inherit website; server = (self.packages.x86_64-linux.server);
+  };
+  docker-image = mkDockerImage { inherit server website; };
+  docker-image-aarch64-linux = mkDockerImage {
+    inherit website; server = (self.packages.aarch64-linux.server);
+  };
+  docker-image-x86_64-linux = mkDockerImage {
+    inherit website; server = (self.packages.x86_64-linux.server);
+  };
+}
diff --git a/nix/gomod2nix.toml b/nix/gomod2nix.toml
new file mode 100644
index 0000000..089a876
--- /dev/null
+++ b/nix/gomod2nix.toml
@@ -0,0 +1,121 @@
+schema = 3
+
+[mod]
+  [mod."github.com/BurntSushi/toml"]
+    version = "v1.3.2"
+    hash = "sha256-FIwyH67KryRWI9Bk4R8s1zFP0IgKR4L66wNQJYQZLeg="
+  [mod."github.com/Code-Hex/dd"]
+    version = "v1.1.0"
+    hash = "sha256-9aoekzjMXuJmR0/7bfu4y3SfcWBgdfYybB7gt4sNKfk="
+  [mod."github.com/PuerkitoBio/goquery"]
+    version = "v1.9.2"
+    hash = "sha256-9T/XF7YzCDt494E40p46BHZVNGnN4Duqlk/HsdbYEnI="
+  [mod."github.com/a-h/htmlformat"]
+    version = "v0.0.0-20240425000139-1244374b2562"
+    hash = "sha256-qvnbf/VCR2s2VmyPaQeHLkpA01MNy1g1U0l9B9maBcE="
+    replaced = "github.com/alanpearce/htmlformat"
+  [mod."github.com/adrg/frontmatter"]
+    version = "v0.2.0"
+    hash = "sha256-WJsVcdCpkIkjqUz5fJOFStZYwQlrcFzQ6+mZatZiimo="
+  [mod."github.com/andybalholm/cascadia"]
+    version = "v1.3.2"
+    hash = "sha256-Nc9SkqJO/ecincVcUBFITy24TMmMGj5o0Q8EgdNhrEk="
+  [mod."github.com/antchfx/xmlquery"]
+    version = "v1.4.0"
+    hash = "sha256-ReWP6CPDvvWUd7vY0qIP4qyxvrotXrx9HXbGbeProP4="
+  [mod."github.com/antchfx/xpath"]
+    version = "v1.3.0"
+    hash = "sha256-SU+Tnf5c9vsDCrY1BVKjqYLhB91xt9oHBS5bicbs2cA="
+  [mod."github.com/ardanlabs/conf/v3"]
+    version = "v3.1.7"
+    hash = "sha256-7H53l0JN5Q6hkAgBivVQ8lFd03oNmP1IG8ihzLKm2CQ="
+  [mod."github.com/aymerick/douceur"]
+    version = "v0.2.0"
+    hash = "sha256-NiBX8EfOvLXNiK3pJaZX4N73YgfzdrzRXdiBFe3X3sE="
+  [mod."github.com/benpate/derp"]
+    version = "v0.31.0"
+    hash = "sha256-Q/QxVDgOFbUjPlwKOsbft3R/8vbNGescX/dcuJGRE0Q="
+  [mod."github.com/benpate/digit"]
+    version = "v0.12.0"
+    hash = "sha256-+leG0kKa+DjkYYbE8l5voMJPDPMYNJ1GIGEGp7wjoKs="
+  [mod."github.com/benpate/domain"]
+    version = "v0.2.1"
+    hash = "sha256-nO3mRwQqgWaVReRFXhZlxdo3EGt87Z4EzZBOIPyZJcs="
+  [mod."github.com/benpate/exp"]
+    version = "v0.8.3"
+    hash = "sha256-FHKWQBPK+0JKMbrb+TXB+MVfgzV72DAv4gEhUEhmV/g="
+  [mod."github.com/benpate/remote"]
+    version = "v0.15.0"
+    hash = "sha256-Rh0YlDycwVAy+CsfB62GIsHgLWen4fD9nT6hrwMp3mk="
+  [mod."github.com/benpate/rosetta"]
+    version = "v0.21.0"
+    hash = "sha256-sM1Sgfs4+7Wuyf7T8QfftWTwM7SK/1s9tEg/3tb/RS8="
+  [mod."github.com/crewjam/csp"]
+    version = "v0.0.2"
+    hash = "sha256-4vlGmDdQjPiXmueCV51fJH/hRcG8eqhCi9TENCXjzfA="
+  [mod."github.com/deckarep/golang-set/v2"]
+    version = "v2.6.0"
+    hash = "sha256-ni1XK75Q8iBBmxgoyZTedP4RmrUPzFC4978xB4HKdfs="
+  [mod."github.com/fatih/structtag"]
+    version = "v1.2.0"
+    hash = "sha256-Y2pjiEmMsxfUH8LONU2/f8k1BibOHeLKJmi4uZm/SSU="
+  [mod."github.com/fsnotify/fsnotify"]
+    version = "v1.7.0"
+    hash = "sha256-MdT2rQyQHspPJcx6n9ozkLbsktIOJutOqDuKpNAtoZY="
+  [mod."github.com/golang/groupcache"]
+    version = "v0.0.0-20210331224755-41bb18bfe9da"
+    hash = "sha256-7Gs7CS9gEYZkbu5P4hqPGBpeGZWC64VDwraSKFF+VR0="
+  [mod."github.com/gorilla/css"]
+    version = "v1.0.1"
+    hash = "sha256-6JwNHqlY2NpZ0pSQTyYPSpiNqjXOdFHqrUT10sv3y8A="
+  [mod."github.com/microcosm-cc/bluemonday"]
+    version = "v1.0.26"
+    hash = "sha256-ZX4QUWHVEoGBeTHfPcLD5XoiubeO8GhkdqkC4Me8nRE="
+  [mod."github.com/osdevisnot/sorvor"]
+    version = "v0.4.4"
+    hash = "sha256-BhyO7bvwxIdEV+c6Eo1uqahhcgsHiS8nJpg2aT8t+8s="
+  [mod."github.com/otiai10/copy"]
+    version = "v1.14.0"
+    hash = "sha256-xsaL1ddkPS544y0Jv7u/INUALBYmYq29ddWvysLXk4A="
+  [mod."github.com/pkg/errors"]
+    version = "v0.9.1"
+    hash = "sha256-mNfQtcrQmu3sNg/7IwiieKWOgFQOVVe2yXgKBpe/wZw="
+  [mod."github.com/snabb/diagio"]
+    version = "v1.0.4"
+    hash = "sha256-H2eGPSXv1mpjDSg0ZDNUr6qRouXZhemE7yvbMSLFlw4="
+  [mod."github.com/snabb/sitemap"]
+    version = "v1.0.4"
+    hash = "sha256-5eq8xuyK3H+IhjkHRFdGrmWyUMxzDA7DEwCmqt8zmgc="
+  [mod."github.com/stefanfritsch/goldmark-fences"]
+    version = "v1.0.0"
+    hash = "sha256-Ei+FLtzyHEqz/ZUwHqtQMKHawglcHqcdXmIa8PLvqtc="
+  [mod."github.com/sykesm/zap-logfmt"]
+    version = "v0.0.4"
+    hash = "sha256-KXVFtOU54chusK8AhZrzrvbbNmzq1mNrhs/7OmO+huE="
+  [mod."github.com/thessem/zap-prettyconsole"]
+    version = "v0.4.0"
+    hash = "sha256-SLpCM1OUiLalSwpO9esXMRjExxEL3V875yxsr3MV/LI="
+  [mod."github.com/yuin/goldmark"]
+    version = "v1.7.1"
+    hash = "sha256-3EUgwoZRRs2jNBWSbB0DGNmfBvx7CeAgEwyUdaRaeR4="
+  [mod."go.uber.org/multierr"]
+    version = "v1.11.0"
+    hash = "sha256-Lb6rHHfR62Ozg2j2JZy3MKOMKdsfzd1IYTR57r3Mhp0="
+  [mod."go.uber.org/zap"]
+    version = "v1.27.0"
+    hash = "sha256-8655KDrulc4Das3VRduO9MjCn8ZYD5WkULjCvruaYsU="
+  [mod."golang.org/x/net"]
+    version = "v0.25.0"
+    hash = "sha256-IjFfXLYNj27WLF7vpkZ6mfFXBnp+7QER3OQ0RgjxN54="
+  [mod."golang.org/x/sync"]
+    version = "v0.7.0"
+    hash = "sha256-2ETllEu2GDWoOd/yMkOkLC2hWBpKzbVZ8LhjLu0d2A8="
+  [mod."golang.org/x/sys"]
+    version = "v0.20.0"
+    hash = "sha256-mowlaoG2k4n1c1rApWef5EMiXd3I77CsUi8jPh6pTYA="
+  [mod."golang.org/x/text"]
+    version = "v0.15.0"
+    hash = "sha256-pBnj0AEkfkvZf+3bN7h6epCD2kurw59clDP7yWvxKlk="
+  [mod."gopkg.in/yaml.v2"]
+    version = "v2.4.0"
+    hash = "sha256-uVEGglIedjOIGZzHW4YwN1VoRSTK8o0eGZqzd+TNdd0="