From 744ca87ed01ef0ee02e62c12340c1071351e561f Mon Sep 17 00:00:00 2001 From: piegames Date: Sat, 14 May 2022 00:03:59 +0200 Subject: [PATCH] npins: Init at 0.1.0 --- pkgs/tools/nix/npins/default.nix | 44 ++++++++++++++++++++++++ pkgs/tools/nix/npins/source.nix | 57 +++++++++++++++++++++++++++++++ pkgs/tools/nix/npins/sources.json | 19 +++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 4 files changed, 122 insertions(+) create mode 100644 pkgs/tools/nix/npins/default.nix create mode 100644 pkgs/tools/nix/npins/source.nix create mode 100644 pkgs/tools/nix/npins/sources.json diff --git a/pkgs/tools/nix/npins/default.nix b/pkgs/tools/nix/npins/default.nix new file mode 100644 index 00000000000..8324a2d8900 --- /dev/null +++ b/pkgs/tools/nix/npins/default.nix @@ -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 {}; +} diff --git a/pkgs/tools/nix/npins/source.nix b/pkgs/tools/nix/npins/source.nix new file mode 100644 index 00000000000..8c9e47204af --- /dev/null +++ b/pkgs/tools/nix/npins/source.nix @@ -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 diff --git a/pkgs/tools/nix/npins/sources.json b/pkgs/tools/nix/npins/sources.json new file mode 100644 index 00000000000..0481abe3f97 --- /dev/null +++ b/pkgs/tools/nix/npins/sources.json @@ -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 +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c3226537e8b..69a39d05db9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -4019,6 +4019,8 @@ with pkgs; notify = callPackage ../tools/misc/notify { }; + npins = callPackage ../tools/nix/npins { }; + nrsc5 = callPackage ../applications/misc/nrsc5 { }; nsync = callPackage ../development/libraries/nsync { };