diff options
Diffstat (limited to 'default.nix')
-rw-r--r-- | default.nix | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/default.nix b/default.nix index b05d12e..4c29731 100644 --- a/default.nix +++ b/default.nix @@ -14,6 +14,27 @@ let runCommandLocal; version = "unstable"; + mkDocker = type: { server, website }: + let + PORT = 80; + in + pkgs.dockerTools.${type} { + name = "registry.fly.io/alanpearce-eu"; + config = { + Cmd = [ "${server}/bin/server" ]; + Env = [ + "PRODUCTION=true" + "LISTEN_ADDRESS=::" + "PORT=${builtins.toString PORT}" + "ROOT=${website}" + ]; + ExposedPorts = { + "${builtins.toString PORT}/tcp" = { }; + }; + }; + }; + mkDockerStream = mkDocker "streamLayeredImage"; + mkDockerImage = mkDocker "buildLayeredImage"; in rec { pre-commit-check = pre-commit-hooks.run { @@ -70,4 +91,49 @@ rec { } '' ${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 = ./nix/gomod2nix.toml; + patchPhase = '' + ${pkgs.templ}/bin/templ generate + ''; + subPackages = [ "cmd/server" ]; + ldflags = [ + "-s" + "-w" + ]; + }; + docker-stream = mkDockerStream { inherit server website; }; + docker-image = mkDockerImage { inherit server website; }; + + server-amd64-linux = server.overrideAttrs (old: old // { + GOOS = "linux"; + GOARCH = "amd64"; + fixupPhase = '' + if [[ -d $out/bin/linux_amd64 ]] + then + mv $out/bin/linux_amd64/server $out/bin/server + rmdir $out/bin/linux_amd64 + fi + ''; + }); + docker-image-amd64-linux = mkDockerImage { + inherit website; + server = server-amd64-linux; + }; + docker-stream-amd64-linux = mkDockerStream { + inherit website; + server = server-amd64-linux; + }; } |