From 8a5d1285f8642e36115fd4f06cfec6f41380c116 Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Sun, 21 Sep 2025 17:06:00 -0400 Subject: [PATCH 1/2] build vendored tarball with nix --- flake.nix | 73 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index 314d4f1..ec4e7d2 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,7 @@ nixpkgs, }: let + pname = "drasl"; version = let buildConfig = builtins.readFile ./build_config.go; @@ -51,40 +52,49 @@ packages = forAllSystems ( system: let - buildDrasl = + npmDeps = pkgs: let nodejs = pkgs.nodejs_20; - npmDeps = pkgs.importNpmLock.buildNodeModules { - inherit nodejs; - npmRoot = ./.; - }; in + pkgs.importNpmLock.buildNodeModules { + inherit nodejs; + npmRoot = ./.; + }; + + nativeBuildInputs = + pkgs: with pkgs; [ + nodejs + go-swag + ]; + + # Update whenever Go dependencies change + vendorHash = "sha256-4Rk59bnDFYpraoGvkBUW6Z5fiXUmm2RLwS1wxScWAMQ="; + + preBuild = pkgs: '' + ln -s ${npmDeps pkgs}/node_modules . + make -o npm-install prebuild + ''; + + buildDrasl = + pkgs: pkgs.buildGoModule { - pname = "drasl"; + inherit pname; inherit version; - src = ./.; - nativeBuildInputs = with pkgs; [ - nodejs - go-swag - ]; + nativeBuildInputs = nativeBuildInputs pkgs; - # Update whenever Go dependencies change - vendorHash = "sha256-4Rk59bnDFYpraoGvkBUW6Z5fiXUmm2RLwS1wxScWAMQ="; + inherit vendorHash; outputs = [ "out" ]; + preBuild = preBuild pkgs; + preConfigure = '' substituteInPlace build_config.go --replace-fail "\"/usr/share/drasl\"" "\"$out/share/drasl\"" ''; - preBuild = '' - ln -s ${npmDeps}/node_modules . - make -o npm-install prebuild - ''; - postInstall = '' mkdir -p "$out/share/drasl" cp -R ./{assets,view,public,locales} "$out/share/drasl" @@ -98,6 +108,30 @@ contents = with pkgs; [ cacert ]; config.Cmd = [ "${buildDrasl pkgs}/bin/drasl" ]; }; + + buildVendoredTarball = + pkgs: + pkgs.buildGoModule { + inherit pname; + inherit version; + src = ./.; + + nativeBuildInputs = nativeBuildInputs pkgs; + + inherit vendorHash; + + outputs = [ "out" ]; + + buildPhase = preBuild pkgs; + + doCheck = false; + + installPhase = '' + tar -cJf "$out" --exclude node_modules --transform "s|^|$pname-$version/|" . + ''; + + dontFixup = true; + }; in rec { drasl = buildDrasl nixpkgsFor.${system}; @@ -113,6 +147,9 @@ # oci-cross-x86_64-darwin = buildOCIImage nixpkgsCross.${system}.x86_64-darwin; oci-cross-aarch64-linux = buildOCIImage nixpkgsCross.${system}.aarch64-linux; # oci-cross-aarch64-darwin = buildOCIImage nixpkgsCross.${system}.aarch64-darwin; + + vendored-tarball = buildVendoredTarball nixpkgsFor.${system}; + vendored-tarball-filename = "${vendored-tarball.pname}-${vendored-tarball.version}-vendored.tar.xz"; } ); From 568650fbb687756d7dc07067ef4e5f40eabad2f0 Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 27 Aug 2025 06:12:12 +0000 Subject: [PATCH 2/2] Add release workflow --- .github/workflows/release.yml | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6ecffe6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v5 + - uses: cachix/install-nix-action@v31 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + + - uses: DeterminateSystems/magic-nix-cache-action@main + + - id: filenames + run: echo VENDORED_TARBALL="$(nix eval --raw .#packages.x86_64-linux.vendored-tarball-filename)" >> "$GITHUB_OUTPUT" + + - run: | + nix build .#vendored-tarball + ln -s result "${{ steps.filenames.outputs.VENDORED_TARBALL }}" + + - name: Create GitHub Release (Draft) + uses: softprops/action-gh-release@v2 + with: + draft: true + tag_name: ${{ github.ref_name }} + files: ${{ steps.filenames.outputs.VENDORED_TARBALL }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}