figsoda 2023-03-19 19:19:23 -04:00
parent 55dea1bc7a
commit f129d39c77
2 changed files with 56 additions and 22 deletions

View File

@ -1,43 +1,81 @@
{ lib
, writeText
, rustPlatform
, fetchFromGitHub
, curl
, installShellFiles
, makeWrapper
, pkg-config
, bzip2
, libgit2_1_5
, openssl
, zlib
, zstd
, stdenv
, darwin
, spdx-license-list-data
, nix
, nurl
, callPackage
, spdx-license-list-data
}:
let
get-nix-license = import ./get-nix-license.nix {
inherit lib writeText;
};
in
rustPlatform.buildRustPackage rec {
pname = "nix-init";
version = "0.1.1";
version = "0.2.0";
src = fetchFromGitHub {
owner = "nix-community";
repo = "nix-init";
rev = "v${version}";
hash = "sha256-x9UrBCnEGz6nI1XGBLjIeiF3qi3EvynAfafiuhQdt9Q=";
hash = "sha256-/lH8zO6ah7/HVZ7jOxTgs2iKND1UlGP5EQLtx6JsFxo=";
};
cargoHash = "sha256-RUfprANAbj8w8LPRwQEF9SD9fhWb1CEcwbvOa6DX9Xk=";
cargoHash = "sha256-jI/hysUq3JGe0hdZTQQw49BfcTWMx6jg+QAkd1QeBv4=";
nativeBuildInputs = [
curl
installShellFiles
makeWrapper
pkg-config
];
buildInputs = [
bzip2
curl
libgit2_1_5
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;
buildFeatures = [ "reqwest/rustls-tls" ];
checkFlags = [
# requires internet access
"--skip=lang::rust::tests"
];
postPatch = ''
mkdir -p data
ln -s ${get-nix-license} data/get-nix-license.rs
'';
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 = ''
wrapProgram $out/bin/nix-init \
--prefix PATH : ${lib.makeBinPath [ nix nurl ]}
@ -46,8 +84,6 @@ rustPlatform.buildRustPackage rec {
'';
GEN_ARTIFACTS = "artifacts";
NIX_LICENSES = callPackage ./license.nix { };
SPDX_LICENSE_LIST_DATA = "${spdx-license-list-data.json}/json/details";
ZSTD_SYS_USE_PKG_CONFIG = true;
meta = with lib; {

View File

@ -1,10 +1,12 @@
# vendored from src/licenses.nix
# vendored from src/get-nix-license.nix
{ lib, writeText }:
let
inherit (lib)
attrNames
concatMapAttrs
concatStringsSep
filterAttrs
flip
id
@ -14,9 +16,6 @@ let
optionalAttrs
pipe
warn
attrNames
concatStringsSep
length
;
licenseMap = flip concatMapAttrs licenses
@ -60,18 +59,17 @@ let
else
warn "${k}: ${concatStringsSep ", " v}"));
inserts = lint (mapAttrsToList
(k: v: '' xs.insert("${k}", "${v}");'')
(deprecatedAliases // licenseMap));
arms = lint (concatStringsSep "\n "
(mapAttrsToList
(k: v: ''"${k}" => Some("${v}"),'')
(deprecatedAliases // licenseMap)));
in
writeText "license.rs" ''
fn get_nix_licenses() -> rustc_hash::FxHashMap<&'static str, &'static str> {
let mut xs = std::collections::HashMap::with_capacity_and_hasher(
${toString (length inserts)},
Default::default(),
);
${concatStringsSep "\n " inserts}
xs
writeText "get-nix-license.rs" ''
pub fn get_nix_license(license: &str) -> Option<&'static str> {
match license {
${arms}
_ => None,
}
}
''