From 35316c820b39635e8feb23badfd578533b84a445 Mon Sep 17 00:00:00 2001 From: Craige McWhirter Date: Tue, 26 Nov 2019 22:37:23 +1000 Subject: [PATCH] Added niv --- nix/sources.json | 26 +++++++ nix/sources.nix | 130 +++++++++++++++++++++++++++++++++++ overlays/default.nix | 2 + overlays/niv.nix | 3 + overlays/overlay-list.nix | 3 + roles/{IOHK.nix => iohk.nix} | 0 6 files changed, 164 insertions(+) create mode 100644 nix/sources.json create mode 100644 nix/sources.nix create mode 100644 overlays/default.nix create mode 100644 overlays/niv.nix create mode 100644 overlays/overlay-list.nix rename roles/{IOHK.nix => iohk.nix} (100%) diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..23640b2 --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,26 @@ +{ + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "c25268460b72cea5b7294354ab019997530a6f3d", + "sha256": "1fgq1nkycm54f431h6wflh6rr7xsq3q2fq9drbgra2fnrsyn65ll", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/c25268460b72cea5b7294354ab019997530a6f3d.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "nixos-19.09", + "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", + "homepage": "https://github.com/NixOS/nixpkgs", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "e1843646b04fb564abf6330a9432a76df3269d2f", + "sha256": "1h1nv7bb6j0ccx8v0sz3gcwl1jqz3v2bb13ham0ky0rg9cvdv91h", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/e1843646b04fb564abf6330a9432a76df3269d2f.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000..b7be13a --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,130 @@ +# This file has been generated by Niv. + +# A record, from name to path, of the third-party packages +with rec +{ + pkgs = + if hasNixpkgsPath + then + if hasThisAsNixpkgsPath + then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {} + else import {} + else + import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; + + sources_nixpkgs = + 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. + ''; + + sources_gitignore = + if builtins.hasAttr "gitignore" sources + then sources.gitignore + else abort + '' + Please add "gitignore" to your sources.json: + niv add hercules-ci/gitignore + ''; + + inherit (import (builtins_fetchTarball { inherit (sources_gitignore) url sha256; }) { + inherit (pkgs) lib; + }) gitignoreSource; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = + { url, sha256 ? null }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if sha256 == null || lessThan nixVersion "1.12" then + fetchTarball { inherit url; } + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = + { url, sha256 ? null }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if sha256 == null || lessThan nixVersion "1.12" then + fetchurl { inherit url; } + else + fetchurl attrs; + + # A wrapper around pkgs.fetchzip that has inspectable arguments, + # annoyingly this means we have to specify them + fetchzip = { url, sha256 ? null }@attrs: if sha256 == null + then builtins.fetchTarball { inherit url; } + else pkgs.fetchzip attrs; + + # A wrapper around pkgs.fetchurl that has inspectable arguments, + # annoyingly this means we have to specify them + fetchurl = { url, sha256 }@attrs: pkgs.fetchurl attrs; + + hasNixpkgsPath = (builtins.tryEval ).success; + hasThisAsNixpkgsPath = + (builtins.tryEval ).success && == ./.; + + sources = builtins.fromJSON (builtins.readFile ./sources.json); + + mapAttrs = builtins.mapAttrs or + (f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))); + + # borrowed from nixpkgs + functionArgs = f: f.__functionArgs or (builtins.functionArgs f); + callFunctionWith = autoArgs: f: args: + let auto = builtins.intersectAttrs (functionArgs f) autoArgs; + in f (auto // args); + + getFetcher = spec: + let fetcherName = + if builtins.hasAttr "type" spec + then builtins.getAttr "type" spec + else "builtin-tarball"; + in builtins.getAttr fetcherName { + "tarball" = fetchzip; + "builtin-tarball" = builtins_fetchTarball; + "file" = fetchurl; + "builtin-url" = builtins_fetchurl; + }; +}; +# NOTE: spec must _not_ have an "outPath" attribute +mapAttrs (name: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + let + host = if (name == "nixpkgs") then "custom_nixpkgs" else name; + tryFromPath = builtins.tryEval (builtins.findFile builtins.nixPath host); + defaultSpec = (if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec + then spec // + { outPath = callFunctionWith spec (getFetcher spec) { }; } + else spec) // (if tryFromPath.success + then let path = tryFromPath.value; + in { + outPath = builtins.trace "using search host <${host}>" ( + if pkgs.lib.hasPrefix "/nix/store" (builtins.toString path) + then path else gitignoreSource path); + } + else {}); + in if builtins.hasAttr "rev" spec && builtins.hasAttr "url" spec then + defaultSpec // + { revOverride = rev: if (rev == null) then defaultSpec else + let + spec' = removeAttrs (spec // { + rev = rev; + url = builtins.replaceStrings [defaultSpec.rev] [rev] defaultSpec.url; + }) [ "sha256" ]; + in + spec' // + { outPath = callFunctionWith spec' (getFetcher spec') { }; }; + } + else defaultSpec + ) sources diff --git a/overlays/default.nix b/overlays/default.nix new file mode 100644 index 0000000..a75f07e --- /dev/null +++ b/overlays/default.nix @@ -0,0 +1,2 @@ +sourcePaths: map import (import ./overlay-list.nix) ++ + [(self: super: { inherit sourcePaths; })] diff --git a/overlays/niv.nix b/overlays/niv.nix new file mode 100644 index 0000000..d884256 --- /dev/null +++ b/overlays/niv.nix @@ -0,0 +1,3 @@ +self: super: { + inherit (import self.sourcePaths.niv {}) niv; +} diff --git a/overlays/overlay-list.nix b/overlays/overlay-list.nix new file mode 100644 index 0000000..3f7d6a2 --- /dev/null +++ b/overlays/overlay-list.nix @@ -0,0 +1,3 @@ +[ + ./niv.nix +] diff --git a/roles/IOHK.nix b/roles/iohk.nix similarity index 100% rename from roles/IOHK.nix rename to roles/iohk.nix