diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index c94e392daa..226768a24d 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -10,4 +10,5 @@ args: { secretsync = import ./secretsync args; copybara = import ./copybara.nix args; hg-git = import ./hg-git.nix args; + erbium = import ./erbium args; } // (import ./heptapod-runner.nix args) diff --git a/nix/pkgs/erbium/crate2nixify.nix b/nix/pkgs/erbium/crate2nixify.nix new file mode 100644 index 0000000000..751661859b --- /dev/null +++ b/nix/pkgs/erbium/crate2nixify.nix @@ -0,0 +1,44 @@ +{ depot, pkgs, lib, ... }: +{ name, src, crateName ? "", depsHash, crate2nixArgs ? {} }: +let + inherit (depot.third_party) crate2nix; + keepFiles = [ ./Cargo.toml ./Cargo.lock ]; + deps = pkgs.stdenv.mkDerivation { + inherit src; + name = "${name}-deps"; + + buildInputs = [ crate2nix ]; + + buildPhase = '' + mkdir /tmp/cargo + export CARGO_HOME=/tmp/cargo + + mkdir /tmp/gen + cp -R $src/* /tmp/gen + + cd /tmp/gen + ${crate2nix}/bin/crate2nix generate + + mkdir $out + cp /tmp/gen/Cargo.nix $out/Cargo.nix + cat >$out/default.nix < {} }: + let cargo_nix = nixpkgs.callPackage ./Cargo.nix { inherit nixpkgs; }; + in cargo_nix.${if crateName == "" then "rootCrate" else "workspaceMembers.${crateName}"}.build + EOF + ''; + + installPhase = "true"; + + outputHash = depsHash; + outputHashMode = "recursive"; + }; + merged = pkgs.runCommand "${name}-merged" { + inherit src deps; + } '' + mkdir $out + cp -R $src/* $out/ + cp $deps/default.nix $deps/Cargo.nix $out/ + ''; +in +import merged ({ nixpkgs = pkgs; } // crate2nixArgs) diff --git a/nix/pkgs/erbium/default.nix b/nix/pkgs/erbium/default.nix new file mode 100644 index 0000000000..6e2963cc0a --- /dev/null +++ b/nix/pkgs/erbium/default.nix @@ -0,0 +1,14 @@ +{ depot, pkgs, lib, ... }@args: +let + crate2nixify = import ./crate2nixify.nix args; +in +crate2nixify { + name = "erbium"; + src = pkgs.fetchFromGitHub { + owner = "isomer"; + repo = "erbium"; + rev = "39465a183454005ca96cdf7fad8638dba192f9a2"; + hash = "sha256:10770s5bm0b0kl2q2irx78s0j5h00a8xyk1dqp9dj03vk4jbhs7q"; + }; + depsHash = "sha256:0vxkl8q554018x7qw0qgbp7z0mgb7jcqsrdcphv319lfxbnymzyv"; +} diff --git a/third_party/default.nix b/third_party/default.nix index 8f4b8e3765..80e0fc3d9c 100644 --- a/third_party/default.nix +++ b/third_party/default.nix @@ -3,17 +3,25 @@ # SPDX-License-Identifier: Apache-2.0 { ... }@ch: -let nixpkgsConfig = { - allowUnfree = true; - permittedInsecurePackages = [ - "p7zip-16.02" - ]; -}; in -rec { - inherit nixpkgsConfig; +let + nixpkgsConfig = { + allowUnfree = true; + permittedInsecurePackages = [ + "p7zip-16.02" + ]; + }; nixpkgs = import ./nixpkgs { config = nixpkgsConfig; }; + crate2nixSrc = nixpkgs.fetchFromGitHub { + owner = "kolloch"; + repo = "crate2nix"; + rev = "e07af104b8e41d1cd7e41dc7ac3fdcdf4953efae"; + hash = "sha256:07syygn1rc5n1big7hf42pzgm5wc1r0mzglzvlbcb7rkzgqqhbqx"; + }; +in +rec { + inherit nixpkgsConfig nixpkgs; nixos = import ./nixpkgs/nixos; nixeval = import ./nixpkgs/nixos/lib/eval-config.nix; buildGo = @@ -37,4 +45,6 @@ rec { }; readTree = import ./tvl/nix/readTree {}; gopkgs = readTree ch ./gopkgs; + + crate2nix = import "${crate2nixSrc}" {}; }