mirror of
https://github.com/DeterminateSystems/flake-checker.git
synced 2024-10-04 01:37:42 +03:00
Fix Nix build and update inputs
This commit is contained in:
parent
ad4f0033b4
commit
8e7089c7ce
109
crane.nix
Normal file
109
crane.nix
Normal file
@ -0,0 +1,109 @@
|
||||
{ stdenv
|
||||
, pkgs
|
||||
, lib
|
||||
, crane
|
||||
, rust
|
||||
, rust-bin
|
||||
, nix-gitignore
|
||||
, supportedSystems
|
||||
, darwinFrameworks
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (stdenv.hostPlatform) system;
|
||||
|
||||
nightlyVersion = "2024-06-13";
|
||||
rustNightly = pkgs.rust-bin.nightly.${nightlyVersion}.default.override {
|
||||
extensions = [ "rust-src" "rust-analyzer-preview" ];
|
||||
targets = cargoTargets;
|
||||
};
|
||||
|
||||
# For easy cross-compilation in devShells
|
||||
# We are just composing the pkgsCross.*.stdenv.cc together
|
||||
crossPlatforms =
|
||||
let
|
||||
makeCrossPlatform = crossSystem:
|
||||
let
|
||||
pkgsCross =
|
||||
if crossSystem == system then pkgs
|
||||
else
|
||||
import pkgs.path {
|
||||
inherit system crossSystem;
|
||||
overlays = [ ];
|
||||
};
|
||||
|
||||
rustTargetSpec = rust.toRustTargetSpec pkgsCross.pkgsStatic.stdenv.hostPlatform;
|
||||
rustTargetSpecUnderscored = builtins.replaceStrings [ "-" ] [ "_" ] rustTargetSpec;
|
||||
|
||||
cargoLinkerEnv = lib.strings.toUpper "CARGO_TARGET_${rustTargetSpecUnderscored}_LINKER";
|
||||
cargoCcEnv = "CC_${rustTargetSpecUnderscored}"; # for ring
|
||||
|
||||
cc = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc";
|
||||
in
|
||||
{
|
||||
name = crossSystem;
|
||||
value = {
|
||||
inherit rustTargetSpec cc;
|
||||
pkgs = pkgsCross;
|
||||
env = {
|
||||
"${cargoLinkerEnv}" = cc;
|
||||
"${cargoCcEnv}" = cc;
|
||||
};
|
||||
};
|
||||
};
|
||||
systems = lib.filter (s: s == system || lib.hasInfix "linux" s) supportedSystems;
|
||||
in
|
||||
builtins.listToAttrs (map makeCrossPlatform systems);
|
||||
|
||||
cargoTargets = lib.mapAttrsToList (_: p: p.rustTargetSpec) crossPlatforms;
|
||||
cargoCrossEnvs = lib.foldl (acc: p: acc // p.env) { } (builtins.attrValues crossPlatforms);
|
||||
|
||||
buildFor = system:
|
||||
let
|
||||
crossPlatform = crossPlatforms.${system};
|
||||
inherit (crossPlatform) pkgs;
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rustNightly;
|
||||
crateName = craneLib.crateNameFromCargoToml {
|
||||
cargoToml = ./Cargo.toml;
|
||||
};
|
||||
|
||||
src = nix-gitignore.gitignoreSource [ ] ./.;
|
||||
|
||||
commonArgs = {
|
||||
inherit (crateName) pname version;
|
||||
inherit src;
|
||||
|
||||
buildInputs = with pkgs; [ ]
|
||||
++ lib.optionals pkgs.stdenv.isDarwin darwinFrameworks;
|
||||
|
||||
nativeBuildInputs = with pkgs; [ ]
|
||||
# The Rust toolchain from rust-overlay has a dynamic libiconv in depsTargetTargetPropagated
|
||||
# Our static libiconv needs to take precedence
|
||||
++ lib.optionals pkgs.stdenv.isDarwin [
|
||||
libiconv
|
||||
];
|
||||
|
||||
cargoExtraArgs = "--target ${crossPlatform.rustTargetSpec}";
|
||||
|
||||
cargoVendorDir = craneLib.vendorMultipleCargoDeps {
|
||||
inherit (craneLib.findCargoFiles src) cargoConfigs;
|
||||
cargoLockList = [
|
||||
./Cargo.lock
|
||||
"${rustNightly.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/Cargo.lock"
|
||||
];
|
||||
};
|
||||
} // crossPlatform.env;
|
||||
|
||||
crate = craneLib.buildPackage (commonArgs // {
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
} // lib.optionalAttrs (!stdenv.isDarwin) {
|
||||
allowedRequisites = [ ];
|
||||
});
|
||||
in
|
||||
crate;
|
||||
in
|
||||
{
|
||||
inherit crossPlatforms cargoTargets cargoCrossEnvs rustNightly;
|
||||
|
||||
flake-checker = buildFor system;
|
||||
}
|
121
flake.lock
121
flake.lock
@ -2,46 +2,21 @@
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"flake-compat"
|
||||
],
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-overlay": "rust-overlay"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1697588719,
|
||||
"narHash": "sha256-n9ALgm3S+ygpzjesBkB9qutEtM4dtIkhn8WnstCPOew=",
|
||||
"rev": "da6b58e270d339a78a6e95728012ec2eea879612",
|
||||
"revCount": 440,
|
||||
"lastModified": 1717383740,
|
||||
"narHash": "sha256-559HbY4uhNeoYvK3H6AMZAtVfmR3y8plXZ1x6ON/cWU=",
|
||||
"rev": "b65673fce97d277934488a451724be94cc62499a",
|
||||
"revCount": 580,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/ipetkov/crane/0.14.3/018b402e-8337-76a6-9764-1748a79a54fd/source.tar.gz"
|
||||
"url": "https://api.flakehub.com/f/pinned/ipetkov/crane/0.17.3/018fdc0e-176b-7a0f-92ce-cc2d0db7b735/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/ipetkov/crane/0.14.%2A"
|
||||
}
|
||||
},
|
||||
"fenix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719815435,
|
||||
"narHash": "sha256-K2xFp142onP35jcx7li10xUxNVEVRWjAdY8DSuR7Naw=",
|
||||
"rev": "ebfe2c639111d7e82972a12711206afaeeda2450",
|
||||
"revCount": 1924,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/nix-community/fenix/0.1.1924%2Brev-ebfe2c639111d7e82972a12711206afaeeda2450/01906d5e-442a-7bca-a2c1-55121965b1a0/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/nix-community/fenix/0.1.%2A"
|
||||
"url": "https://flakehub.com/f/ipetkov/crane/0.17.%2A"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
@ -55,39 +30,7 @@
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/edolstra/flake-compat/%2A"
|
||||
}
|
||||
},
|
||||
"flake-schemas": {
|
||||
"locked": {
|
||||
"lastModified": 1697467827,
|
||||
"narHash": "sha256-j8SR19V1SRysyJwpOBF4TLuAvAjF5t+gMiboN4gYQDU=",
|
||||
"rev": "764932025c817d4e500a8d2a4d8c565563923d29",
|
||||
"revCount": 29,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.2/018b3da8-4cc3-7fbb-8ff7-1588413c53e2/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
"url": "https://flakehub.com/f/edolstra/flake-compat/1.0.1"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
@ -107,46 +50,23 @@
|
||||
"root": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"fenix": "fenix",
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-schemas": "flake-schemas",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1719760370,
|
||||
"narHash": "sha256-fsxAuW6RxKZYjAP3biUC6C4vaYFhDfWv8lp1Tmx3ZCY=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "ea7fdada6a0940b239ddbde2048a4d7dac1efe1e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "rust-lang",
|
||||
"ref": "nightly",
|
||||
"repo": "rust-analyzer",
|
||||
"type": "github"
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"flake-utils": [
|
||||
"crane",
|
||||
"flake-utils"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"crane",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1696299134,
|
||||
"narHash": "sha256-RS77cAa0N+Sfj5EmKbm5IdncNXaBCE1BSSQvUE8exvo=",
|
||||
"lastModified": 1719800573,
|
||||
"narHash": "sha256-9DLgG4T6l7cc4pJNOCcXGUwHsFfUp8KLsiwed65MdHk=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "611ccdceed92b4d94ae75328148d84ee4a5b462d",
|
||||
"rev": "648b25dd9c3acd255dc50c1eb3ca8b987856f675",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -154,21 +74,6 @@
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
75
flake.nix
75
flake.nix
@ -2,73 +2,43 @@
|
||||
inputs = {
|
||||
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2405.*";
|
||||
|
||||
fenix = {
|
||||
url = "https://flakehub.com/f/nix-community/fenix/0.1.*";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
crane = {
|
||||
url = "https://flakehub.com/f/ipetkov/crane/0.14.*";
|
||||
url = "https://flakehub.com/f/ipetkov/crane/0.17.*";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.flake-compat.follows = "flake-compat";
|
||||
};
|
||||
|
||||
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/*";
|
||||
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*";
|
||||
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.0.1";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, fenix, crane, flake-schemas, ... }:
|
||||
outputs = { self, nixpkgs, rust-overlay, crane, ... }:
|
||||
let
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec {
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlays.default ];
|
||||
overlays = [
|
||||
rust-overlay.overlays.default
|
||||
];
|
||||
};
|
||||
|
||||
cranePkgs = pkgs.callPackage ./crane.nix {
|
||||
inherit crane supportedSystems;
|
||||
darwinFrameworks = with pkgs.darwin.apple_sdk.frameworks; [ Security SystemConfiguration ];
|
||||
};
|
||||
});
|
||||
meta = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package;
|
||||
in
|
||||
{
|
||||
inherit (flake-schemas) schemas;
|
||||
|
||||
overlays.default = final: prev: rec {
|
||||
system = final.stdenv.hostPlatform.system;
|
||||
rustToolchain = with fenix.packages.${system};
|
||||
combine ([
|
||||
stable.clippy
|
||||
stable.rustc
|
||||
stable.cargo
|
||||
stable.rustfmt
|
||||
stable.rust-src
|
||||
stable.rust-analyzer-preview
|
||||
] ++ nixpkgs.lib.optionals (system == "x86_64-linux") [
|
||||
targets.x86_64-unknown-linux-musl.stable.rust-std
|
||||
] ++ nixpkgs.lib.optionals (system == "aarch64-linux") [
|
||||
targets.aarch64-unknown-linux-musl.stable.rust-std
|
||||
]);
|
||||
craneLib = (crane.mkLib final).overrideToolchain rustToolchain;
|
||||
darwinInputs = final.lib.optionals final.stdenv.isDarwin (with final.darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]);
|
||||
};
|
||||
|
||||
packages = forAllSystems ({ pkgs }: rec {
|
||||
packages = forAllSystems ({ cranePkgs, ... }: rec {
|
||||
inherit (cranePkgs) flake-checker;
|
||||
default = flake-checker;
|
||||
|
||||
flake-checker =
|
||||
let
|
||||
args = {
|
||||
pname = meta.name;
|
||||
inherit (meta) version;
|
||||
src = self;
|
||||
doCheck = true;
|
||||
buildInputs = with pkgs; [ iconv ] ++ pkgs.darwinInputs;
|
||||
};
|
||||
in
|
||||
pkgs.craneLib.buildPackage (args // {
|
||||
cargoArtifacts = pkgs.craneLib.buildDepsOnly args;
|
||||
});
|
||||
});
|
||||
|
||||
devShells = forAllSystems ({ pkgs }: {
|
||||
devShells = forAllSystems ({ pkgs, cranePkgs }: {
|
||||
default =
|
||||
let
|
||||
check-nixpkgs-fmt = pkgs.writeShellApplication {
|
||||
@ -80,12 +50,12 @@
|
||||
};
|
||||
check-rustfmt = pkgs.writeShellApplication {
|
||||
name = "check-rustfmt";
|
||||
runtimeInputs = with pkgs; [ rustToolchain ];
|
||||
runtimeInputs = [ cranePkgs.rustNightly ];
|
||||
text = "cargo fmt --check";
|
||||
};
|
||||
get-allowed-refs = pkgs.writeShellApplication {
|
||||
name = "get-allowed-refs";
|
||||
runtimeInputs = with pkgs; [ rustToolchain ];
|
||||
runtimeInputs = [ cranePkgs.rustNightly ];
|
||||
text = "cargo run --features allowed-refs -- --get-allowed-refs";
|
||||
};
|
||||
in
|
||||
@ -94,13 +64,12 @@
|
||||
bashInteractive
|
||||
|
||||
# Rust
|
||||
rustToolchain
|
||||
cranePkgs.rustNightly
|
||||
cargo-bloat
|
||||
cargo-edit
|
||||
cargo-machete
|
||||
bacon
|
||||
cargo-watch
|
||||
rust-analyzer
|
||||
iconv
|
||||
|
||||
# Nix
|
||||
nixpkgs-fmt
|
||||
@ -111,11 +80,11 @@
|
||||
|
||||
# Scripts
|
||||
get-allowed-refs
|
||||
]) ++ pkgs.darwinInputs;
|
||||
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]);
|
||||
|
||||
env = {
|
||||
# Required by rust-analyzer
|
||||
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
|
||||
RUST_SRC_PATH = "${cranePkgs.rustNightly}/lib/rustlib/src/rust/library";
|
||||
};
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user