diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7b690b9..673faaa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,6 +50,20 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Install Nix + if: hashFiles('flake.nix') != '' + uses: cachix/install-nix-action@v31 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Flake schema check + if: hashFiles('flake.nix') != '' + run: nix flake check --no-build + + - name: Nix build package + if: hashFiles('flake.nix') != '' + run: nix build + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v6 with: diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ab1e40e --- /dev/null +++ b/flake.nix @@ -0,0 +1,47 @@ +{ + description = "Lightweight, headless implementation of the KDE Connect protocol in Go"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + packages.default = pkgs.buildGoModule { + pname = "kcd"; + version = self.shortRev or "dirty"; + + src = ./.; + + # Update when go.sum changes: nix build 2>&1 | grep 'got:' | awk '{print $2}' + vendorHash = "sha256-rnI60JzB8vtFC4iIVoHGi9um7f0mV7jbIJTNVu8ytVY="; + + subPackages = [ "cmd/kcd" ]; + + env.CGO_ENABLED = "0"; + + ldflags = [ + "-s" "-w" + "-X main.version=${self.shortRev or "dirty"}" + ]; + + meta = with pkgs.lib; { + description = "Headless KDE Connect daemon written in Go"; + homepage = "https://github.com/bethropolis/kcd"; + license = licenses.mit; + maintainers = [ ]; + platforms = platforms.linux; + }; + }; + + apps.default = flake-utils.lib.mkApp { + drv = self.packages.${system}.default; + }; + } + ); +}