Continued work configuring nix flakes

This commit is contained in:
Andrew Rioux 2024-01-23 17:39:56 -05:00
parent 4905ab54f0
commit b2278cc8e8
Signed by: andrew.rioux
GPG Key ID: 9B8BAC47C17ABB94
7 changed files with 247 additions and 23 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake . --impure

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ target
examples/bind-shell/key-generator/pubkey
examples/bind-shell/key-generator/privkey
core
**/core
**/core
.direnv

View File

@ -9,6 +9,8 @@ members = [
"tcp-test/client"
]
resolver = "2"
package.name = "sparse"
package.version = "0.6.0"
[profile.release]
strip = true

171
flake.lock generated Normal file
View File

@ -0,0 +1,171 @@
{
"nodes": {
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1705974079,
"narHash": "sha256-HyC3C2esW57j6bG0MKwX4kQi25ltslRnr6z2uvpadJo=",
"owner": "ipetkov",
"repo": "crane",
"rev": "0b4e511fe6e346381e31d355e03de52aa43e8cb2",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"libnl": {
"flake": false,
"locked": {
"lastModified": 1704704641,
"narHash": "sha256-5U9Pfd738Hyjtew9ZeDGKGbpRspym47T8egje1ZVUO4=",
"ref": "refs/heads/main",
"rev": "8693347fe9c47d08ce5899602ab4f208c1249619",
"revCount": 2024,
"type": "git",
"url": "https://github.com/thom311/libnl"
},
"original": {
"type": "git",
"url": "https://github.com/thom311/libnl"
}
},
"libpcap-src": {
"flake": false,
"locked": {
"lastModified": 1705891920,
"narHash": "sha256-4FehaAo6eWDqDVij/uY+BmVGhNMS7AfFZRyw2jk4inI=",
"ref": "refs/heads/master",
"rev": "fb92b4dd10ed1f73a536e512fd0b0e33b76329a6",
"revCount": 5944,
"type": "git",
"url": "https://github.com/the-tcpdump-group/libpcap"
},
"original": {
"type": "git",
"url": "https://github.com/the-tcpdump-group/libpcap"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1705916986,
"narHash": "sha256-iBpfltu6QvN4xMpen6jGGEb6jOqmmVQKUrXdOJ32u8w=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d7f206b723e42edb09d9d753020a84b3061a79d8",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"crane": "crane",
"flake-utils": "flake-utils",
"libnl": "libnl",
"libpcap-src": "libpcap-src",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1705976279,
"narHash": "sha256-Zx97bJ3+O8IP70uJPD//rRsr8bcxICISMTZUT/L9eFk=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "f889dc31ef97835834bdc3662394ebdb3c96b974",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View File

@ -3,8 +3,8 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
fenix = {
url = "github:nix-community/fenix";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
@ -12,62 +12,106 @@
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
libpcap-src = {
url = "git+https://github.com/the-tcpdump-group/libpcap";
flake = false;
};
libnl = {
url = "git+https://github.com/thom311/libnl";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, crane, fenix }:
outputs =
{ self, nixpkgs, flake-utils, crane, rust-overlay, libpcap-src, libnl }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
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
];
buildTools = with pkgs; [
autoconf
automake
bison
cmake
flex
libtool
libpcap
musl
pkg-config
];
toolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile
./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
src = craneLib.cleanCargoSource (craneLib.path ./.);
src = craneLib.path ./.;
commonArgs = {
inherit src;
strictDeps = true;
#strictDeps = true;
#CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
SPARSE_BUILD_LIBPCAP = "${libpcap-src}";
#SPARSE_BUILD_LIBNL = "${libnl}";
};
commonWindowsArgs = commonArgs // {
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
};
artifacts = craneLib.buildDepsOnly commonArgs;
windowsArtifacts = craneLib.buildDepsOnly commonWindowsArgs;
sparse-c2-linux-beacon = craneLib.buildPackage (commonArgs // {
inherit artifacts;
pname = "sparse-c2-beacon";
cargoExtraArgs = "-p sparse-c2-beacon --locked";
doCheck = false;
nativeBuildInputs = buildTools;
buildInputs = buildTools;
});
crate = craneLib.buildPackage (commonArgs // {
inherit artifacts;
buildInputs = with pkgs; [ cmake make ];
buildInputs = buildTools;
});
in with pkgs; {
devShells.default = craneLib.devShell rec {
name = "sparse";
buildInputs = [ cmake make ];
buildInputs = buildTools;
SPARSE_BUILD_LIBPCAP = "${libpcap-src}";
#SPARSE_BUILD_LIBNL = "${libnl}";
};
packages = {
default = crate;
packages = rec {
inherit sparse-c2-linux-beacon;
default = sparse-c2-linux-beacon;
windows = craneLib.buildPackage (commonArgs // {
doCheck = false;
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
depsBuildBUild = [
depsBuildBuild = [
pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
];
});
checks = { inherit crate; };
artifacts = windowsArtifacts;
});
};
});
}

View File

@ -14,7 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
fn main() {
let dst = cmake::Config::new("libpcap")
let dst = cmake::Config::new(std::env!("SPARSE_BUILD_LIBPCAP"))
.define("BUILD_SHARED_LIBS", "OFF")
.define("BUILD_WITH_LIBNL", "OFF")
.define("DISABLE_BLUETOOTH", "ON")

5
rust-toolchain.toml Normal file
View File

@ -0,0 +1,5 @@
[toolchain]
channel = "stable"
components = [ "rustfmt", "rust-std", "rustc-dev" ]
targets = [ "x86_64-pc-windows-gnu", "x86_64-unknown-linux-musl" ]
profile = "minimal"