diff options
Diffstat (limited to 'nix')
-rw-r--r-- | nix/default.nix | 102 | ||||
-rw-r--r-- | nix/gomod2nix.toml | 118 |
2 files changed, 220 insertions, 0 deletions
diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..de427db --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,102 @@ +{ 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 = [ + (pkgs.writeTextDir "config.toml" (builtins.readFile ./../config.toml)) + 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/website + ''; + 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..16365cd --- /dev/null +++ b/nix/gomod2nix.toml @@ -0,0 +1,118 @@ +schema = 3 + +[mod] + [mod."github.com/BurntSushi/toml"] + version = "v1.3.2" + hash = "sha256-FIwyH67KryRWI9Bk4R8s1zFP0IgKR4L66wNQJYQZLeg=" + [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/antage/eventsource"] + version = "v0.0.0-20220422142129-c4aae935d5bd" + hash = "sha256-5JLLEwW3L3Mt756q3Qw0TKtrNjQ3VtEsV9S2JfdPHy0=" + [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/bep/godartsass"] + version = "v1.2.0" + hash = "sha256-kkKRFesHX8Yp1+/L7yFeRqltBRlAVKgdSN4d7Lc/uI8=" + [mod."github.com/bep/godartsass/v2"] + version = "v2.0.0" + hash = "sha256-ISvlb0UVikyLGPCrkQus//HVgAcgplQDhdIuTrmToRM=" + [mod."github.com/bep/golibsass"] + version = "v1.1.1" + hash = "sha256-rQK/w54sh57GtCG8plKbkFxWBZB0+7RLMvOGCV2jvqY=" + [mod."github.com/cli/safeexec"] + version = "v1.0.1" + hash = "sha256-74r/MHyMIxDSGA2D862d/OQ3lYLozxoUIRMyL0n03m8=" + [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/getsentry/sentry-go"] + version = "v0.27.0" + hash = "sha256-PTkTzVNogqFA/5rc6INLY6RxK5uR1AoJFOO+pOPdE7Q=" + [mod."github.com/gobwas/glob"] + version = "v0.2.3" + hash = "sha256-hYHMUdwxVkMOjSKjR7UWO0D0juHdI4wL8JEy5plu/Jc=" + [mod."github.com/gohugoio/hugo"] + version = "v0.125.7" + hash = "sha256-9Nvtpu6G50GAFKH/XYZq0zrr3+eQNfMVQVafJI2hOFI=" + [mod."github.com/golang/groupcache"] + version = "v0.0.0-20210331224755-41bb18bfe9da" + hash = "sha256-7Gs7CS9gEYZkbu5P4hqPGBpeGZWC64VDwraSKFF+VR0=" + [mod."github.com/mattn/go-isatty"] + version = "v0.0.20" + hash = "sha256-qhw9hWtU5wnyFyuMbKx+7RB8ckQaFQ8D+8GKPkN3HHQ=" + [mod."github.com/mitchellh/hashstructure"] + version = "v1.1.0" + hash = "sha256-dNPVpLRsCa2XZHlCRRtkpBVqb8rpHIocpFPNCqZg2EY=" + [mod."github.com/otiai10/copy"] + version = "v1.14.0" + hash = "sha256-xsaL1ddkPS544y0Jv7u/INUALBYmYq29ddWvysLXk4A=" + [mod."github.com/pelletier/go-toml/v2"] + version = "v2.2.2" + hash = "sha256-ukxk1Cfm6cQW18g/aa19tLcUu5BnF7VmfAvrDHAOl6A=" + [mod."github.com/pkg/errors"] + version = "v0.9.1" + hash = "sha256-mNfQtcrQmu3sNg/7IwiieKWOgFQOVVe2yXgKBpe/wZw=" + [mod."github.com/shengyanli1982/law"] + version = "v0.1.15" + hash = "sha256-Z5G3PtR7V0d04MN+kBge33Pv6VDjJryx+N7JGJkzfLQ=" + [mod."github.com/spf13/afero"] + version = "v1.11.0" + hash = "sha256-+rV3cDZr13N8E0rJ7iHmwsKYKH+EhV+IXBut+JbBiIE=" + [mod."github.com/spf13/cast"] + version = "v1.6.0" + hash = "sha256-hxioqRZfXE0AE5099wmn3YG0AZF8Wda2EB4c7zHF6zI=" + [mod."github.com/tdewolff/parse/v2"] + version = "v2.7.14" + hash = "sha256-DYhy4Uvs0/WdlRGputUQkduuHMzBpEWTMF4bMkJ57qo=" + [mod."github.com/yuin/goldmark"] + version = "v1.7.1" + hash = "sha256-3EUgwoZRRs2jNBWSbB0DGNmfBvx7CeAgEwyUdaRaeR4=" + [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."google.golang.org/protobuf"] + version = "v1.34.1" + hash = "sha256-qnHqY6KLZiZDbTVTN6uzF4jedxROYlPCYHoiv6XI0sc=" + [mod."gopkg.in/check.v1"] + version = "v1.0.0-20201130134442-10cb98267c6c" + hash = "sha256-VlIpM2r/OD+kkyItn6vW35dyc0rtkJufA93rjFyzncs=" + [mod."gopkg.in/yaml.v2"] + version = "v2.4.0" + hash = "sha256-uVEGglIedjOIGZzHW4YwN1VoRSTK8o0eGZqzd+TNdd0=" |