diff options
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; +} |