diff --git a/nix/sources.json b/nix/sources.json index f5de360..d180d33 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -1,61 +1,15 @@ { - "nixpkgs": { - "url": "https://github.com/NixOS/nixpkgs-channels/archive/7bb74e653654dbf9206e751574b5132b15f46bb5.tar.gz", - "owner": "NixOS", - "branch": "nixos-19.03", - "url_template": "https://github.com///archive/.tar.gz", - "repo": "nixpkgs-channels", - "type": "tarball", - "sha256": "1dbdy4f58yqz4l67n032184rx7ci94hx3wl52c8h2bg06awkzq87", - "description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels", - "rev": "7bb74e653654dbf9206e751574b5132b15f46bb5" - }, "all-hies": { + "branch": "master", + "description": "Cached Haskell IDE Engine Nix builds for all GHC versions", "homepage": "", - "url": "https://github.com/Infinisil/all-hies/archive/b06fdd252c71404ace1eea5e09b562bcf7f834f7.tar.gz", "owner": "Infinisil", - "branch": "master", - "url_template": "https://github.com///archive/.tar.gz", "repo": "all-hies", - "type": "tarball", + "rev": "b06fdd252c71404ace1eea5e09b562bcf7f834f7", "sha256": "1gzipcmhm6xbfjdjx3i4057vysmvrm6xykx9aplj3wcwmk3bhmdy", - "description": "Cached Haskell IDE Engine Nix builds for all GHC versions", - "rev": "b06fdd252c71404ace1eea5e09b562bcf7f834f7" - }, - "unstable": { - "url": "https://github.com/NixOS/nixpkgs-channels/archive/beff2f8d75ef2c65017fb25e251337c6bb2e950d.tar.gz", - "owner": "NixOS", - "branch": "nixos-unstable", - "url_template": "https://github.com///archive/.tar.gz", - "repo": "nixpkgs-channels", - "type": "tarball", - "sha256": "1av1m2mibv9dgfrjv9r8n3ih9dyb0wi594s5xb4c135v121jpzs3", - "description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels", - "rev": "beff2f8d75ef2c65017fb25e251337c6bb2e950d" - }, - "static-haskell-nix": { - "homepage": "", - "url": "https://github.com/nh2/static-haskell-nix/archive/b06f8979bfaa27dc4ce76cbeaa393e0c28b5baef.tar.gz", - "owner": "nh2", - "branch": "master", - "url_template": "https://github.com///archive/.tar.gz", - "repo": "static-haskell-nix", - "type": "tarball", - "sha256": "17f4if6rx7xhsfz1n9i151n7zxf82p08nmyml24fb1axi9j6ya38", - "description": "easily build most Haskell programs into fully static Linux executables", - "rev": "b06f8979bfaa27dc4ce76cbeaa393e0c28b5baef" - }, - "niv": { - "homepage": "https://github.com/nmattia/niv", - "url": "https://github.com/nmattia/niv/archive/5d9e3a5f7d51765f0369a4682770ec57d863f19f.tar.gz", - "owner": "nmattia", - "branch": "master", - "url_template": "https://github.com///archive/.tar.gz", - "repo": "niv", "type": "tarball", - "sha256": "0x7d2rb89h0h7g8sjsgax6ncvf2wwbmxkgvlfi53d00kxj6kfzba", - "description": "Easy dependency management for Nix projects", - "rev": "5d9e3a5f7d51765f0369a4682770ec57d863f19f" + "url": "https://github.com/Infinisil/all-hies/archive/b06fdd252c71404ace1eea5e09b562bcf7f834f7.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" }, "bootstrap": { "sha256": "0dldiln2s3z8iqc5ccjid2i5gh9527naas064bwly8x9lrfrxcb0", @@ -70,5 +24,51 @@ "url": "https://cdnjs.cloudflare.com/ajax/libs/d3/5.15.0/d3.min.js", "url_template": "https://cdnjs.cloudflare.com/ajax/libs/d3//d3.min.js", "version": "5.15.0" + }, + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "2ecfd86b631714b457e56d70dd83fa60435baeb6", + "sha256": "01j6727cws8blg1npp54b4w6xa0gpgyzhyws2vqgp8clnlnmqqhi", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/2ecfd86b631714b457e56d70dd83fa60435baeb6.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "nixos-19.03", + "description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "7bb74e653654dbf9206e751574b5132b15f46bb5", + "sha256": "1dbdy4f58yqz4l67n032184rx7ci94hx3wl52c8h2bg06awkzq87", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/7bb74e653654dbf9206e751574b5132b15f46bb5.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "static-haskell-nix": { + "branch": "master", + "description": "easily build most Haskell programs into fully static Linux executables", + "homepage": "", + "owner": "nh2", + "repo": "static-haskell-nix", + "rev": "b06f8979bfaa27dc4ce76cbeaa393e0c28b5baef", + "sha256": "17f4if6rx7xhsfz1n9i151n7zxf82p08nmyml24fb1axi9j6ya38", + "type": "tarball", + "url": "https://github.com/nh2/static-haskell-nix/archive/b06f8979bfaa27dc4ce76cbeaa393e0c28b5baef.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "unstable": { + "branch": "nixos-unstable", + "description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "beff2f8d75ef2c65017fb25e251337c6bb2e950d", + "sha256": "1av1m2mibv9dgfrjv9r8n3ih9dyb0wi594s5xb4c135v121jpzs3", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/beff2f8d75ef2c65017fb25e251337c6bb2e950d.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/nix/sources.nix b/nix/sources.nix index dc040f8..6e2bf23 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -1,67 +1,138 @@ # This file has been generated by Niv. -# A record, from name to path, of the third-party packages -with rec -{ - pkgs = +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: spec: + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; } + else + pkgs.fetchurl { inherit (spec) url sha256; }; + + fetch_tarball = pkgs: spec: + if spec.builtin or true then + builtins_fetchTarball { inherit (spec) url sha256; } + else + pkgs.fetchzip { inherit (spec) url sha256; }; + + fetch_git = spec: + builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; + + fetch_builtin-tarball = spec: + builtins.trace + '' + WARNING: + The niv type "builtin-tarball" will soon be deprecated. You should + instead use `builtin = true`. + + $ niv modify -a type=tarball -a builtin=true + '' + builtins_fetchTarball { inherit (spec) url sha256; }; + + fetch_builtin-url = spec: + builtins.trace + '' + WARNING: + The niv type "builtin-url" will soon be deprecated. You should + instead use `builtin = true`. + + $ niv modify -a type=file -a builtin=true + '' + (builtins_fetchurl { inherit (spec) url sha256; }); + + # + # Various helpers + # + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: if hasNixpkgsPath then - if hasThisAsNixpkgsPath - then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {} - else import {} + if hasThisAsNixpkgsPath + then import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {} + else import {} else - import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; + import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {}; - sources_nixpkgs = + mkNixpkgs = sources: if builtins.hasAttr "nixpkgs" sources then sources.nixpkgs else abort - '' + '' Please specify either (through -I or NIX_PATH=nixpkgs=...) or add a package called "nixpkgs" to your sources.json. - ''; - - builtins_fetchTarball = - # fetchTarball version that is compatible between all the versions of - # Nix - { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball { inherit url; } - else - fetchTarball attrs; + ''; hasNixpkgsPath = (builtins.tryEval ).success; hasThisAsNixpkgsPath = (builtins.tryEval ).success && == ./.; - sources = builtins.fromJSON (builtins.readFile ./sources.json); + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs spec + else if spec.type == "tarball" then fetch_tarball pkgs spec + else if spec.type == "git" then fetch_git spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec + else if spec.type == "builtin-url" then fetch_builtin-url spec + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); - mapAttrs = builtins.mapAttrs or - (f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))); + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball { inherit url; } + else + fetchTarball attrs; - getFetcher = spec: - let fetcherName = - if builtins.hasAttr "type" spec - then builtins.getAttr "type" spec - else "tarball"; - in builtins.getAttr fetcherName { - "tarball" = pkgs.fetchzip; - "file" = pkgs.fetchurl; + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl { inherit url; } + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs ( + name: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = fetch config.pkgs name spec; } + ) config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? ./sources.json + , sources ? builtins.fromJSON (builtins.readFile sourcesFile) + , pkgs ? mkPkgs sources + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; }; -}; -# NOTE: spec must _not_ have an "outPath" attribute -mapAttrs (_: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec - then - spec // - { outPath = getFetcher spec { inherit (spec) url sha256; } ; } - else spec - ) sources +in +mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }