ytdl-web/nix/devenv.nix

108 lines
2.9 KiB
Nix
Raw Permalink Normal View History

{ pkgs, ... }:
{
# https://devenv.sh/basics/
env.NAME = "ytdl-web";
env.BINARY_OUT = "./out/ytdl-web";
2024-02-17 12:03:46 -05:00
env.VERSION = "v1.2.0";
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
2023-07-12 19:30:56 -04:00
docker-buildx
yt-dlp
cobra-cli
];
# https://devenv.sh/scripts/
scripts.deps.exec = "go mod download";
scripts.tidy.exec = "go mod tidy";
scripts.check.exec = "goreleaser check";
2023-08-12 13:38:58 -04:00
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
'';
2023-08-12 13:46:32 -04:00
scripts.docker-login.exec = "docker login $DOCKER_REGISTRY";
2023-08-12 13:38:58 -04:00
scripts.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 \
2023-08-12 13:38:58 -04:00
--platform $platform \
--builder $NAME \
2023-08-12 13:38:58 -04:00
--build-arg VERSION=$VERSION \
--build-arg BUILD=$(build-id) \
--build-arg BUILD_DATE=$(build-date) \
2023-08-14 19:26:48 -04:00
--build-arg BUILT_BY="Devenv Script" \
--progress plain \
2023-08-12 13:38:58 -04:00
--output $output
'';
2023-08-12 13:38:58 -04:00
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/
}