From f129d39c779f090a2ee1e284f479e1450e767458 Mon Sep 17 00:00:00 2001 From: figsoda Date: Sun, 19 Mar 2023 19:19:23 -0400 Subject: [PATCH] nix-init: 0.1.1 -> 0.2.0 Diff: https://github.com/nix-community/nix-init/compare/v0.1.1...v0.2.0 Changelog: https://github.com/nix-community/nix-init/blob/v0.2.0/CHANGELOG.md --- pkgs/tools/nix/nix-init/default.nix | 50 ++++++++++++++++--- .../{license.nix => get-nix-license.nix} | 28 +++++------ 2 files changed, 56 insertions(+), 22 deletions(-) rename pkgs/tools/nix/nix-init/{license.nix => get-nix-license.nix} (74%) diff --git a/pkgs/tools/nix/nix-init/default.nix b/pkgs/tools/nix/nix-init/default.nix index c60f88022ccc..3453a1b74c66 100644 --- a/pkgs/tools/nix/nix-init/default.nix +++ b/pkgs/tools/nix/nix-init/default.nix @@ -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; { diff --git a/pkgs/tools/nix/nix-init/license.nix b/pkgs/tools/nix/nix-init/get-nix-license.nix similarity index 74% rename from pkgs/tools/nix/nix-init/license.nix rename to pkgs/tools/nix/nix-init/get-nix-license.nix index 0a1ad4fce122..2aa514bd3465 100644 --- a/pkgs/tools/nix/nix-init/license.nix +++ b/pkgs/tools/nix/nix-init/get-nix-license.nix @@ -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, + } } ''