1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-07 22:36:53 +03:00

Merge pull request #21 from nmattia/nm-map-attrs

Declare mapAttrs on old Nix
This commit is contained in:
Nicolas Mattia 2019-02-22 11:43:40 +01:00 committed by GitHub
commit a75cdd6312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

14
Main.hs
View File

@ -569,35 +569,37 @@ pathNixSourcesNix :: FilePath
pathNixSourcesNix = "nix" </> "sources.nix"
-- | Glue code between nix and sources.json
-- TODO: update this
initNixSourcesNixContent :: String
initNixSourcesNixContent = [s|
# A record, from name to path, of the third-party packages
with
{
versions = builtins.fromJSON (builtins.readFile ./sources.json);
sources = builtins.fromJSON (builtins.readFile ./sources.json);
# fetchTarball version that is compatible between all the versions of Nix
# fetchTarball version that is compatible between all the sources of Nix
fetchTarball =
{ url, sha256 }:
if builtins.lessThan builtins.nixVersion "1.12" then
builtins.fetchTarball { inherit url; }
else
builtins.fetchTarball { inherit url sha256; };
mapAttrs = builtins.mapAttrs or
(f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
};
# NOTE: spec must _not_ have an "outPath" attribute
builtins.mapAttrs (_: spec:
mapAttrs (_: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in versions.json should not have an 'outPath' attribute"
"The values in sources.json should not have an 'outPath' attribute"
else
if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
then
spec //
{ outPath = fetchTarball { inherit (spec) url sha256; } ; }
else spec
) versions
) sources
|]
-- | @nix/default.nix@