draconisplusplus/flake.nix

150 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";
2024-06-08 14:10:59 -04:00
treefmt-nix.url = "github:numtide/treefmt-nix";
2024-05-27 05:40:36 -04:00
utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
2024-06-08 14:10:59 -04:00
treefmt-nix,
2024-05-27 05:40:36 -04:00
utils,
...
}:
utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
2024-05-27 05:40:36 -04:00
overlays = [
2024-06-08 14:10:59 -04:00
(_self: super: {
2024-05-27 05:40:36 -04:00
ccacheWrapper = super.ccacheWrapper.override {
extraConfig = ''
export CCACHE_COMPRESS=1
2024-05-29 06:39:39 -04:00
export CCACHE_DIR="/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-06-06 21:04:32 -04:00
stdenv =
if pkgs.hostPlatform.isLinux
then pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv
else pkgs.llvmPackages_18.stdenv;
2024-06-06 04:14:52 -04:00
deps = with (
if !stdenv.isDarwin
then pkgs.pkgsStatic
2024-06-08 14:10:59 -04:00
else pkgs # TODO: Remove when fixed on darwin
);
2024-06-06 04:14:52 -04:00
[
2024-06-07 04:23:11 -04:00
curl
2024-06-06 04:14:52 -04:00
fmt
glib
tomlplusplus
2024-06-07 04:23:11 -04:00
yyjson
2024-06-08 04:57:32 -04:00
]
++ linuxPkgs
++ darwinPkgs;
2024-06-06 21:04:32 -04:00
2024-06-07 04:25:01 -04:00
linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs; [
2024-06-07 04:23:11 -04:00
systemdLibs
2024-06-06 21:04:32 -04:00
sdbus-cpp
valgrind
]);
darwinPkgs = nixpkgs.lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
Foundation
2024-06-07 13:45:59 -04:00
MediaPlayer
2024-06-05 19:04:53 -04:00
]);
in
with pkgs; {
packages = rec {
2024-06-08 04:57:32 -04:00
draconisplusplus = stdenv.mkDerivation {
2024-05-27 05:40:36 -04:00
name = "draconis++";
version = "0.1.0";
2024-05-27 05:40:36 -04:00
src = self;
nativeBuildInputs = [
meson
2024-05-29 06:39:39 -04:00
ninja
2024-05-27 05:40:36 -04:00
pkg-config
];
2024-06-08 04:57:32 -04:00
buildInputs = deps;
configurePhase = ''
meson setup build
'';
2024-05-27 05:40:36 -04:00
buildPhase = ''
meson compile -C build
2024-05-27 05:40:36 -04:00
'';
installPhase = ''
mkdir -p $out/bin
mv build/draconis++ $out/bin/draconis++
2024-05-27 05:40:36 -04:00
'';
};
2024-06-08 04:57:32 -04:00
default = draconisplusplus;
};
2024-06-08 14:10:59 -04:00
formatter = treefmt-nix.lib.mkWrapper pkgs {
projectRootFile = "flake.nix";
programs = {
alejandra.enable = true;
deadnix.enable = true;
clang-format = {
enable = true;
package = pkgs.clang-tools_18;
};
};
};
2024-05-27 05:40:36 -04:00
devShell = mkShell.override {inherit stdenv;} {
packages =
2024-05-29 00:28:54 -04:00
[
alejandra
bear
2024-06-01 06:59:01 -04:00
clang-tools_18
2024-06-06 04:14:52 -04:00
lldb
2024-06-08 04:57:32 -04:00
meson
2024-05-29 06:39:39 -04:00
ninja
2024-05-29 00:28:54 -04:00
pkg-config
2024-06-06 04:14:52 -04:00
unzip
2024-05-29 00:28:54 -04:00
2024-06-06 04:14:52 -04:00
(writeScriptBin "build" "meson compile -C build")
(writeScriptBin "clean" "meson setup build --wipe")
(writeScriptBin "run" "meson compile -C build && build/draconis++")
2024-06-05 19:04:53 -04:00
]
2024-06-08 04:57:32 -04:00
++ deps;
2024-05-27 05:40:36 -04:00
name = "C++";
};
}
2024-05-27 05:40:36 -04:00
);
}