switch from fenix to buildRustPackage

Build dependencies are no longer cached, which slows down the build,
but at least it fixes the build in CI.

This simplifies the maintainance as it brings the build closer to the nixpkgs version
This commit is contained in:
Jörg Thalheim 2024-08-14 05:15:05 +02:00
parent a3f275a2f0
commit 2201657246
4 changed files with 132 additions and 237 deletions

91
default.nix Normal file
View File

@ -0,0 +1,91 @@
{ lib
, rustPlatform
, curl
, installShellFiles
, pkg-config
, bzip2
, libgit2
, openssl
, zlib
, zstd
, stdenv
, darwin
, spdx-license-list-data
, nix
, nurl
, get-nix-license
, license-store-cache
}:
rustPlatform.buildRustPackage rec {
pname = "nix-init";
version = "0.3.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = [
curl
installShellFiles
pkg-config
];
buildInputs = [
bzip2
curl
libgit2
openssl
zlib
zstd
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
] ++ lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [
darwin.apple_sdk.frameworks.CoreFoundation
];
buildNoDefaultFeatures = true;
checkFlags = [
# requires internet access
"--skip=lang::rust::tests"
];
postPatch = ''
mkdir -p data
ln -s ${get-nix-license} data/get_nix_license.rs
'';
shellHook = ''
mkdir -p data
ln -sf ${get-nix-license} data/get_nix_license.rs
ln -sf ${license-store-cache} data/license-store-cache.zstd
'';
preBuild = ''
cargo run -p license-store-cache \
-j $NIX_BUILD_CORES --frozen \
data/license-store-cache.zstd ${spdx-license-list-data.json}/json/details
'';
postInstall = ''
installManPage artifacts/nix-init.1
installShellCompletion artifacts/nix-init.{bash,fish} --zsh artifacts/_nix-init
'';
env = {
GEN_ARTIFACTS = "artifacts";
LIBGIT2_NO_VENDOR = 1;
NIX = lib.getExe nix;
NURL = lib.getExe nurl;
ZSTD_SYS_USE_PKG_CONFIG = true;
};
meta = {
description = "Command line tool to generate Nix packages from URLs";
mainProgram = "nix-init";
homepage = "https://github.com/nix-community/nix-init";
changelog = "https://github.com/nix-community/nix-init/blob/${src.rev}/CHANGELOG.md";
license = lib.licenses.mpl20;
maintainers = with lib.maintainers; [ figsoda ];
};
}

View File

