git.delta.rocks / jrsonnet / refs/commits / db1fd8f12920

difftreelog

source

flake.nix17.1 KiBsourcehistory
1{2  description = "Jrsonnet";3  inputs = {4    nixpkgs.url = "github:nixos/nixpkgs/master";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                  # https://github.com/rust-cross/cargo-zigbuild/issues/433244                  zig = pkgs.zig_0_15;245                };246                jrsonnet-experimental-darwin = jrsonnet-darwin.override {247                  withExperimentalFeatures = true;248                };249              }250              // optionalAttrs (targetArch == "x86_64") rec {251                jrsonnet-windows = pkgsWindows.callPackage ./nix/jrsonnet-cross-windows.nix {252                  craneLib = craneLibWindows;253                  targetTriple = "${targetArch}-pc-windows-gnu";254                };255                jrsonnet-experimental-windows = jrsonnet-windows.override {256                  withExperimentalFeatures = true;257                };258              }259            );260            benchmarks = optionalAttrs (system == "x86_64-linux" || system == "aarch64-linux") {261              default = pkgs.callPackage ./nix/benchmarks.nix {262                inherit (config.legacyPackages) fetchJrq;263                inherit (config.legacyPackages.jsonnetImpls)264                  go-jsonnet265                  sjsonnet266                  cpp-jsonnet267                  rsjsonnet268                  ;269                jrsonnetVariants = [270                  {271                    drv = self'.packages.jrsonnet.override { forBenchmarks = true; };272                    name = "";273                  }274                ];275              };276              quick = pkgs.callPackage ./nix/benchmarks.nix {277                inherit (config.legacyPackages) fetchJrq;278                inherit (config.legacyPackages.jsonnetImpls)279                  go-jsonnet280                  sjsonnet281                  cpp-jsonnet282                  rsjsonnet283                  ;284                quick = true;285                jrsonnetVariants = [286                  {287                    drv = self'.packages.jrsonnet.override { forBenchmarks = true; };288                    name = "";289                  }290                ];291              };292              against-release = pkgs.callPackage ./nix/benchmarks.nix {293                inherit (config.legacyPackages) fetchJrq;294                inherit (config.legacyPackages.jsonnetImpls)295                  go-jsonnet296                  sjsonnet297                  cpp-jsonnet298                  rsjsonnet299                  ;300                jrsonnetVariants = [301                  {302                    drv = self'.packages.jrsonnet.override { forBenchmarks = true; };303                    name = "current";304                  }305                  {306                    drv = self'.packages.jrsonnet-experimental.override { forBenchmarks = true; };307                    name = "current-experimental";308                  }309                  {310                    drv = self'.legacyPackages.jsonnetImpls.jrsonnet-release.override { forBenchmarks = true; };311                    name = "release";312                  }313                ];314              };315              quick-against-release = pkgs.callPackage ./nix/benchmarks.nix {316                inherit (config.legacyPackages) fetchJrq;317                inherit (config.legacyPackages.jsonnetImpls)318                  go-jsonnet319                  sjsonnet320                  cpp-jsonnet321                  rsjsonnet322                  ;323                quick = true;324                jrsonnetVariants = [325                  {326                    drv = self'.packages.jrsonnet.override { forBenchmarks = true; };327                    name = "current";328                  }329                  {330                    drv = self'.packages.jrsonnet-experimental.override { forBenchmarks = true; };331                    name = "current-experimental";332                  }333                  {334                    drv = self'.legacyPackages.jsonnetImpls.jrsonnet-release.override { forBenchmarks = true; };335                    name = "release";336                  }337                ];338              };339            };340            jsonnetImpls = {341              go-jsonnet = pkgs.callPackage ./nix/go-jsonnet.nix { };342              sjsonnet = pkgs.callPackage ./nix/sjsonnet.nix { };343              cpp-jsonnet = pkgs.callPackage ./nix/cpp-jsonnet.nix { };344              # I didn't managed to build it, and nixpkgs version is marked as broken345              # haskell-jsonnet = pkgs.callPackage ./nix/haskell-jsonnet.nix { };346              rsjsonnet = pkgs.callPackage ./nix/rsjsonnet.nix { };347              # Older released version of jrsonnet itself, for benchmarking purposes348              jrsonnet-release = pkgs.callPackage ./nix/jrsonnet-release.nix {349                rustPlatform = pkgs.makeRustPlatform {350                  rustc = toolchain;351                  cargo = toolchain;352                };353              };354            };355          };356          packages =357            let358              jrsonnet = pkgs.callPackage ./nix/jrsonnet.nix {359                inherit craneLib;360                inherit (inputs) cpp-jsonnet-for-tests go-jsonnet-for-tests;361              };362              jrsonnet-experimental = pkgs.callPackage ./nix/jrsonnet.nix {363                inherit craneLib;364                inherit (inputs) cpp-jsonnet-for-tests go-jsonnet-for-tests;365                withExperimentalFeatures = true;366              };367            in368            {369              default = jrsonnet;370              inherit jrsonnet jrsonnet-experimental;371            };372          checks = optionalAttrs (system != "armv7l-linux") {373            formatting = treefmt.check inputs.self;374          };375          formatter = mkIf (system != "armv7l-linux") treefmt.wrapper;376          shelly.shells.default = {377            factory = craneLibDev.devShell;378            packages =379              with pkgs;380              [381                cargo-edit382                cargo-outdated383                cargo-watch384                cargo-insta385                cargo-hack386                cargo-show-asm387                lld388                hyperfine389                graphviz390              ]391              ++ optionals (!stdenv.isDarwin) [392                valgrind393                kdePackages.kcachegrind394                samply395              ];396            environment = {397              CPP_JSONNET_FOR_TESTS = inputs.cpp-jsonnet-for-tests;398              GO_JSONNET_FOR_TESTS = inputs.go-jsonnet-for-tests;399            };400          };401          shelly.shells.impls = {402            packages =403              (with self'.legacyPackages.jsonnetImpls; [404                cpp-jsonnet405                go-jsonnet406                rsjsonnet407                sjsonnet408              ])409              ++ (with self'.packages; [410                jrsonnet411              ]);412          };413        };414      hercules-ci.github-releases.files = map (a: {415        label = a.label + (if a.windows or false then ".exe" else "");416        path = "${a.drv}/bin/jrsonnet${if a.windows or false then ".exe" else ""}";417      }) releaseArtifacts;418      hercules-ci.cargo-publish = {419        enable = true;420        secretName = "crates-io";421        extraPublishArgs = [ "--workspace" ];422        assertVersions = true;423      };424      hercules-ci.flake-update = {425        enable = true;426        baseMerge.enable = true;427        baseMerge.method = "fast-forward";428        when = {429          dayOfWeek = [ "Sat" ];430        };431      };432      hercules-ci.post-comment = {433        enable = true;434        caches = [ "jrsonnet.cachix.org" ];435        script =436          let437            benchmarks = inputs.self.legacyPackages.x86_64-linux.benchmarks.default;438            renderSection = s: ''439              echo440              echo "### ${s.name}"441              echo442              ${concatMapStringsSep "\n" (a: ''echo "- [${a.label}]($(nixTar ${a.drv}))"'') s.artifacts}443            '';444          in445          ''446            {447              echo "## Benchmark results"448              echo449              echo "[View rendered]($(nixRender ${benchmarks}))"450              echo451              echo "## Downloads"452              ${concatMapStringsSep "\n" renderSection releaseSections}453            } > $out454          '';455      };456      herculesCI =457        { lib, config, ... }:458        {459          ciSystems = [460            "x86_64-linux"461            "i686-linux"462            "aarch64-linux"463            "armv7l-linux"464            # TODO: add workers for these platforms465            # "aarch64-darwin"466          ];467          onPush.default.outputs = {468            benchmarks.x86_64-linux = inputs.self.legacyPackages.x86_64-linux.benchmarks.default;469470            # Cross: musl/mingw/darwin-zigbuild471            release.x86_64-linux = inputs.self.legacyPackages.x86_64-linux.release;472            release.aarch64-linux = inputs.self.legacyPackages.aarch64-linux.release;473            release.armv7l-linux = inputs.self.legacyPackages.armv7l-linux.release;474            release.i686-linux = inputs.self.legacyPackages.i686-linux.release;475476            # Too much to build for CI purposes477            devShells = mkForce { };478            formatter = mkForce { };479480            # No need to run them on different arch, pretty large derivations and might try to compile GHC481            checks.i686-linux.formatting = mkForce { };482            checks.aarch64-linux.formatting = mkForce { };483          };484        };485    };486}