diff options
author | Alan Pearce | 2024-04-19 16:11:33 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-19 22:13:42 +0200 |
commit | 30e4cb4e4af3a6eebd3b4fb431828d284a72a10a (patch) | |
tree | ca5ae02e140f9d1b35a9824da04a71e32a981a47 /nix/default.nix | |
parent | 0fc79f324d54cc7a45c0ad0ffa9c75cd716e0126 (diff) | |
download | website-30e4cb4e4af3a6eebd3b4fb431828d284a72a10a.tar.lz website-30e4cb4e4af3a6eebd3b4fb431828d284a72a10a.tar.zst website-30e4cb4e4af3a6eebd3b4fb431828d284a72a10a.zip |
use nix to build docker images
Diffstat (limited to 'nix/default.nix')
-rw-r--r-- | nix/default.nix | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..a04131b --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,71 @@ +{ pkgs, self }: +let + revision = "${self.lastModifiedDate}-${self.shortRev or "dirty"}"; + version = "unstable-${self.shortRev or "dirty"}"; + mkDocker = server: + let + PORT = 3000; + in + pkgs.dockerTools.streamLayeredImage { + name = "registry.fly.io/alanpearce-eu"; + tag = revision; + contents = [ server ]; + config = { + Cmd = [ "website" ]; + Env = [ + "PRODUCTION=true" + "PORT=${builtins.toString PORT}" + "ROOT=public" + ]; + ExposedPorts = { + "${builtins.toString PORT}/tcp" = { }; + }; + }; + }; +in +rec { + default = server; + builder = pkgs.buildGoApplication { + pname = "website-builder"; + inherit version; + src = with pkgs.lib.fileset; toSource { + root = ./..; + fileset = unions [ + ./../go.mod + ./../go.sum + ./../cmd + ./../internal + ]; + }; + modules = ./gomod2nix.toml; + subPackages = [ "cmd/build" ]; + }; + server = pkgs.buildGoApplication { + pname = "website"; + inherit version; + CGO_ENABLED = 0; + src = with pkgs.lib.fileset; toSource { + root = ./..; + fileset = unions [ + ./../go.mod + ./../go.sum + ./../server.go + ./../internal + ./../config.toml + ./../content + ./../static + ./../templates + ]; + }; + buildInputs = [ builder ]; + prePatch = '' + ${builder}/bin/build + ''; + modules = ./gomod2nix.toml; + ldflags = [ "-s" "-w" ]; + }; + docker = mkDocker server; + docker-aarch64-linux = mkDocker (self.packages.aarch64-linux.server); + docker-x86_64-linux = mkDocker (self.packages.x86_64-linux.server); + fly = docker-x86_64-linux; +} |