draconisplusplus/flake.nix

155 lines
3.9 KiB
Nix
Raw Normal View History

2024-05-27 05:40:36 -04:00
{
description = "C/C++ environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
utils,
...
}:
utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
(self: super: {
ccacheWrapper = super.ccacheWrapper.override {
extraConfig = ''
export CCACHE_COMPRESS=1
2024-05-29 00:28:54 -04:00
export CCACHE_DIR="/nix/var/cache/ccache"
2024-05-27 05:40:36 -04:00
export CCACHE_UMASK=007
if [ ! -d "$CCACHE_DIR" ]; then
echo "====="
echo "Directory '$CCACHE_DIR' does not exist"
echo "Please create it with:"
echo " sudo mkdir -m0770 '$CCACHE_DIR'"
echo " sudo chown root:nixbld '$CCACHE_DIR'"
echo "====="
exit 1
fi
if [ ! -w "$CCACHE_DIR" ]; then
echo "====="
echo "Directory '$CCACHE_DIR' is not accessible for user $(whoami)"
echo "Please verify its access permissions"
echo "====="
exit 1
fi
'';
};
})
];
};
2024-05-29 00:28:54 -04:00
2024-05-27 05:40:36 -04:00
llvm = pkgs.llvmPackages_latest;
2024-05-29 00:28:54 -04:00
stdenv = pkgs.ccacheStdenv.override {
stdenv =
if pkgs.hostPlatform.isDarwin
then llvm.libcxxStdenv
else pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv;
};
darwinPkgs = nixpkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin; [
apple_sdk.frameworks.AppKit
apple_sdk.frameworks.Carbon
apple_sdk.frameworks.Cocoa
apple_sdk.frameworks.CoreFoundation
apple_sdk.frameworks.IOKit
apple_sdk.frameworks.WebKit
apple_sdk.frameworks.Security
apple_sdk.frameworks.DisplayServices
]);
2024-05-27 05:40:36 -04:00
in {
packages = rec {
draconis-cpp = with pkgs;
stdenv.mkDerivation {
name = "draconis++";
src = self;
nativeBuildInputs = [
cmake
pkg-config
];
2024-05-29 00:28:54 -04:00
propagatedBuildInputs =
[
boost185
glib
]
++ (
if pkgs.hostPlatform.isLinux
then [playerctl]
else []
);
buildInputs =
[
fmt
libcpr
tomlplusplus
]
++ darwinPkgs;
2024-05-27 05:40:36 -04:00
buildPhase = ''
cmake .
make
'';
installPhase = ''
install -Dm755 ./draconis++ $out/bin/draconis++
'';
};
default = draconis-cpp;
};
devShell = with pkgs;
mkShell.override {inherit stdenv;} {
2024-05-29 00:28:54 -04:00
packages = with pkgs;
[
# builder
gnumake
cmake
pkg-config
# debugger
lldb
# fix headers not found
clang-tools
# LSP and compiler
llvm.libstdcxxClang
# other tools
cppcheck
llvm.libllvm
# stdlib for cpp
llvm.libcxx
# libraries
boost185
fmt
glib
libcpr
tomlplusplus
]
++ (
if stdenv.isDarwin
then []
else [playerctl]
)
++ darwinPkgs;
2024-05-27 05:40:36 -04:00
name = "C++";
};
}
);
}