mirror of
https://git.dirksys.ovh/dirk/bankserver.git
synced 2026-01-06 11:12:41 +01:00
nix: compile schemas only once when cross compiling
This commit is contained in:
parent
e9244e6be5
commit
9a52d120bf
77
flake.nix
77
flake.nix
@ -17,6 +17,25 @@
|
||||
rust-overlay,
|
||||
}:
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
src = lib.fileset.toSource {
|
||||
root = ./.;
|
||||
fileset =
|
||||
with lib.fileset;
|
||||
intersection (gitTracked ./.) (unions [
|
||||
(fileFilter (
|
||||
file:
|
||||
file.type == "directory"
|
||||
|| file.hasExt "rs"
|
||||
|| file.hasExt "toml"
|
||||
|| file.name == "Cargo.lock"
|
||||
|| file.hasExt "sql"
|
||||
|| file.name == "openapi-def.yaml"
|
||||
|| file.hasExt "html"
|
||||
) ./.)
|
||||
]);
|
||||
};
|
||||
|
||||
forAllSystems =
|
||||
function:
|
||||
nixpkgs.lib.genAttrs
|
||||
@ -39,6 +58,49 @@
|
||||
overlay =
|
||||
pkgs:
|
||||
let
|
||||
rev = self.shortRev or "dirty";
|
||||
cargoDeps =
|
||||
platform:
|
||||
platform.importCargoLock {
|
||||
lockFile = ./Cargo.lock;
|
||||
outputHashes = {
|
||||
"dbmigrator-0.4.4-alpha" = "sha256-Nwxw74IyZeZ9dODb+aneQmuQe0grO+g45B3zv1XaihE=";
|
||||
};
|
||||
};
|
||||
mkRustPlatform =
|
||||
pkgs: rustVersion:
|
||||
pkgs.makeRustPlatform {
|
||||
cargo = rustVersion;
|
||||
rustc = rustVersion;
|
||||
};
|
||||
buildRustVersion = pkgs.pkgsBuildBuild.rust-bin.stable.latest.minimal;
|
||||
buildRustPlatform = mkRustPlatform pkgs.pkgsBuildBuild buildRustVersion;
|
||||
schemas = pkgs.pkgsBuildBuild.stdenv.mkDerivation {
|
||||
pname = "bankingserver_schemas";
|
||||
version = "unstable-${rev}";
|
||||
inherit src;
|
||||
cargoDeps = cargoDeps buildRustPlatform;
|
||||
cargoBuildType = "debug";
|
||||
# "CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" =
|
||||
# "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
||||
nativeBuildInputs = [
|
||||
buildRustPlatform.cargoSetupHook
|
||||
buildRustVersion
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
touch openapi.json
|
||||
cargo build --bin generate-schemas
|
||||
target/debug/generate-schemas
|
||||
runHook postBuild
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/bankserver
|
||||
cp -r schemas $out/share/bankserver/schemas
|
||||
'';
|
||||
doCheck = false;
|
||||
};
|
||||
|
||||
rustVersion = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchain {
|
||||
channel = "stable";
|
||||
targets = [
|
||||
@ -46,13 +108,16 @@
|
||||
pkgs.pkgsBuildHost.buildPlatform.rust.rustcTarget
|
||||
];
|
||||
};
|
||||
rustPlatform = pkgs.makeRustPlatform {
|
||||
cargo = rustVersion;
|
||||
rustc = rustVersion;
|
||||
};
|
||||
rustPlatform = mkRustPlatform pkgs rustVersion;
|
||||
|
||||
bankserver = pkgs.callPackage ./package.nix {
|
||||
inherit rustPlatform;
|
||||
rev = self.shortRev or "dirty";
|
||||
inherit
|
||||
src
|
||||
rustPlatform
|
||||
schemas
|
||||
rev
|
||||
;
|
||||
cargoDeps = cargoDeps rustPlatform;
|
||||
};
|
||||
in
|
||||
{
|
||||
|
||||
55
package.nix
55
package.nix
@ -1,62 +1,14 @@
|
||||
{
|
||||
lib,
|
||||
rustPlatform,
|
||||
stdenv,
|
||||
redocly,
|
||||
yq-go,
|
||||
targetPlatform,
|
||||
pkgsBuildBuild,
|
||||
src,
|
||||
schemas,
|
||||
cargoDeps,
|
||||
rev ? "dirty",
|
||||
}:
|
||||
let
|
||||
src = lib.fileset.toSource {
|
||||
root = ./.;
|
||||
fileset =
|
||||
with lib.fileset;
|
||||
intersection (gitTracked ./.) (unions [
|
||||
(fileFilter (
|
||||
file:
|
||||
file.type == "directory"
|
||||
|| file.hasExt "rs"
|
||||
|| file.hasExt "toml"
|
||||
|| file.name == "Cargo.lock"
|
||||
|| file.hasExt "sql"
|
||||
|| file.name == "openapi-def.yaml"
|
||||
|| file.hasExt "html"
|
||||
) ./.)
|
||||
]);
|
||||
};
|
||||
cargoDeps = rustPlatform.importCargoLock {
|
||||
lockFile = ./Cargo.lock;
|
||||
outputHashes = {
|
||||
"dbmigrator-0.4.4-alpha" = "sha256-Nwxw74IyZeZ9dODb+aneQmuQe0grO+g45B3zv1XaihE=";
|
||||
};
|
||||
};
|
||||
schemas = pkgsBuildBuild.stdenv.mkDerivation {
|
||||
pname = "bankingserver_schemas";
|
||||
version = "unstable-${rev}";
|
||||
inherit src cargoDeps;
|
||||
cargoBuildType = "debug";
|
||||
# "CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" =
|
||||
# "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
||||
nativeBuildInputs = [
|
||||
rustPlatform.cargoSetupHook
|
||||
rustPlatform.rust.cargo
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
touch openapi.json
|
||||
cargo build --bin generate-schemas
|
||||
target/debug/generate-schemas
|
||||
runHook postBuild
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/bankserver
|
||||
cp -r schemas $out/share/bankserver/schemas
|
||||
'';
|
||||
doCheck = false;
|
||||
};
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "bankingserver";
|
||||
version = "unstable-${rev}";
|
||||
@ -69,7 +21,6 @@ rustPlatform.buildRustPackage {
|
||||
];
|
||||
|
||||
preBuild = ''
|
||||
echo "Schemas: ${schemas}"
|
||||
cp -r ${schemas}/share/bankserver/schemas schemas
|
||||
|
||||
yq eval-all -n 'load("openapi-def.yaml") *n load("schemas/schemas.json")' > openapi-temp.yaml
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user