diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000..4df0d4a --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,28 @@ +name: nix +on: [push] + +jobs: + update-vendor-sha: + name: vendor-sha + runs-on: ubuntu-latest + steps: + + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Install nix + uses: cachix/install-nix-action@v17 + with: + extra_nix_config: | + experimental-features = nix-command flakes + nix_path: nixpkgs=channel:nixos-unstable + + - name: Update packwiz version + run: nix run nixpkgs#nix-prefetch ./nix/prefetcher.nix | tee ./nix/vendor-sha256 + + - name: Commit + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "chore: update packwiz vendorSha256" + branch: master + diff --git a/.gitignore b/.gitignore index 8f45bb6..b4ef2b5 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,7 @@ # I use GoLand now .idea/ -dist/ \ No newline at end of file +# Nix build output +result + +dist/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..08a0816 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1655221618, + "narHash": "sha256-ht8HRFthDKzYt+il+sGgkBwrv+Ex2l8jdGVpsrPfFME=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6616de389ed55fba6eeba60377fc04732d5a207c", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..be98b30 --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; + + outputs = { + self, + nixpkgs, + }: + with nixpkgs.lib; let + # List of explicetely unsupported systems + explicitelyUnsupportedSystems = []; + + # Packwiz should support all 64-bit systems supported by go, but nix only + # support strictly less, so all nix-supported systems are included + # (except ones in explicitelyUnsupportedSystems). + supportedSystems = + filter + # Filter out systems that are explicetely supported + (s: ! elem s explicitelyUnsupportedSystems) + # This lists all systems reasonably well-supported by nix + (import "${nixpkgs}/lib/systems/flake-systems.nix" {}); + + # Helper generating outputs for each supported system + forAllSystems = genAttrs supportedSystems; + + # Import nixpkgs' package set for each system. + nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;}); + in { + # Packwiz package + packages = forAllSystems (system: let + pkgs = nixpkgsFor.${system}; + in rec { + packwiz = pkgs.callPackage ./nix { + version = substring 0 8 self.rev or "dirty"; + vendorSha256 = readFile ./nix/vendor-sha256; + buildGoModule = pkgs.buildGo118Module; + }; + # Build packwiz by default when no package name is specified + default = packwiz; + }); + + # This flake's nix code formatter + formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra); + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..f1a8eb9 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,38 @@ +let + # Import nixpkgs if needed + pkgs = import {}; +in + { + lib ? pkgs.lib, + buildGoModule ? pkgs.buildGoModule, + fetchFromGitHub ? pkgs.fetchFromGitHub, + installShellFiles ? pkgs.installShellFiles, + # version and vendorSha256 should be specified by the caller + version ? "latest", + vendorSha256, + }: + buildGoModule rec { + pname = "packwiz"; + inherit version vendorSha256; + + src = ./..; + + nativeBuildInputs = [ + installShellFiles + ]; + + # Install shell completions + postInstall = '' + installShellCompletion --cmd packwiz \ + --bash <($out/bin/packwiz completion bash) \ + --fish <($out/bin/packwiz completion fish) \ + --zsh <($out/bin/packwiz completion zsh) + ''; + + meta = with lib; { + description = "A command line tool for editing and distributing Minecraft modpacks, using a git-friendly TOML format"; + homepage = "https://packwiz.infra.link/"; + license = licenses.mit; + mainProgram = "packwiz"; + }; + } diff --git a/nix/prefetcher.nix b/nix/prefetcher.nix new file mode 100644 index 0000000..3f8fb2d --- /dev/null +++ b/nix/prefetcher.nix @@ -0,0 +1,11 @@ +{ + sha256, + pkgs ? import {}, +}: +pkgs.callPackage (import ./.) { + buildGoModule = pkgs.buildGo118Module; + vendorSha256 = sha256; +} +// { + outputHash = sha256; +} diff --git a/nix/vendor-sha256 b/nix/vendor-sha256 new file mode 100644 index 0000000..f904fc7 --- /dev/null +++ b/nix/vendor-sha256 @@ -0,0 +1 @@ +sha256-M9u7N4IrL0B4pPRQwQG5TlMaGT++w3ZKHZ0RdxEHPKk=