serene/flake.nix

123 lines
4.1 KiB
Nix

# Serene Programming Language
#
# Copyright (c) 2019-2024 Sameer Rahmani <lxsameer@gnu.org>
#
# 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 <http://www.gnu.org/licenses/>.
{
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-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, git-hooks, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
version = "1.0.0";
overlays = [ (import ./nix/overlays.nix { }).muslComp ];
utils = import ./nix/utils.nix { inherit nixpkgs; };
# Create a package set based on the build system
pkgs_set = utils.get_pkgs system overlays;
hostPkgs = pkgs_set.host;
pkgs = pkgs_set.target;
# Create a stdenv based on LLVM
stdenv = pkgs.stdenvAdapters.overrideCC pkgs.stdenv
pkgs.llvmPackages_18.clangUseLLVM;
gc = pkgs.callPackage ./nix/boehmgc.nix { inherit stdenv; };
zlib' = pkgs.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 ]
++ [ pkgs.zlib.static ];
});
llvm = pkgs.llvmPackages_18.llvm.overrideAttrs
(old: { propagatedBuildInputs = [ pkgs.zlib.static ]; });
# This is the actual stdenv that we need to use anywhere else
stdenv' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv clang';
nativeBuildToolsDeps = (with hostPkgs; [ cmake ninja ccache ]);
buildToolsDeps =
(with pkgs; [ llvm llvmPackages_18.mlir llvmPackages_18.clang iwyu ]);
buildDeps = (with pkgs; [
gc
zlib'
llvm
llvmPackages_18.mlir
llvmPackages_18.clang
]);
testDeps = (with hostPkgs; [ gtest gmock gbenchmark ]);
in {
inherit pkgs;
devShells.default = (pkgs.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;
CPP_LS = "serene-clangd";
};
packages.devshell = stdenv'.mkDerivation {
inherit version;
name = "devshell";
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;
};
};
};
});
}