diff --git a/.gitignore b/.gitignore index 98cd2b59..7243b66b 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,5 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake build/ +# Nix build output +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..53ce05af --- /dev/null +++ b/flake.lock @@ -0,0 +1,83 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1690933134, + "narHash": "sha256-ab989mN63fQZBFrkk4Q8bYxQCktuHmBIBqUG1jl6/FQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "59cf3f1447cfc75087e7273b04b31e689a8599fb", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1691342804, + "narHash": "sha256-jRvAZj8/8rHItyceMrY2R37EABJH6RVRdHYCBLKdpIE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e133d401e664303611d635ea62f15cfee9b4f7ae", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1690881714, + "narHash": "sha256-h/nXluEqdiQHs1oSgkOOWF+j8gcJMWhwnZ9PFabN6q0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9e1960bc196baf6881340d53dccb203a951745a2", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..12bddb3b --- /dev/null +++ b/flake.nix @@ -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" ]; + }; +}