Unverified Commit af6a483e authored by Anderson Torres's avatar Anderson Torres Committed by GitHub
Browse files

Merge pull request #213219 from figsoda/nix-init

nix-init: init at 0.1.0
parents 9a3b37a7 44187e2a
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
{ lib
, rustPlatform
, fetchFromGitHub
, installShellFiles
, makeWrapper
, pkg-config
, zstd
, stdenv
, darwin
, nix
, nurl
, callPackage
, spdx-license-list-data
}:

rustPlatform.buildRustPackage rec {
  pname = "nix-init";
  version = "0.1.0";

  src = fetchFromGitHub {
    owner = "nix-community";
    repo = "nix-init";
    rev = "v${version}";
    hash = "sha256-97aAlH03H8xTVhp45FwecNb7i/ZUtJG9OOYBx8Sf+YI=";
  };

  cargoHash = "sha256-uvn1cP6aIxfPKG/QLtHBd6fHjl7JNRtkZ4gIG2tpHVg=";

  nativeBuildInputs = [
    installShellFiles
    makeWrapper
    pkg-config
  ];

  buildInputs = [
    zstd
  ] ++ lib.optionals stdenv.isDarwin [
    darwin.apple_sdk.frameworks.Security
  ];

  postInstall = ''
    wrapProgram $out/bin/nix-init \
      --prefix PATH : ${lib.makeBinPath [ nix nurl ]}
    installManPage artifacts/nix-init.1
    installShellCompletion artifacts/nix-init.{bash,fish} --zsh artifacts/_nix-init
  '';

  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; {
    description = "Command line tool to generate Nix packages from URLs";
    homepage = "https://github.com/nix-community/nix-init";
    changelog = "https://github.com/nix-community/nix-init/blob/${src.rev}/CHANGELOG.md";
    license = licenses.mpl20;
    maintainers = with maintainers; [ figsoda ];
  };
}
+23 −0
Original line number Diff line number Diff line
# vendored from src/licenses.nix

{ lib, writeText }:

let
  inherit (builtins) concatLists concatStringsSep length;
  inherit (lib) flip licenses mapAttrsToList optional;

  inserts = concatLists
    (flip mapAttrsToList licenses
      (k: v: optional (v ? spdxId) ''  xs.insert("${v.spdxId}", "${k}");''));
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
  }
''
+2 −0
Original line number Diff line number Diff line
@@ -37644,6 +37644,8 @@ with pkgs;
  nix-info = callPackage ../tools/nix/info { };
  nix-info-tested = nix-info.override { doCheck = true; };
  nix-init = callPackage ../tools/nix/nix-init { };
  nix-index-unwrapped = callPackage ../tools/package-management/nix-index {
    inherit (darwin.apple_sdk.frameworks) Security;
  };