# Serene Programming Language # # Copyright (c) 2019-2024 Sameer Rahmani # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 2. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . { description = "Serene programming language"; inputs.nixpkgs.url = "github:lxsameer/nixpkgs/c738ee8ad1c35383037c20fa13eaac17c8ae98c5"; #inputs.nixpkgs.url = "/home/lxsameer/src/nixpkgs/"; inputs.git-hooks.url = "github:cachix/git-hooks.nix"; inputs.flake-parts.url = "github:hercules-ci/flake-parts"; outputs = { self, nixpkgs, git-hooks, flake-parts, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "aarch64-darwin" "riscv64-linux" "x86_64-linux" ]; flake = { }; perSystem = { config, self', inputs', system, pkgs, lib, ... }: let version = "1.0.0"; overlays = (lib.attrsets.attrValues (import ./nix/overlays.nix { })); utils = import ./nix/utils.nix { inherit nixpkgs; }; hostPkgs = pkgs; targetPkgs = utils.getPkgs system overlays; # Create a stdenv based on LLVM stdenv = targetPkgs.stdenvAdapters.overrideCC targetPkgs.stdenv targetPkgs.llvmPackages_18.clangUseLLVM; gc = targetPkgs.callPackage ./nix/boehmgc.nix { inherit stdenv; }; zlib' = targetPkgs.zlib-ng.overrideAttrs (old: { cmakeFlags = [ "-DCMAKE_INSTALL_PREFIX=/" "-DBUILD_SHARED_LIBS=OFF" "-DINSTALL_UTILS=ON" "-DZLIB_COMPAT=ON" ]; }); # By default llvm adds zlib to `propagatedBuildInputs` which means any # package that uses llvm will indirectly depends on zlib. And since # by default that zlib is built as a shared lib (since our packageset # is not static), We can't statically link to it. So, we just replace # that zlib with our override of zlib-ng clang' = stdenv.cc.overrideAttrs (old: { propagatedBuildInputs = [ stdenv.cc.bintools ] ++ [ targetPkgs.zlib.static ]; }); llvm = targetPkgs.llvmPackages_18.llvm.overrideAttrs (old: { propagatedBuildInputs = [ targetPkgs.zlib.static ]; }); # This is the actual stdenv that we need to use anywhere else stdenv' = targetPkgs.stdenvAdapters.overrideCC targetPkgs.stdenv clang'; nativeBuildToolsDeps = (with hostPkgs; [ cmake ninja ccache ]); buildToolsDeps = (with targetPkgs; [ llvm llvmPackages_18.mlir llvmPackages_18.clang iwyu ]); buildDeps = (with targetPkgs; [ gc zlib' llvm llvmPackages_18.mlir llvmPackages_18.clang ]); testDeps = (with hostPkgs; [ gtest gmock gbenchmark ]); in { devShells.default = (targetPkgs.mkShell.override { stdenv = stdenv'; }) { inherit (self.checks.${system}.git-hook-check) shellHook; nativeBuildInputs = nativeBuildToolsDeps ++ buildToolsDeps; buildInputs = buildDeps ++ testDeps ++ self.checks.${system}.git-hook-check.enabledPackages; }; packages.blah = buildDeps ++ testDeps ++ nativeBuildToolsDeps ++ buildToolsDeps; packages.devshell = stdenv'.mkDerivation { inherit version; name = "devshell"; src = ./.; doBuild = false; doUnpack = false; doCheck = false; nativeBuildInputs = nativeBuildToolsDeps ++ buildToolsDeps; buildInputs = buildDeps ++ testDeps; }; checks = { git-hook-check = git-hooks.lib.${system}.run { src = ./.; hooks = { nixfmt.enable = true; clang-format = { enable = true; types_or = hostPkgs.lib.mkForce [ "c" "c++" ]; }; shellcheck.enable = true; cmake-format.enable = true; }; }; }; }; }; }