@ -1,46 +1,5 @@
{
"nodes": {
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1707685877,
"narHash": "sha256-XoXRS+5whotelr1rHiZle5t5hDg9kpguS5yk8c8qzOc=",
"owner": "ipetkov",
"repo": "crane",
"rev": "2c653e4478476a52c6aa3ac0495e4dea7449ea0e",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": []
},
"locked": {
"lastModified": 1708323807,
"narHash": "sha256-ruXYKlIAuvSIyaV6DsoYFqtcSWIS8x4QbtZ4lZyn5no=",
"owner": "nix-community",
"repo": "fenix",
"rev": "cacd01c5149b8b1f9ec0e667c551f0fbcd6edd0f",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
@ -48,11 +7,11 @@
]
},
"locked": {
"lastModified": 1706830856,
"narHash": "sha256-a0NYyp+h9hlb7ddVz4LUn1vT/PLwqfrWYcHMvFB1xYg=",
"lastModified": 1722555600,
"narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "b253292d9c0a5ead9bc98c4e9a26c6312e27d69f",
"rev": "8471fe90ad337a8074e957b69ca4d0089218391d",
"type": "github"
},
"original": {
@ -63,11 +22,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1708118438,
"narHash": "sha256-kk9/0nuVgA220FcqH/D2xaN6uGyHp/zoxPNUmPCMmEE=",
"lastModified": 1723362943,
"narHash": "sha256-dFZRVSgmJkyM0bkPpaYRtG/kRMRTorUIDj8BxoOt1T4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5863c27340ba4de8f83e7e3c023b9599c3cb3c80",
"rev": "a58bc8ad779655e790115244571758e8de055e3d",
"type": "github"
},
"original": {
@ -79,8 +38,6 @@
},
"root": {
"inputs": {
"crane": "crane",
"fenix": "fenix",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}

198
flake.nix
View File

@ -2,15 +2,7 @@
description = "Generate Nix packages from URLs with hash prefetching, dependency inference, license detection, and more";
inputs = {
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
@ -18,7 +10,8 @@
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = inputs@{ crane, flake-parts, ... }:
outputs =
inputs@{ flake-parts, treefmt-nix, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
@ -27,186 +20,15 @@
"x86_64-linux"
];
perSystem = { inputs', lib, pkgs, self', system, ... }:
let
inherit (builtins)
attrValues
getAttr
listToAttrs
readDir
;
inherit (lib)
concatMapAttrs
flip
getExe
hasSuffix
importTOML
licenses
maintainers
nameValuePair
optionalAttrs
optionals
pipe
sourceByRegex
;
inherit (crane.lib.${system}.overrideToolchain inputs'.fenix.packages.default.toolchain)
buildDepsOnly
buildPackage
cargoClippy
cargoFmt
cargoNextest
;
inherit (pkgs)
bzip2
callPackage
curl
darwin
installShellFiles
libgit2
libiconv
mkShell
nix
nixpkgs-fmt
nurl
openssl
pkg-config
spdx-license-list-data
stdenv
zlib
zstd
;
src = sourceByRegex ./. [
"(license-store-cache|src)(/.*)?"
''Cargo\.(toml|lock)''
''build\.rs''
''rustfmt\.toml''
];
get-nix-license = callPackage ./src/get_nix_license.nix { };
license-store-cache = buildPackage {
pname = "license-store-cache";
inherit src;
buildInputs = optionals stdenv.isDarwin [
libiconv
];
doCheck = false;
doNotRemoveReferencesToVendorDir = true;
cargoArtifacts = null;
cargoExtraArgs = "-p license-store-cache";
CARGO_PROFILE = "";
postInstall = ''
cache=$(mktemp)
$out/bin/license-store-cache $cache ${spdx-license-list-data.json}/json/details
rm -rf $out
mv $cache $out
'';
};
args = {
inherit src;
nativeBuildInputs = [
curl
installShellFiles
pkg-config
];
buildInputs = [
bzip2
curl
libgit2
openssl
zlib
zstd
] ++ optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.SystemConfiguration
] ++ optionals (stdenv.isDarwin && stdenv.isx86_64) [
darwin.apple_sdk.frameworks.CoreFoundation
];
cargoArtifacts = buildDepsOnly args;
cargoExtraArgs = "--no-default-features";
doInstallCargoArtifacts = false;
postPatch = ''
mkdir -p data
ln -s ${get-nix-license} data/get_nix_license.rs
ln -s ${license-store-cache} data/license-store-cache.zstd
'';
env = {
GEN_ARTIFACTS = "artifacts";
NIX = getExe nix;
NURL = getExe nurl;
ZSTD_SYS_USE_PKG_CONFIG = true;
};
meta = {
license = licenses.mpl20;
maintainers = with maintainers; [ figsoda ];
};
};
in
perSystem =
{ config, pkgs, ... }:
{
checks = {
build = self'.packages.default;
clippy = cargoClippy (args // {
cargoClippyExtraArgs = "-- -D warnings";
});
fmt = cargoFmt (removeAttrs args [ "cargoExtraArgs" ]);
test =
let
fixtures = src + "/src/lang/rust/fixtures";
lock = src + "/Cargo.lock";
getPackages = flip pipe [
importTOML
(getAttr "package")
(map ({ name, version, ... }@pkg:
nameValuePair "${name}-${version}" pkg))
listToAttrs
];
in
cargoNextest (args // {
cargoArtifacts = null;
cargoLock = lock;
cargoLockParsed = importTOML lock // {
package = attrValues (getPackages lock // concatMapAttrs
(name: _: optionalAttrs
(hasSuffix "-lock.toml" name)
(getPackages (fixtures + "/${name}")))
(readDir fixtures));
packages.nix-init = pkgs.callPackage ./default.nix {
inherit (config.packages) get-nix-license license-store-cache;
};
});
};
devShells.default = mkShell {
NIX_INIT_LOG = "nix_init=trace";
RUST_BACKTRACE = true;
shellHook = ''
mkdir -p data
ln -sf ${get-nix-license} data/get_nix_license.rs
ln -sf ${license-store-cache} data/license-store-cache.zstd
'';
};
formatter = nixpkgs-fmt;
packages.default = buildPackage (args // {
doCheck = false;
postInstall = ''
installManPage artifacts/nix-init.1
installShellCompletion artifacts/nix-init.{bash,fish} --zsh artifacts/_nix-init
'';
});
packages.get-nix-license = pkgs.callPackage ./src/get_nix_license.nix { };
packages.license-store-cache = pkgs.callPackage ./license-store-cache.nix { };
packages.default = config.packages.nix-init;
};
};
}

25
license-store-cache.nix Normal file
View File

@ -0,0 +1,25 @@
{
rustPlatform,
stdenv,
libiconv,
lib,
spdx-license-list-data,
}:
rustPlatform.buildRustPackage {
name = "license-store-cache";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
doCheck = false;
cargoBuildFlags = [ "-p license-store-cache" ];
postInstall = ''
cache=$(mktemp)
$out/bin/license-store-cache $cache ${spdx-license-list-data.json}/json/details
rm -rf $out
mv $cache $out
'';
}