create portable service image

Signed-off-by: Xe Iaso <xe@tailscale.com>
This commit is contained in:
Xe Iaso 2023-01-16 16:23:53 +00:00
parent ad516287c4
commit 34bef046bf
2 changed files with 39 additions and 11 deletions

View file

@ -4,7 +4,7 @@
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable"; nixpkgs.url = "nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
gomod2nix = { gomod2nix = {
url = "github:tweag/gomod2nix"; url = "github:tweag/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -28,28 +28,46 @@
in { in {
packages = rec { packages = rec {
web = pkgs.buildGoApplication { web = pkgs.buildGoApplication {
pname = "tailpaste-web"; pname = "infinipaste-web";
version = "0.1.0-dev"; version = "0.1.0-${version}";
src = ./.; src = ./.;
subPackages = "cmd/web"; subPackages = "cmd/web";
modules = ./gomod2nix.toml; modules = ./gomod2nix.toml;
}; };
tailpaste = pkgs.buildGoApplication { infinipaste = pkgs.buildGoApplication {
pname = "tailpaste"; pname = "infinipaste";
inherit (web) src version modules; inherit (web) src version modules;
subPackages = "cmd/tailpaste"; subPackages = "cmd/infinipaste";
CGO_ENABLED = "0"; CGO_ENABLED = "0";
}; };
docker = pkgs.dockerTools.buildLayeredImage { docker = pkgs.dockerTools.buildLayeredImage {
name = "tailpaste"; name = "infinipaste";
tag = "latest"; tag = "latest";
config.Cmd = [ "${web}/bin/web" ]; config.Cmd = [ "${web}/bin/web" ];
contents = [ pkgs.cacert ]; contents = [ pkgs.cacert ];
}; };
portable-service = let
web-service = pkgs.substituteAll {
name = "infinipaste.service";
src = ./run/portable-service/infinipaste.service.in;
infinipaste = web;
};
in pkgs.portableService {
inherit (web) version;
pname = "infinipaste";
description = "The infinipaste service";
homepage = "https://github.com/tailscale-dev/infinipaste";
units = [ web-service ];
symlinks = [{
object = "${pkgs.cacert}/etc/ssl";
symlink = "/etc/ssl";
}];
};
default = docker; default = docker;
}; };
@ -64,12 +82,9 @@
go-tools go-tools
gomod2nix.packages.${system}.default gomod2nix.packages.${system}.default
sqlite-interactive sqlite-interactive
jo
jq
]; ];
TSNET_HOSTNAME = "paste-devel"; TSNET_HOSTNAME = "paste-devel";
}; };
}); }) // {};
} }

View file

@ -0,0 +1,13 @@
[Unit]
Description=The Infinipaste service
Documentation=https://github.com/tailscale-dev/infinipaste
[Service]
DynamicUser=yes
StateDirectory=infinipaste
Environment=DATA_DIR=/var/lib/private/infinipaste/data
WorkingDirectory=/var/lib/private/infinipaste
ExecStart=@web@/bin/web
[Install]
WantedBy=multi-user.target