ytdl-web/devenv.nix

105 lines
2.8 KiB
Nix

{ pkgs, ... }:
{
# https://devenv.sh/basics/
env.NAME = "ytdl-web";
env.BINARY_OUT = "./out/ytdl-web";
env.VERSION = "1.0.8";
env.VERSION_PKG = "go.fifitido.net/ytdl-web/version";
env.DOCKER_REGISTRY = "git.fifitido.net";
env.DOCKER_ORG = "apps";
env.DOCKER_PLATFORMS = "linux/amd64,linux/arm64";
env.YTDL_ENV = "Development";
# https://devenv.sh/packages/
packages = with pkgs; [
git
air
goreleaser
docker
docker-compose
buildkit
docker-buildx
yt-dlp
];
# https://devenv.sh/scripts/
scripts.deps.exec = "go mod download";
scripts.tidy.exec = "go mod tidy";
scripts.check.exec = "goreleaser check";
scripts.build-id.exec = "git rev-parse --short HEAD";
scripts.build-date.exec = "date -Iseconds";
scripts.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 .
'';
scripts.clean.exec = ''
rm -rf ./dist/ ./out/ ./tmp/
go clean
'';
scripts.release.exec = ''
clean
goreleaser release
docker-build-release
'';
scripts.lint.exec = "trunk check";
scripts.fmt.exec = "trunk fmt";
scripts.docker-image.exec = "echo $DOCKER_REGISTRY/$DOCKER_ORG/$NAME";
scripts.docker-init.exec = ''
docker buildx create \
--name $NAME \
--platform $DOCKER_PLATFORMS
'';
scripts.docker-login.exec = "docker login $DOCKER_REGISTRY";
scripts.docker-build.exec = ''
platform=''${1:-linux}
output=''${2:-type=docker}
docker-init
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" \
--output $output
'';
scripts.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/
pre-commit.hooks.staticcheck.enable = true;
pre-commit.hooks.hadolint.enable = true;
pre-commit.hooks.yamllint.enable = true;
# https://devenv.sh/processes/
processes.web.exec = "air";
# See full reference at https://devenv.sh/reference/options/
}