diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..271ffde --- /dev/null +++ b/flake.nix @@ -0,0 +1,73 @@ +{ + description = "Sparse C2 framework"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, crane, fenix }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + toolchain = with fenix.packages.${system}; + combine [ + stable.rustc + stable.cargo + targets.x86_64-pc-windows-gnu.stable.rust-std + targets.x86_64-unknown-linux-musl.stable.rust-std + stable.rust-analyzer + ]; + + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + + src = craneLib.cleanCargoSource (craneLib.path ./.); + + commonArgs = { + inherit src; + + strictDeps = true; + + CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; + }; + + artifacts = craneLib.buildDepsOnly commonArgs; + + crate = craneLib.buildPackage (commonArgs // { + inherit artifacts; + buildInputs = with pkgs; [ cmake make ]; + }); + in with pkgs; { + devShells.default = craneLib.devShell rec { + name = "sparse"; + + buildInputs = [ cmake make ]; + }; + + packages = { + default = crate; + + windows = craneLib.buildPackage (commonArgs // { + doCheck = false; + + CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"; + + depsBuildBUild = [ + pkgsCross.mingwW64.stdenv.cc + pkgsCross.mingwW64.windows.pthreads + ]; + }); + + checks = { inherit crate; }; + }; + }); +}