serene/flake.nix

377 lines
13 KiB
Nix

# Serene Programming Language
#
# Copyright (c) 2019-2023 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:NixOS/nixpkgs/bcb1a9c7e1d8568c5e58316fe3254eb8f4455439";
inputs.nixpkgs.url = "github:lxsameer/nixpkgs/e1f7865bce4d52d30dd1d61e79798ee2765cc2b0";
#inputs.nixpkgs.url = "/home/lxsameer/src/nixpkgs/";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
# Out zsh configuration directory. mkShell will pick up the .zshrc
# from this directory.
zshDir = ./scripts/zsh;
# Most of these overlays are do to bugs and problems
# in upstream nixpkgs. But thanks to their design
# We can fix them using these overlays and contribuete
# them upstream little by little.
overlays = [
(final: prev: {
p11-kit = prev.p11-kit.overrideAttrs (old: {
patches = [
./nix/patches/p11-kit_skip_test.patch
];
});
cpio = prev.cpio.overrideAttrs (old: {
nativeBuildInputs = [ prev.autoreconfHook ];
NIX_CFLAGS_COMPILE = "-Wno-implicit-function-declaration";
});
libedit = prev.libedit.overrideAttrs (old: {
# Musl is ISO 10646 compliant but doesn't define __STDC_ISO_10646__ we need to do it ourselves
NIX_CFLAGS_COMPILE = "-D__STDC_ISO_10646__=201103L";
});
elfutils = prev.elfutils.overrideAttrs (old: {
# libcxx does not have __cxa_demangle
configureFlags = old.configureFlags ++ [ "--disable-demangler" ];
});
ccache = prev.ccache.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ final.elfutils ];
});
# We don't need systemd at all
util-linux = prev.util-linux.override { systemdSupport = false; };
# libpam exmaples use glibc. We need to disable them
linux-pam = prev.linux-pam.overrideAttrs (old: {
postConfigure = ''
sed 's/examples//' -i Makefile
'';
});
#=============================================================
# Since we're using lld-17, and --no-undefined-version is the
# default in lld-17. We need to explicitely turn it off for
# these problematic packages untill they fix it upstream.
libgcrypt = prev.libgcrypt.overrideAttrs (old: {
NIX_LDFLAGS = if prev.stdenv.cc.isClang
then [ "--undefined-version" ]
else [];
});
libxcrypt = prev.libxcrypt.overrideAttrs (old: {
NIX_LDFLAGS = if prev.stdenv.cc.isClang
then [ "--undefined-version" ]
else [];
});
ncurses = prev.ncurses.overrideAttrs (old: {
NIX_LDFLAGS = if prev.stdenv.cc.isClang
then [ "--undefined-version" ]
else [];
});
libbsd = prev.libbsd.overrideAttrs (old: { #old.NIX_LDFLAGS ++
NIX_LDFLAGS = if prev.stdenv.cc.isClang
then [ "--undefined-version" ]
else [];
});
libidn2 = prev.libidn2.overrideAttrs (old: { #old.NIX_LDFLAGS ++
NIX_LDFLAGS = if prev.stdenv.cc.isClang
then [ "--undefined-version" ]
else [];
});
#==============================================================
iwyu = (prev.include-what-you-use.overrideAttrs (old:
let
version = "0.21";
in {
inherit version;
src = prev.fetchurl {
url = "${old.meta.homepage}/downloads/${old.pname}-${version}.src.tar.gz";
hash = "sha256-ajUZGf+JvafJXIlUcmAYaNs9qrlqlYs44DYokNWHYLY=";
};
cmakeFlags = [ "-DCMAKE_PREFIX_PATH=${prev.llvmPackages_17.llvm.dev}" ];
})).override {
llvmPackages = prev.__splicedPackages.llvmPackages_17;
};
})
];
get_pkgs = system:
if system == "x86_64-linux"
then import nixpkgs {
inherit system overlays;
linker = "lld";
crossSystem = nixpkgs.lib.systems.examples.musl64 // { useLLVM = true; };
# config.replaceCrossStdenv = { buildPackages, baseStdenv }:
# buildPackages.stdenvAdapters.overrideCC baseStdenv buildPackages.llvmPackages_17.clangUseLLVM;
}
else import nixpkgs {
inherit system overlays;
};
pkgs = get_pkgs system;
# # sereneLLVM = (pkgs.callPackage ./nix/llvm.nix {
# # inherit (pkgs) lib stdenv cmake ninja ccache zlib libxml2 fetchgit;
# # }).llvm;
# # stdenv = pkgs.stdenvAdapters.overrideCC pkgs.stdenv sereneLLVM;
# stdenv = pkgs.stdenv;
stdenv = pkgs.stdenvAdapters.overrideCC pkgs.stdenv pkgs.llvmPackages_17.clangUseLLVM;
sereneLLVM = pkgs.llvmPackages_17.override { inherit stdenv; };
gc = pkgs.callPackage ./nix/boehmgc.nix { inherit stdenv; };
clang' = stdenv.cc.overrideAttrs (old: {
propagatedBuildInputs = [ stdenv.cc.bintools ] ++ [ pkgs.zlib-ng ];
});
stdenv' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv clang';
# utils = (pkgs.callPackage ./nix/utils.nix {});
# llvm_source = pkgs.callPackage ./nix/llvm_source.nix {};
# libunwind = (pkgs.callPackage ./nix/libunwind {
# stdenv = stdenv';
# inherit llvm_source utils;
# });
# cxx-headers = (pkgs.callPackage ./nix/libcxx {
# inherit llvm_source utils;
# llvm_libunwind = libunwind;
# llvm_libcxxabi = null;
# headersOnly = true;
# stdenv = stdenv';
# });
# libcxxabi = (pkgs.callPackage ./nix/libcxxabi {
# inherit llvm_source utils cxx-headers;
# llvm_libunwind = libunwind;
# stdenv = stdenv';
# });
# libcxx = (pkgs.callPackage ./nix/libcxx {
# inherit llvm_source utils;
# llvm_libcxxabi = libcxxabi;
# llvm_libunwind = libunwind;
# stdenv = stdenv';
# });
# compiler-rt = (pkgs.callPackage ./nix/compiler-rt {
# inherit llvm_source utils;
# llvm_libcxxabi = libcxxabi;
# stdenv = stdenv';
# });
# ullvm = pkgs.stellvmPackages_17;
# clang' = pkgs.wrapCCWith rec {
# libcxx = ullvm.libcxx;
# cc = ullvm.clang;
# libc = ullvm.musl;
# bintools = ullvm.bintools;
# extraPackages = [
# libcxxabi
# compiler-rt
# ] ++ pkgs.lib.optionals (!pkgs.stdenv.targetPlatform.isWasm) [
# ullvm.libunwind
# ];
# extraBuildCommands = mkExtraBuildCommands cc llvm_source.major compiler-rt;
# nixSupport.cc-cflags =
# [ "-rtlib=compiler-rt"
# "-Wno-unused-command-line-argument"
# "-B${compiler-rt}/lib"
# ]
# ++ pkgs.lib.optional (!pkgs.stdenv.targetPlatform.isWasm) "--unwindlib=libunwind"
# ++ pkgs.lib.optional
# (!stdenv'.targetPlatform.isWasm)
# "-lunwind"
# ++ pkgs.lib.optional pkgs.stdenv.targetPlatform.isWasm "-fno-exceptions";
# };
# stdenv'' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv clang';
# llvm = (pkgs.callPackage ./nix/llvm {
# inherit llvm_source utils;
# buildLlvmTools = pkgs.llvmPackages_17;
# stdenv = stdenv'';
# });
# llvm = (pkgs.callPackage ./nix/llvm.nix {
# inherit llvm_source utils;
# # llvm_libcxx = libcxx;
# # llvm_libcxxabi = libcxxabi;
# # llvm_compiler-rt = compiler-rt;
# # llvm_libunwind = libunwind;
# stdenv = pkgs.stdenv;
# });
# clang' = pkgs.wrapCCWith rec {
# libcxx = llvm;
# cc = llvm;
# libc = pkgs.llvmPackages_17.bintools.libc;
# bintools = pkgs.llvmPackages_17.bintools;
# extraPackages = [
# llvm
# ];
# # extraPackages = [
# # libcxxabi
# # compiler-rt
# # ] ++ pkgs.lib.optionals (!pkgs.stdenv.targetPlatform.isWasm) [
# # ullvm.libunwind
# # ];
# extraBuildCommands = mkExtraBuildCommands cc llvm_source.major;
# nixSupport.cc-cflags =
# [ "-rtlib=compiler-rt"
# "-Wno-unused-command-line-argument"
# "-B${llvm}/lib/"
# ]
# ++ pkgs.lib.optional (!pkgs.stdenv.targetPlatform.isWasm) "--unwindlib=libunwind"
# ++ pkgs.lib.optional
# (!stdenv'.targetPlatform.isWasm)
# "-lunwind"
# ++ pkgs.lib.optional pkgs.stdenv.targetPlatform.isWasm "-fno-exceptions";
# };
# stdenv'' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv clang';
llvm = pkgs.llvmPackages_17.llvm.overrideAttrs (old: {
propagatedBuildInputs = [];
});
z = pkgs.zlib-ng.overrideAttrs (old: {
cmakeFlags = [
"-DCMAKE_INSTALL_PREFIX=/"
"-DBUILD_SHARED_LIBS=OFF"
"-DINSTALL_UTILS=ON"
"-DZLIB_COMPAT=ON"
];
});
#with pkgs;
native_build_inputs =
let
# filterCmakeFlags = xs: builtins.filter
# (x: !(x == "-DCMAKE_CROSSCOMPILING=True" || pkgs.lib.hasPrefix "-DLLVM_TABLEGEN=" x))
# xs;
git' = pkgs.git.overrideAttrs (old: {
preInstallCheck =
pkgs.lib.replaceStrings [ ''disable_test t0201-gettext-fallbacks'' ]
[ ''
disable_test t0201-gettext-fallbacks
disable_test t2082-parallel-checkout-attributes
'' ]
old.preInstallCheck;
});
# iwyu = (pkgs.include-what-you-use.overrideAttrs (old:
# let
# version = "0.22";
# in {
# inherit version;
# src = pkgs.fetchurl {
# url = "${old.meta.homepage}/downloads/${old.pname}-${version}.src.tar.gz";
# hash = "sha256-ajUZGf+JvafJXIlUcmAYaNs9qrlqlYs44DYokNWHYLY=";
# };
# }))
# .override {
# llvmPackages = pkgs.__splicedPackages.llvmPackages_17;# .overrideAttrs (oldLLVM: {
# # cmakeFlags = builtins.trace ">> ${toString(filterCmakeFlags oldLLVM.cmakeFlags)}" filterCmakeFlags oldLLVM.cmakeFlags;
# # });
# };
# mlir_16' = pkgs.mlir_16.overrideAttrs (old: {
# });
# builtins.trace ">> ${sereneLLVM}"
in (with pkgs; [
# sereneLLVM.llvm
# sereneLLVM.mlir
# sereneLLVM.clang
# sereneLLVM.compiler-rt
# sereneLLVM.lld
# sereneLLVM.libcxx
# sereneLLVM.libcxxabi
cmake
ninja
ccache
git'
zsh
zsh-autosuggestions
zsh-autocomplete
zsh-syntax-highlighting
python3
iwyu
# mlir17
# llvm17
# cr17
# cc17
# libcxx17
# libcxxabi17
# lld17
# libunwind17
gc
#musl
llvm
#llvmPackages_17.llvm
llvmPackages_17.mlir
llvmPackages_17.clang
]);
build_inputs = with pkgs; [
gc
#musl
gtest
gmock
#llvmPackages_17.llvm
z
llvm
llvmPackages_17.mlir
llvmPackages_17.clang
# llvmPackages_17.libcxx
# llvmPackages_17.libcxxabi
# llvmPackages_17.compiler-rt
# zstd
];
in {
inherit pkgs;
devShells.default = (pkgs.mkShell.override { stdenv = stdenv';}) {
nativeBuildInputs = native_build_inputs;
buildInputs = build_inputs;
shellHook =
''
ZDOTDIR=${zshDir} zsh -d && exit
'';
};
#packages.llvm = llvm;
}
);
}