aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraditya <bluenerd@protonmail.com>2023-06-30 14:59:28 +0530
committeraditya <bluenerd@protonmail.com>2023-06-30 14:59:28 +0530
commitfd71d74d4e9c6b06981ec4a9000579ecb362cc98 (patch)
tree5e68c4aa36a4a4e0660ed8bedae7f98f9c276414
parent39c3c26455b0c730ea3b66cbca3917b02692a110 (diff)
add c flake
-rw-r--r--flake-c.nix40
1 files changed, 40 insertions, 0 deletions
diff --git a/flake-c.nix b/flake-c.nix
new file mode 100644
index 0000000..c4ad911
--- /dev/null
+++ b/flake-c.nix
@@ -0,0 +1,40 @@
+
+{
+ description = "A build environment for C programs";
+
+ inputs = { nixpkgs.url = "github:nixos/nixpkgs/master"; };
+
+ outputs = { self, nixpkgs }:
+ let
+ pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgs;
+ in {
+ devShell.x86_64-linux = pkgs.llvmPackages_16.libcxxStdenv.mkDerivation {
+ name = "A build environment for C programs";
+ buildInputs = [
+ pkgs.clang_16
+ pkgs.clang-tools
+ pkgs.clang-analyzer
+ pkgs.lldb_16
+ pkgs.llvmPackages_16.stdenv
+ pkgs.llvmPackages_16.libcxxStdenv
+ pkgs.llvmPackages_16.libcxxClang
+ pkgs.llvmPackages_16.compiler-rt
+ pkgs.llvmPackages_16.compiler-rt-libc
+ pkgs.llvmPackages_16.bintools
+ pkgs.llvmPackages_16.clangUseLLVM
+ pkgs.llvmPackages_16.libcxxabi
+ pkgs.llvmPackages_16.libcxx
+ pkgs.llvmPackages_16.libllvm
+ pkgs.llvmPackages_16.lld
+ pkgs.llvmPackages_16.bintools
+ ];
+ shellHook = ''
+ echo "Usage: cc -o bin source.c"
+ export C_SANITIZE_FLAGS='-fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=bounds -fsanitize=float-divide-by-zero -fsanitize=integer-divide-by-zero -fsanitize=nonnull-attribute -fsanitize=null -fsanitize=pointer-overflow -fsanitize=integer -fno-omit-frame-pointer'
+ export C_WARNING_FLAGS='-Weverything -Wno-c++98-compat'
+ alias cc='clang -O1 -std=c17 -stdlib=libc++ $(echo $C_SANITIZE_FLAGS $C_WARNING_FLAGS) -g'
+ '';
+ };
+ };
+}
+