Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nix flake support #682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
build/
# Nix build output
result
83 changes: 83 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
gitignore = {
inputs.nixpkgs.follows = "nixpkgs";
url = "github:hercules-ci/gitignore.nix";
};
};

outputs = { nixpkgs, flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
perSystem = {config, self', inputs', pkgs, system, ...}:
with rec {
inherit (pkgs) lib;
clean-source = src: inputs.gitignore.lib.gitignoreSource (lib.cleanSource src);
}; {
packages = {
default = pkgs.stdenv.mkDerivation (self: {
name = "trojan";
src = clean-source ./.;
nativeBuildInputs = [
pkgs.cmake
# tests:
pkgs.curl
pkgs.netcat
pkgs.python3
];
env = lib.optionalAttrs self.enableMysql {
NIX_CFLAGS_COMPILE = "-L${pkgs.libmysqlclient}/lib/mariadb";
};
buildInputs = with pkgs; [ boost openssl ] ++
lib.optionals self.enableMysql [ libmysqlclient ];
enableMysql = true;
cmakeFlags = [
"-DDEFAULT_CONFIG=config.json"
"-DENABLE_MYSQL=${if self.enableMysql then "ON" else "OFF"}"
# Options that I found in their CI config but didn’t care to enable just yet
# "-DBoost_USE_STATIC_LIBS=ON"
# -DFORCE_TCP_FASTOPEN=ON
] ++ lib.optionals self.enableMysql [
"-DMYSQL_INCLUDE_DIR=${lib.getDev pkgs.libmysqlclient}/include/mariadb"
];
doCheck = true;
});
nomysql = self'.packages.default.overrideAttrs (_: {
enableMysql = false;
});
};
};
systems = [ "x86_64-linux" "aarch64-linux" ];
};
}