summaryrefslogtreecommitdiffstats
path: root/lib/nix-thin-edge-builder/writeCargoRegistry.nix
diff options
context:
space:
mode:
authorMarcel Müller <m.mueller@ifm.com>2022-08-31 12:01:34 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-09-09 14:19:04 +0200
commit55c3f56dc53de2451718d3fdba16d2197b48b509 (patch)
tree49f6da7bd813fa3106177077d4def1a3ca17a47c /lib/nix-thin-edge-builder/writeCargoRegistry.nix
parent4fa4856c5d21fdcfb37d5d6a0ca9853372f809f9 (diff)
Implement generating thin-edge binariespost-merge/nix-thin-edge-builder
The flake now exports a working `lib.mkThinEdge` function with which users can generate a working binary with only the components they wish to include. It works as follows: - It pulls in all the dependencies required for the thin-edge CLI - It then pulls in and patches the sources given. Any path references to tedge_api/lib are patched to their nix-store equivalencies. - The Cargo.lock is generated by downloading the cargo index and overriding its location to be effectively offline - A temporary Rust project is created, where all the different components are then referenced and pulled in. - This Rust project is then compiled using `crane` (currently a private fork with some hacks due to a deficiency in Nix relating to importing store paths in the TOML reader) - crane automatically copies the resulting binary to the output Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Diffstat (limited to 'lib/nix-thin-edge-builder/writeCargoRegistry.nix')
-rw-r--r--lib/nix-thin-edge-builder/writeCargoRegistry.nix20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/nix-thin-edge-builder/writeCargoRegistry.nix b/lib/nix-thin-edge-builder/writeCargoRegistry.nix
new file mode 100644
index 00000000..d536b2ab
--- /dev/null
+++ b/lib/nix-thin-edge-builder/writeCargoRegistry.nix
@@ -0,0 +1,20 @@
+{ craneLib, pkgs }:
+
+let
+ cratesIoRegistry = fetchGit {
+ url = "https://github.com/rust-lang/crates.io-index.git";
+ ref = "master";
+ rev = "e9936adc4a5f03f929c3d19a8d3bcc73479ccc9a";
+ };
+ localCrateRegistry = pkgs.linkFarm "local-crate-registry" [
+ { name = "index"; path = cratesIoRegistry; }
+ ];
+ config = {
+ source = {
+ crates-io = {
+ local-registry = localCrateRegistry;
+ };
+ };
+ };
+in
+craneLib.writeTOML "Cargo.toml" config