From 5ea26bfc203c26b09bdfe7e01ee42a575352a7de Mon Sep 17 00:00:00 2001 From: asonix Date: Fri, 10 Nov 2023 17:21:02 -0600 Subject: [PATCH] preprare nightly cross-compile environment --- flake.lock | 66 +++++++++++++++++++++++++++++++++++++++++++++--- flake.nix | 73 +++++++++++++++++++++++++++++++++++++++++++---------- pict-rs.nix | 40 ----------------------------- 3 files changed, 123 insertions(+), 56 deletions(-) delete mode 100644 pict-rs.nix diff --git a/flake.lock b/flake.lock index 15e4c30..fb41589 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,26 @@ { "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": { "inputs": { "systems": "systems" @@ -18,13 +39,33 @@ "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": { "locked": { - "lastModified": 1694959747, - "narHash": "sha256-CXQ2MuledDVlVM5dLC4pB41cFlBWxRw4tCBsFrq3cRk=", + "lastModified": 1699099776, + "narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "970a59bd19eff3752ce552935687100c46e820a5", + "rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb", "type": "github" }, "original": { @@ -36,10 +77,29 @@ }, "root": { "inputs": { + "fenix": "fenix", "flake-utils": "flake-utils", + "naersk": "naersk", "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": { "locked": { "lastModified": 1681028828, diff --git a/flake.nix b/flake.nix index bf2ed66..ee92350 100644 --- a/flake.nix +++ b/flake.nix @@ -4,20 +4,68 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 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: let pkgs = import nixpkgs { 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 { packages = rec { - pict-rs = pkgs.callPackage ./pict-rs.nix { - inherit (pkgs.darwin.apple_sdk.frameworks) Security; - }; + pict-rs-x86_64-linux-gnu = makeRustCrossPackage "x86_64-linux"; + + pict-rs-aarch64-linux-gnu = makeRustCrossPackage "aarch64-linux"; + + pict-rs = pict-rs-x86_64-linux-gnu; default = pict-rs; }; @@ -29,23 +77,22 @@ devShell = with pkgs; mkShell { nativeBuildInputs = [ - cargo - cargo-outdated - clippy diesel-cli exiftool + (pkgs.fenix.complete.withComponents [ + "cargo" + "clippy" + "rust-src" + "rustc" + "rustfmt" + ]) ffmpeg_6-full garage - gcc imagemagick - rust-analyzer - rustc - rustfmt + rust-analyzer-nightly taplo tokio-console ]; - - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; }; }); } diff --git a/pict-rs.nix b/pict-rs.nix deleted file mode 100644 index 9b8aca1..0000000 --- a/pict-rs.nix +++ /dev/null @@ -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 ]; - }; -}