preprare nightly cross-compile environment

This commit is contained in:
asonix 2023-11-10 17:21:02 -06:00
parent 71f8f52b58
commit 5ea26bfc20
3 changed files with 123 additions and 56 deletions

View file

@ -1,5 +1,26 @@
{ {
"nodes": { "nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1699597299,
"narHash": "sha256-uJMCDTKSUB7+K+s7SB2DS6WU2VGDmruXmP9TQwTYGkw=",
"owner": "nix-community",
"repo": "fenix",
"rev": "ae8ecab0dbfe3552bd1a0bf5504416fd07dd2e8a",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
@ -18,13 +39,33 @@
"type": "github" "type": "github"
} }
}, },
"naersk": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1698420672,
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
"owner": "nix-community",
"repo": "naersk",
"rev": "aeb58d5e8faead8980a807c840232697982d47b9",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1694959747, "lastModified": 1699099776,
"narHash": "sha256-CXQ2MuledDVlVM5dLC4pB41cFlBWxRw4tCBsFrq3cRk=", "narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "970a59bd19eff3752ce552935687100c46e820a5", "rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -36,10 +77,29 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"fenix": "fenix",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"naersk": "naersk",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
}, },
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1699552432,
"narHash": "sha256-MxxTH/X5vnqLWEwokxdA5AkX/NpXOrHMn/95QwOdA4o=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "76633199f4316b9c659d4ec0c102774d693cd940",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": { "systems": {
"locked": { "locked": {
"lastModified": 1681028828, "lastModified": 1681028828,

View file

@ -4,20 +4,68 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = { self, nixpkgs, flake-utils }: outputs = { self, nixpkgs, flake-utils, fenix, naersk }:
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [ fenix.overlays.default ];
}; };
makeRustCrossPackage = (crossSystem:
let
systemMappings = {
"x86_64-linux" = ["x86_64" "unknown" "linux" "gnu"];
"aarch64-linux" = ["aarch64" "unknown" "linux" "gnu"];
};
pkgsCross = import nixpkgs {
inherit system;
crossSystem.system = crossSystem;
};
target = nixpkgs.lib.strings.concatStringsSep "-" systemMappings.${crossSystem};
cargoTarget = nixpkgs.lib.strings.concatMapStringsSep "_" (nixpkgs.lib.strings.toUpper) systemMappings.${crossSystem};
ccTarget = nixpkgs.lib.strings.concatStringsSep "_" systemMappings.${crossSystem};
toolchain = with fenix.packages.${system}; combine [
minimal.cargo
minimal.rustc
targets.${target}.latest.rust-std
];
inherit (pkgsCross.stdenv) cc;
in
(naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
}).buildPackage {
src = ./.;
CARGO_BUILD_TARGET = target;
"CARGO_TARGET_${cargoTarget}_LINKER" = "${cc}/bin/${cc.targetPrefix}cc";
"CC_${ccTarget}" = "${cc}/bin/${cc.targetPrefix}cc";
"AR_${ccTarget}" = "${cc}/bin/${cc.targetPrefix}ar";
});
in in
{ {
packages = rec { packages = rec {
pict-rs = pkgs.callPackage ./pict-rs.nix { pict-rs-x86_64-linux-gnu = makeRustCrossPackage "x86_64-linux";
inherit (pkgs.darwin.apple_sdk.frameworks) Security;
}; pict-rs-aarch64-linux-gnu = makeRustCrossPackage "aarch64-linux";
pict-rs = pict-rs-x86_64-linux-gnu;
default = pict-rs; default = pict-rs;
}; };
@ -29,23 +77,22 @@
devShell = with pkgs; mkShell { devShell = with pkgs; mkShell {
nativeBuildInputs = [ nativeBuildInputs = [
cargo
cargo-outdated
clippy
diesel-cli diesel-cli
exiftool exiftool
(pkgs.fenix.complete.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
])
ffmpeg_6-full ffmpeg_6-full
garage garage
gcc
imagemagick imagemagick
rust-analyzer rust-analyzer-nightly
rustc
rustfmt
taplo taplo
tokio-console tokio-console
]; ];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}; };
}); });
} }

View file

@ -1,40 +0,0 @@
{ exiftool
, ffmpeg_6-full
, imagemagick
, lib
, makeWrapper
, nixosTests
, rustPlatform
, Security
, stdenv
}:
rustPlatform.buildRustPackage {
pname = "pict-rs";
version = "0.5.0-beta.2";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = [ stdenv makeWrapper ];
buildInputs = lib.optionals stdenv.isDarwin [ Security ];
RUSTFLAGS = "--cfg tokio_unstable --cfg uuid_unstable";
TARGET_CC = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
TARGET_AR = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}ar";
postInstall = ''
wrapProgram $out/bin/pict-rs \
--prefix PATH : "${lib.makeBinPath [ imagemagick ffmpeg_6-full exiftool ]}"
'';
passthru.tests = { inherit (nixosTests) pict-rs; };
meta = with lib; {
description = "A simple image hosting service";
homepage = "https://git.asonix.dog/asonix/pict-rs";
license = with licenses; [ agpl3Plus ];
};
}