114 lines
2.9 KiB
Nix
114 lines
2.9 KiB
Nix
{ pkgs, lib, config, inputs, ... }:
|
|
|
|
{
|
|
# https://devenv.sh/basics/
|
|
env = {
|
|
NAME = "ytdl-web";
|
|
BINARY_OUT = "./out/ytdl-web";
|
|
VERSION = "v1.2.3";
|
|
VERSION_PKG = "go.fifitido.net/ytdl-web/version";
|
|
DOCKER_REGISTRY = "git.fifitido.net";
|
|
DOCKER_ORG = "apps";
|
|
DOCKER_PLATFORMS = "linux/amd64,linux/arm64";
|
|
|
|
YTDL_ENV = "Development";
|
|
};
|
|
|
|
# https://devenv.sh/packages/
|
|
packages = with pkgs; [
|
|
git
|
|
air
|
|
goreleaser
|
|
docker
|
|
docker-compose
|
|
buildkit
|
|
docker-buildx
|
|
yt-dlp
|
|
cobra-cli
|
|
];
|
|
|
|
# https://devenv.sh/scripts/
|
|
scripts = {
|
|
deps.exec = "go mod download";
|
|
tidy.exec = "go mod tidy";
|
|
check.exec = "goreleaser check";
|
|
|
|
build-id.exec = "git rev-parse --short HEAD";
|
|
build-date.exec = "date -Iseconds";
|
|
|
|
build.exec = ''
|
|
go build -ldflags="
|
|
-X $VERSION_PKG.Version=$VERSION
|
|
-X $VERSION_PKG.Build=$(build-id)
|
|
-X $VERSION_PKG.BuildDate=$(build-date)
|
|
-X $VERSION_PKG.BuiltBy=manual
|
|
" -o $BINARY_OUT .
|
|
'';
|
|
clean.exec = ''
|
|
rm -rf ./dist/ ./out/ ./tmp/
|
|
go clean
|
|
'';
|
|
release.exec = ''
|
|
clean
|
|
goreleaser release
|
|
docker-build-release
|
|
'';
|
|
lint.exec = "trunk check";
|
|
fmt.exec = "trunk fmt";
|
|
|
|
docker-image.exec = "echo $DOCKER_REGISTRY/$DOCKER_ORG/$NAME";
|
|
|
|
docker-init.exec = ''
|
|
docker buildx create \
|
|
--name $NAME \
|
|
--platform $DOCKER_PLATFORMS
|
|
'';
|
|
|
|
docker-login.exec = "docker login $DOCKER_REGISTRY";
|
|
|
|
docker-build.exec = ''
|
|
platform=''${1:-linux}
|
|
output=''${2:-type=docker}
|
|
|
|
docker-init
|
|
PROGRESS_NO_TRUNC=1 docker buildx build . \
|
|
--tag $(docker-image):$VERSION \
|
|
--tag $(docker-image):latest \
|
|
--platform $platform \
|
|
--builder $NAME \
|
|
--build-arg VERSION=$VERSION \
|
|
--build-arg BUILD=$(build-id) \
|
|
--build-arg BUILD_DATE=$(build-date) \
|
|
--build-arg BUILT_BY="Devenv Script" \
|
|
--progress plain \
|
|
--output $output
|
|
'';
|
|
|
|
docker-build-release.exec = "docker-build $DOCKER_PLATFORMS type=image,push=true";
|
|
};
|
|
|
|
enterShell = ''
|
|
echo "Welcome to the $NAME development environment."
|
|
echo -n "Golang version: $(go version | cut -d ' ' -f 3), "
|
|
echo -n "Goreleaser version: $(goreleaser --version | tail -n 9 | head -n 1 | cut -c 16-), "
|
|
echo -n "Docker CLI version: $(docker version -f {{.Client.Version}}), "
|
|
echo -n "Buildx version: $(docker buildx version | cut -d ' ' -f 2), "
|
|
echo "yt-dlp version: $(yt-dlp --version)"
|
|
'';
|
|
|
|
# https://devenv.sh/languages/
|
|
languages.go.enable = true;
|
|
|
|
# https://devenv.sh/pre-commit-hooks/
|
|
git-hooks.hooks = {
|
|
staticcheck.enable = true;
|
|
hadolint.enable = true;
|
|
yamllint.enable = true;
|
|
};
|
|
|
|
# https://devenv.sh/processes/
|
|
processes.web.exec = "air";
|
|
|
|
# See full reference at https://devenv.sh/reference/options/
|
|
}
|