|
| 1 | +{ |
| 2 | + inputs = { |
| 3 | + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
| 4 | + flake-utils.url = "github:numtide/flake-utils"; |
| 5 | + nix-bundle-exe = { |
| 6 | + url = "github:3noch/nix-bundle-exe"; |
| 7 | + flake = false; |
| 8 | + }; |
| 9 | + gomod2nix = { |
| 10 | + url = "github:nix-community/gomod2nix"; |
| 11 | + inputs.nixpkgs.follows = "nixpkgs"; |
| 12 | + inputs.flake-utils.follows = "flake-utils"; |
| 13 | + }; |
| 14 | + }; |
| 15 | + |
| 16 | + outputs = { self, nixpkgs, nix-bundle-exe, gomod2nix, flake-utils }: |
| 17 | + let |
| 18 | + rev = self.shortRev or "dirty"; |
| 19 | + mkApp = drv: { |
| 20 | + type = "app"; |
| 21 | + program = "${drv}/bin/${drv.meta.mainProgram}"; |
| 22 | + }; |
| 23 | + in |
| 24 | + (flake-utils.lib.eachDefaultSystem |
| 25 | + (system: |
| 26 | + let |
| 27 | + pkgs = import nixpkgs { |
| 28 | + inherit system; |
| 29 | + overlays = [ |
| 30 | + (import ./nix/build_overlay.nix) |
| 31 | + gomod2nix.overlays.default |
| 32 | + self.overlay |
| 33 | + ]; |
| 34 | + config = { }; |
| 35 | + }; |
| 36 | + in |
| 37 | + rec { |
| 38 | + packages = pkgs.cronos-matrix // { |
| 39 | + inherit (pkgs) rocksdb; |
| 40 | + }; |
| 41 | + apps = { |
| 42 | + cronosd = mkApp packages.cronosd; |
| 43 | + cronosd-testnet = mkApp packages.cronosd-testnet; |
| 44 | + }; |
| 45 | + defaultPackage = packages.cronosd; |
| 46 | + defaultApp = apps.cronosd; |
| 47 | + devShells = { |
| 48 | + default = pkgs.mkShell { |
| 49 | + buildInputs = [ |
| 50 | + defaultPackage.go |
| 51 | + pkgs.gomod2nix |
| 52 | + ]; |
| 53 | + }; |
| 54 | + rocksdb = pkgs.mkShell { |
| 55 | + buildInputs = [ |
| 56 | + defaultPackage.go |
| 57 | + pkgs.gomod2nix |
| 58 | + pkgs.rocksdb |
| 59 | + ]; |
| 60 | + }; |
| 61 | + }; |
| 62 | + legacyPackages = pkgs; |
| 63 | + } |
| 64 | + ) |
| 65 | + ) // { |
| 66 | + overlay = final: super: { |
| 67 | + go = super.go_1_22; |
| 68 | + bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { }; |
| 69 | + # make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references. |
| 70 | + # reset the ownership and permissions to make the extract result more normal. |
| 71 | + make-tarball = drv: final.runCommand "tarball-${drv.name}" |
| 72 | + { |
| 73 | + nativeBuildInputs = with final.buildPackages; [ gnutar gzip ]; |
| 74 | + } '' |
| 75 | + tar cfv - -C "${drv}" \ |
| 76 | + --owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \ |
| 77 | + | gzip -9 > $out |
| 78 | + ''; |
| 79 | + bundle-win-exe = drv: final.callPackage ./nix/bundle-win-exe.nix { cronosd = drv; }; |
| 80 | + } // (with final; |
| 81 | + let |
| 82 | + matrix = lib.cartesianProductOfSets { |
| 83 | + network = [ "mainnet" "testnet" ]; |
| 84 | + pkgtype = [ |
| 85 | + "nix" # normal nix package |
| 86 | + "bundle" # relocatable bundled package |
| 87 | + "tarball" # tarball of the bundle, for distribution and checksum |
| 88 | + ]; |
| 89 | + }; |
| 90 | + binaries = builtins.listToAttrs (builtins.map |
| 91 | + ({ network, pkgtype }: { |
| 92 | + name = builtins.concatStringsSep "-" ( |
| 93 | + [ "cronosd" ] ++ |
| 94 | + lib.optional (network != "mainnet") network ++ |
| 95 | + lib.optional (pkgtype != "nix") pkgtype |
| 96 | + ); |
| 97 | + value = |
| 98 | + let |
| 99 | + cronosd = callPackage ./. { |
| 100 | + inherit rev network; |
| 101 | + }; |
| 102 | + bundle = |
| 103 | + if stdenv.hostPlatform.isWindows then |
| 104 | + bundle-win-exe cronosd |
| 105 | + else |
| 106 | + bundle-exe cronosd; |
| 107 | + in |
| 108 | + if pkgtype == "bundle" then |
| 109 | + bundle |
| 110 | + else if pkgtype == "tarball" then |
| 111 | + make-tarball bundle |
| 112 | + else |
| 113 | + cronosd; |
| 114 | + }) |
| 115 | + matrix |
| 116 | + ); |
| 117 | + in |
| 118 | + { |
| 119 | + cronos-matrix = binaries; |
| 120 | + } |
| 121 | + ); |
| 122 | + }; |
| 123 | +} |
0 commit comments