Merge pull request #172934 from piegamesde/npins

npins: Init at 0.1.0
This commit is contained in:
maralorn 2022-05-17 19:31:46 +02:00 committed by GitHub
commit a03776647d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 0 deletions

View file

@ -0,0 +1,44 @@
{ lib
, rustPlatform
, fetchFromGitHub
, nix-gitignore
, makeWrapper
, stdenv
, darwin
, callPackage
# runtime dependencies
, nix # for nix-prefetch-url
, nix-prefetch-git
, git # for git ls-remote
}:
let
runtimePath = lib.makeBinPath [ nix nix-prefetch-git git ];
sources = (builtins.fromJSON (builtins.readFile ./sources.json)).pins;
in rustPlatform.buildRustPackage rec {
pname = "npins";
version = src.version;
src = passthru.mkSource sources.npins;
cargoSha256 = "0rwnzkmx91cwcz9yw0rbbqv73ba6ggim9f4qgz5pgy6h696ld2k8";
buildInputs = lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security ]);
nativeBuildInputs = [ makeWrapper ];
# (Almost) all tests require internet
doCheck = false;
postFixup = ''
wrapProgram $out/bin/npins --prefix PATH : "${runtimePath}"
'';
meta = with lib; {
description = "Simple and convenient dependency pinning for Nix";
homepage = "https://github.com/andir/npins";
license = licenses.eupl12;
maintainers = with maintainers; [ piegames ];
};
passthru.mkSource = callPackage ./source.nix {};
}

View file

@ -0,0 +1,57 @@
# Not part of the public API for use within nixpkgs only
#
# Usage:
# ```nix
# let
# sources = builtins.fromJSON (builtins.readFile ./sources.json);
# in mkMyDerivation rec {
# version = src.version; # This obviously only works for releases
# src = pkgs.npins.mkSource sources.mySource;
# }
# ```
{ fetchgit
, fetchzip
, fetchurl
}:
let
mkSource = spec:
assert spec ? type; let
path =
if spec.type == "Git" then mkGitSource spec
else if spec.type == "GitRelease" then mkGitSource spec
else if spec.type == "PyPi" then mkPyPiSource spec
else if spec.type == "Channel" then mkChannelSource spec
else throw "Unknown source type ${spec.type}";
in
spec // { outPath = path; };
mkGitSource = { repository, revision, url ? null, hash, ... }:
assert repository ? type;
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
# In the latter case, there we will always be an url to the tarball
if url != null then
(fetchzip {
inherit url;
sha256 = hash;
extension = "tar";
})
else assert repository.type == "Git"; fetchgit {
url = repository.url;
rev = revision;
};
mkPyPiSource = { url, hash, ... }:
fetchurl {
inherit url;
sha256 = hash;
};
mkChannelSource = { url, hash, ... }:
fetchzip {
inherit url;
sha256 = hash;
extension = "tar";
};
in
mkSource

View file

@ -0,0 +1,19 @@
{
"pins": {
"npins": {
"type": "GitRelease",
"repository": {
"type": "GitHub",
"owner": "andir",
"repo": "npins"
},
"pre_releases": false,
"version_upper_bound": null,
"version": "0.1.0",
"revision": "5c9253ff6010f435ab73fbe1e50ae0fdca0ec07b",
"url": "https://api.github.com/repos/andir/npins/tarball/0.1.0",
"hash": "019fr9xsirld8kap75k18in3krkikqhjn4mglpy3lyhbhc5n1kh6"
}
},
"version": 2
}

View file

@ -4015,6 +4015,8 @@ with pkgs;
notify = callPackage ../tools/misc/notify { };
npins = callPackage ../tools/nix/npins { };
nrsc5 = callPackage ../applications/misc/nrsc5 { };
nsync = callPackage ../development/libraries/nsync { };