git.delta.rocks / jrsonnet / refs/commits / 80f6128c09ce

difftreelog

source

flake.nix17.0 KiBsourcehistory
1{2  description = "Jrsonnet";3  inputs = {4    nixpkgs.url = "github:nixos/nixpkgs/release-25.11";5    fenix = {6      url = "github:CertainLach/fenix/fix/libatomic";7      inputs.nixpkgs.follows = "nixpkgs";8    };9    flake-parts = {10      url = "github:hercules-ci/flake-parts";11      inputs.nixpkgs-lib.follows = "nixpkgs";12    };13    hercules-ci-effects = {14      url = "github:hercules-ci/hercules-ci-effects";15      inputs.flake-parts.follows = "flake-parts";16      inputs.nixpkgs.follows = "nixpkgs";17    };18    treefmt-nix = {19      url = "github:numtide/treefmt-nix";20      inputs.nixpkgs.follows = "nixpkgs";21    };22    crane.url = "github:ipetkov/crane";23    shelly.url = "github:CertainLach/shelly";2425    cpp-jsonnet-for-tests = {26      url = "github:google/jsonnet";27      flake = false;28    };29    go-jsonnet-for-tests = {30      url = "github:google/go-jsonnet";31      flake = false;32    };33  };34  outputs =35    inputs:36    let37      inherit (inputs.nixpkgs.lib)38        mkIf39        mkForce40        optionals41        optionalAttrs42        concatMapStringsSep43        ;44      rel = system: inputs.self.legacyPackages.${system}.release;45      releaseSections = [46        {47          name = "Linux (glibc)";48          artifacts = [49            {50              label = "jrsonnet-x86_64-linux-glibc";51              drv = (rel "x86_64-linux").jrsonnet-linux-glibc;52            }53            {54              label = "jrsonnet-experimental-x86_64-linux-glibc";55              drv = (rel "x86_64-linux").jrsonnet-experimental-linux-glibc;56            }57            {58              label = "jrsonnet-aarch64-linux-glibc";59              drv = (rel "aarch64-linux").jrsonnet-linux-glibc;60            }61            {62              label = "jrsonnet-experimental-aarch64-linux-glibc";63              drv = (rel "aarch64-linux").jrsonnet-experimental-linux-glibc;64            }65            {66              label = "jrsonnet-i686-linux-glibc";67              drv = (rel "i686-linux").jrsonnet-linux-glibc;68            }69            {70              label = "jrsonnet-experimental-i686-linux-glibc";71              drv = (rel "i686-linux").jrsonnet-experimental-linux-glibc;72            }73            {74              label = "jrsonnet-armv7l-linux-glibc";75              drv = (rel "armv7l-linux").jrsonnet-linux-glibc;76            }77            {78              label = "jrsonnet-experimental-armv7l-linux-glibc";79              drv = (rel "armv7l-linux").jrsonnet-experimental-linux-glibc;80            }81          ];82        }83        {84          name = "Linux (musl)";85          artifacts = [86            {87              label = "jrsonnet-x86_64-linux-musl";88              drv = (rel "x86_64-linux").jrsonnet-linux-musl;89            }90            {91              label = "jrsonnet-experimental-x86_64-linux-musl";92              drv = (rel "x86_64-linux").jrsonnet-experimental-linux-musl;93            }94            {95              label = "jrsonnet-aarch64-linux-musl";96              drv = (rel "aarch64-linux").jrsonnet-linux-musl;97            }98            {99              label = "jrsonnet-experimental-aarch64-linux-musl";100              drv = (rel "aarch64-linux").jrsonnet-experimental-linux-musl;101            }102          ];103        }104        {105          name = "macOS";106          artifacts = [107            {108              label = "jrsonnet-aarch64-darwin";109              drv = (rel "aarch64-linux").jrsonnet-darwin;110            }111            {112              label = "jrsonnet-experimental-aarch64-darwin";113              drv = (rel "aarch64-linux").jrsonnet-experimental-darwin;114            }115          ];116        }117        {118          name = "Windows";119          artifacts = [120            {121              label = "jrsonnet-x86_64-windows";122              drv = (rel "x86_64-linux").jrsonnet-windows;123              windows = true;124            }125            {126              label = "jrsonnet-experimental-x86_64-windows";127              drv = (rel "x86_64-linux").jrsonnet-experimental-windows;128              windows = true;129            }130          ];131        }132      ];133      releaseArtifacts = builtins.concatMap (s: s.artifacts) releaseSections;134    in135    inputs.flake-parts.lib.mkFlake { inherit inputs; } {136      imports = [137        inputs.shelly.flakeModule138        inputs.hercules-ci-effects.flakeModule139        ./nix/post-comment.nix140      ];141      systems = [142        "x86_64-linux"143        "i686-linux"144        "aarch64-linux"145        "armv7l-linux"146        "aarch64-darwin"147      ];148      perSystem =149        {150          config,151          self',152          system,153          ...154        }:155        let156          pkgs = import inputs.nixpkgs {157            inherit system;158            overlays = [ inputs.fenix.overlays.default ];159            config.allowUnsupportedSystem = true;160            config.allowUnfreePredicate = pkg: pkg.name == "Xcode.app";161          };162          targetArch = pkgs.stdenv.hostPlatform.parsed.cpu.name;163          rustfmt = (pkgs.fenix.complete or pkgs.fenix.stable).rustfmt;164          toolchain = pkgs.fenix.combine [165            (pkgs.fenix.stable.withComponents [166              "cargo"167              "clippy"168              "rustc"169              "rustfmt"170            ])171            pkgs.fenix.targets.wasm32-unknown-unknown.stable.rust-std172          ];173          devToolchain = pkgs.fenix.combine [174            ((pkgs.fenix.complete or pkgs.fenix.stable).withComponents [175              "cargo"176              "clippy"177              "rustc"178              "rust-src"179              "rustfmt"180              "rust-analyzer"181            ])182            pkgs.fenix.targets.wasm32-unknown-unknown.latest.rust-std183          ];184          craneLib = (inputs.crane.mkLib pkgs).overrideToolchain toolchain;185          craneLibDev = (inputs.crane.mkLib pkgs).overrideToolchain devToolchain;186          treefmt =187            (inputs.treefmt-nix.lib.evalModule pkgs (import ./treefmt.nix { inherit rustfmt; })).config.build;188189          # Cross-compilation toolchains190          crossToolchain = pkgs.fenix.combine [191            (pkgs.fenix.stable.withComponents [192              "cargo"193              "rustc"194            ])195            pkgs.fenix.targets."${targetArch}-unknown-linux-musl".stable.rust-std196            pkgs.fenix.targets."${targetArch}-apple-darwin".stable.rust-std197          ];198          craneLibCross = (inputs.crane.mkLib pkgs).overrideToolchain crossToolchain;199200          # Windows cross-compilation201          pkgsWindows = import inputs.nixpkgs {202            overlays = [ inputs.fenix.overlays.default ];203            localSystem = system;204            crossSystem = {205              config = "${targetArch}-w64-mingw32";206              libc = "msvcrt";207            };208          };209          windowsToolchain = pkgs.fenix.combine [210            (pkgs.fenix.stable.withComponents [211              "cargo"212              "rustc"213            ])214            pkgs.fenix.targets."${targetArch}-pc-windows-gnu".stable.rust-std215          ];216          craneLibWindows = (inputs.crane.mkLib pkgsWindows).overrideToolchain (_: windowsToolchain);217218        in219        {220          legacyPackages = {221            fetchJrq = pkgs.callPackage ./nix/fetch-jrq.nix {222              inherit (self'.packages) jrsonnet;223            };224            release = optionalAttrs pkgs.stdenv.hostPlatform.isLinux (225              {226                jrsonnet-linux-glibc = self'.packages.jrsonnet;227                jrsonnet-experimental-linux-glibc = self'.packages.jrsonnet-experimental;228              }229              // optionalAttrs pkgs.stdenv.hostPlatform.is64bit rec {230                jrsonnet-linux-musl = pkgs.callPackage ./nix/jrsonnet-cross-musl.nix {231                  craneLib = craneLibCross;232                  targetTriple = "${targetArch}-unknown-linux-musl";233                  muslCC = pkgs.pkgsMusl.stdenv.cc;234                };235                jrsonnet-experimental-linux-musl = jrsonnet-linux-musl.override {236                  withExperimentalFeatures = true;237                };238              }239              // optionalAttrs (targetArch == "aarch64") rec {240                jrsonnet-darwin = pkgs.callPackage ./nix/jrsonnet-cross-darwin.nix {241                  craneLib = craneLibCross;242                  targetTriple = "${targetArch}-apple-darwin";243                };244                jrsonnet-experimental-darwin = jrsonnet-darwin.override {245                  withExperimentalFeatures = true;246                };247              }248              // optionalAttrs (targetArch == "x86_64") rec {249                jrsonnet-windows = pkgsWindows.callPackage ./nix/jrsonnet-cross-windows.nix {250                  craneLib = craneLibWindows;251                  targetTriple = "${targetArch}-pc-windows-gnu";252                };253                jrsonnet-experimental-windows = jrsonnet-windows.override {254                  withExperimentalFeatures = true;255                };256              }257            );258            benchmarks = optionalAttrs (system == "x86_64-linux" || system == "aarch64-linux") {259              default = pkgs.callPackage ./nix/benchmarks.nix {260                inherit (config.legacyPackages) fetchJrq;261                inherit (config.legacyPackages.jsonnetImpls)262                  go-jsonnet263                  sjsonnet264                  cpp-jsonnet265                  rsjsonnet266                  ;267                jrsonnetVariants = [268                  {269                    drv = self'.packages.jrsonnet.override { forBenchmarks = true; };270                    name = "";271                  }272                ];273              };274              quick = pkgs.callPackage ./nix/benchmarks.nix {275                inherit (config.legacyPackages) fetchJrq;276                inherit (config.legacyPackages.jsonnetImpls)277                  go-jsonnet278                  sjsonnet279                  cpp-jsonnet280                  rsjsonnet281                  ;282                quick = true;283                jrsonnetVariants = [284                  {285                    drv = self'.packages.jrsonnet.override { forBenchmarks = true; };286                    name = "";287                  }288                ];289              };290              against-release = pkgs.callPackage ./nix/benchmarks.nix {291                inherit (config.legacyPackages) fetchJrq;292                inherit (config.legacyPackages.jsonnetImpls)293                  go-jsonnet294                  sjsonnet295                  cpp-jsonnet296                  rsjsonnet297                  ;298                jrsonnetVariants = [299                  {300                    drv = self'.packages.jrsonnet.override { forBenchmarks = true; };301                    name = "current";302                  }303                  {304                    drv = self'.packages.jrsonnet-experimental.override { forBenchmarks = true; };305                    name = "current-experimental";306                  }307                  {308                    drv = self'.legacyPackages.jsonnetImpls.jrsonnet-release.override { forBenchmarks = true; };309                    name = "release";310                  }311                ];312              };313              quick-against-release = pkgs.callPackage ./nix/benchmarks.nix {314                inherit (config.legacyPackages) fetchJrq;315                inherit (config.legacyPackages.jsonnetImpls)316                  go-jsonnet317                  sjsonnet318                  cpp-jsonnet319                  rsjsonnet320                  ;321                quick = true;322                jrsonnetVariants = [323                  {324                    drv = self'.packages.jrsonnet.override { forBenchmarks = true; };325                    name = "current";326                  }327                  {328                    drv = self'.packages.jrsonnet-experimental.override { forBenchmarks = true; };329                    name = "current-experimental";330                  }331                  {332                    drv = self'.legacyPackages.jsonnetImpls.jrsonnet-release.override { forBenchmarks = true; };333                    name = "release";334                  }335                ];336              };337            };338            jsonnetImpls = {339              go-jsonnet = pkgs.callPackage ./nix/go-jsonnet.nix { };340              sjsonnet = pkgs.callPackage ./nix/sjsonnet.nix { };341              cpp-jsonnet = pkgs.callPackage ./nix/cpp-jsonnet.nix { };342              # I didn't managed to build it, and nixpkgs version is marked as broken343              # haskell-jsonnet = pkgs.callPackage ./nix/haskell-jsonnet.nix { };344              rsjsonnet = pkgs.callPackage ./nix/rsjsonnet.nix { };345              # Older released version of jrsonnet itself, for benchmarking purposes346              jrsonnet-release = pkgs.callPackage ./nix/jrsonnet-release.nix {347                rustPlatform = pkgs.makeRustPlatform {348                  rustc = toolchain;349                  cargo = toolchain;350                };351              };352            };353          };354          packages =355            let356              jrsonnet = pkgs.callPackage ./nix/jrsonnet.nix {357                inherit craneLib;358                inherit (inputs) cpp-jsonnet-for-tests go-jsonnet-for-tests;359              };360              jrsonnet-experimental = pkgs.callPackage ./nix/jrsonnet.nix {361                inherit craneLib;362                inherit (inputs) cpp-jsonnet-for-tests go-jsonnet-for-tests;363                withExperimentalFeatures = true;364              };365            in366            {367              default = jrsonnet;368              inherit jrsonnet jrsonnet-experimental;369            };370          checks = optionalAttrs (system != "armv7l-linux") {371            formatting = treefmt.check inputs.self;372          };373          formatter = mkIf (system != "armv7l-linux") treefmt.wrapper;374          shelly.shells.default = {375            factory = craneLibDev.devShell;376            packages =377              with pkgs;378              [379                cargo-edit380                cargo-outdated381                cargo-watch382                cargo-insta383                cargo-hack384                cargo-show-asm385                lld386                hyperfine387                graphviz388              ]389              ++ optionals (!stdenv.isDarwin) [390                valgrind391                kdePackages.kcachegrind392                samply393              ];394            environment = {395              CPP_JSONNET_FOR_TESTS = inputs.cpp-jsonnet-for-tests;396              GO_JSONNET_FOR_TESTS = inputs.go-jsonnet-for-tests;397            };398          };399          shelly.shells.impls = {400            packages =401              (with self'.legacyPackages.jsonnetImpls; [402                cpp-jsonnet403                go-jsonnet404                rsjsonnet405                sjsonnet406              ])407              ++ (with self'.packages; [408                jrsonnet409              ]);410          };411        };412      hercules-ci.github-releases.files = map (a: {413        label = a.label + (if a.windows or false then ".exe" else "");414        path = "${a.drv}/bin/jrsonnet${if a.windows or false then ".exe" else ""}";415      }) releaseArtifacts;416      hercules-ci.cargo-publish = {417        enable = true;418        secretName = "crates-io";419        extraPublishArgs = [ "--workspace" ];420        assertVersions = true;421      };422      hercules-ci.flake-update = {423        enable = true;424        baseMerge.enable = true;425        baseMerge.method = "fast-forward";426        when = {427          dayOfWeek = [ "Sat" ];428        };429      };430      hercules-ci.post-comment = {431        enable = true;432        caches = [ "jrsonnet.cachix.org" ];433        script =434          let435            benchmarks = inputs.self.legacyPackages.x86_64-linux.benchmarks.default;436            renderSection = s: ''437              echo438              echo "### ${s.name}"439              echo440              ${concatMapStringsSep "\n" (a: ''echo "- [${a.label}]($(nixTar ${a.drv}))"'') s.artifacts}441            '';442          in443          ''444            {445              echo "## Benchmark results"446              echo447              echo "[View rendered]($(nixRender ${benchmarks}))"448              echo449              echo "## Downloads"450              ${concatMapStringsSep "\n" renderSection releaseSections}451            } > $out452          '';453      };454      herculesCI =455        { lib, config, ... }:456        {457          ciSystems = [458            "x86_64-linux"459            "i686-linux"460            "aarch64-linux"461            "armv7l-linux"462            # TODO: add workers for these platforms463            # "aarch64-darwin"464          ];465          onPush.default.outputs = {466            benchmarks.x86_64-linux = inputs.self.legacyPackages.x86_64-linux.benchmarks.default;467468            # Cross: musl/mingw/darwin-zigbuild469            release.x86_64-linux = inputs.self.legacyPackages.x86_64-linux.release;470            release.aarch64-linux = inputs.self.legacyPackages.aarch64-linux.release;471            release.armv7l-linux = inputs.self.legacyPackages.armv7l-linux.release;472            release.i686-linux = inputs.self.legacyPackages.i686-linux.release;473474            # Too much to build for CI purposes475            devShells = mkForce { };476            formatter = mkForce { };477478            # No need to run them on different arch, pretty large derivations and might try to compile GHC479            checks.i686-linux.formatting = mkForce { };480            checks.aarch64-linux.formatting = mkForce { };481          };482        };483    };484}