From 97ff96075ba3a82fe55a16fc8b1966add40359bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 4 Aug 2018 17:55:52 +0100 Subject: [PATCH] move repoSource to external file --- default.nix | 50 ++++++++++------------------------------------ lib/repoSource.nix | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 lib/repoSource.nix diff --git a/default.nix b/default.nix index c5fdd8020..d2507eeaa 100644 --- a/default.nix +++ b/default.nix @@ -3,51 +3,21 @@ , pkgs ? null }: let - inherit (nurpkgs) fetchgit fetchzip lib; - manifest = (builtins.fromJSON (builtins.readFile ./repos.json)).repos; lockedRevisions = (builtins.fromJSON (builtins.readFile ./repos.json.lock)).repos; - parseGitlabUrl = url: - with builtins; - let - parts = lib.splitString "/" url; - len = length parts; - in { - domain = elemAt parts 2; - owner = elemAt parts (len - 2); - repo = elemAt parts (len - 1); - }; + inherit (nurpkgs) lib; - repoSource = name: attr: - let - revision = lockedRevisions.${name}; - submodules = attr.submodules or false; - type = attr.type or null; - in if lib.hasPrefix "https://github.com" attr.url && !submodules then - fetchzip { - url = "${attr.url}/archive/${revision.rev}.zip"; - inherit (revision) sha256; - } - else if (lib.hasPrefix "https://gitlab.com" attr.url || type == "gitlab") && !submodules then - let - gitlab = parseGitlabUrl attr.url; - in fetchzip { - url = "https://${gitlab.domain}/api/v4/projects/${gitlab.owner}%2F${gitlab.repo}/repository/archive.tar.gz?sha=${revision.rev}"; - inherit (revision) sha256; - } - else - fetchgit { - inherit (attr) url; - inherit (revision) rev sha256; - fetchSubmodules = submodules; - }; + repoSource = name: attr: import ./lib/repoSource.nix { + inherit name attr manifest lockedRevisions lib; + inherit (nurpkgs) fetchgit fetchzip; + }; - createRepo = name: attr: import ./lib/evalRepo.nix { - inherit name pkgs lib; - inherit (attr) url; - src = repoSource name attr + "/" + (attr.file or ""); - }; + createRepo = name: attr: import ./lib/evalRepo.nix { + inherit name pkgs lib; + inherit (attr) url; + src = repoSource name attr + "/" + (attr.file or ""); + }; in { repos = lib.mapAttrs createRepo manifest; diff --git a/lib/repoSource.nix b/lib/repoSource.nix new file mode 100644 index 000000000..44b7b9868 --- /dev/null +++ b/lib/repoSource.nix @@ -0,0 +1,38 @@ +{ + name, attr, + fetchgit, fetchzip, lib, + manifest, lockedRevisions +}: + +let + parseGitlabUrl = url: with builtins; let + parts = lib.splitString "/" url; + len = length parts; + in { + domain = elemAt parts 2; + owner = elemAt parts (len - 2); + repo = elemAt parts (len - 1); + }; + + revision = lockedRevisions.${name}; + submodules = attr.submodules or false; + type = attr.type or null; +in + if lib.hasPrefix "https://github.com" attr.url && !submodules then + fetchzip { + url = "${attr.url}/archive/${revision.rev}.zip"; + inherit (revision) sha256; + } + else if (lib.hasPrefix "https://gitlab.com" attr.url || type == "gitlab") && !submodules then + let + gitlab = parseGitlabUrl attr.url; + in fetchzip { + url = "https://${gitlab.domain}/api/v4/projects/${gitlab.owner}%2F${gitlab.repo}/repository/archive.tar.gz?sha=${revision.rev}"; + inherit (revision) sha256; + } + else + fetchgit { + inherit (attr) url; + inherit (revision) rev sha256; + fetchSubmodules = submodules; + }