From 6fb0b1ec66e70f997ba129fb0080400538a05a52 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 4 Oct 2019 16:37:39 +0200 Subject: [PATCH] Update nixpkgs via added niv --- nix/default.nix | 5 +-- nix/nixpkgs.nix | 5 --- nix/overlay.nix | 5 +++ nix/sources.json | 26 ++++++++++++++ nix/sources.nix | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 7 deletions(-) delete mode 100644 nix/nixpkgs.nix create mode 100644 nix/sources.json create mode 100644 nix/sources.nix diff --git a/nix/default.nix b/nix/default.nix index c3fd071..12e5b95 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,12 +1,13 @@ /** * This is the entry-point for all nix execution in this project. */ -{ nixpkgsSrc ? ./nixpkgs.nix +{ sources ? import ./sources.nix +, nixpkgsSrc ? sources.nixpkgs , system ? null , ... }: -import (import ./nixpkgs.nix) ({ +import nixpkgsSrc ({ # Makes the config pure as well. See /top-level/impure.nix: config = { }; diff --git a/nix/nixpkgs.nix b/nix/nixpkgs.nix deleted file mode 100644 index 662487c..0000000 --- a/nix/nixpkgs.nix +++ /dev/null @@ -1,5 +0,0 @@ -# to update: $ nix-prefetch-url --unpack url -builtins.fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/bd5e8f35c2e9d1ddc9cd2fea7a23563336d54acb.tar.gz"; - sha256 = "1wnzqqijrwf797nb234q10zb1h7086njradkkrx3a15b303grsw4"; -} diff --git a/nix/overlay.nix b/nix/overlay.nix index 8b5490c..5c3fa01 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -3,6 +3,8 @@ let inherit (self.arion-project) haskellPkgs; inherit (super) lib; + sources = import ./sources.nix; + in { @@ -19,7 +21,10 @@ in haskellPkgs.ghcid super.docker-compose (import ~/h/ghcide-nix {}).ghcide-ghc864 + self.niv ]; }; }; + + inherit (import (sources.niv) {}) niv; } diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..efa1ae1 --- /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": "1dd094156b249586b66c16200ecfd365c7428dc0", + "sha256": "1b2vjnn8iac5iiqszjc2v1s1ygh0yri998c0k3s4x4kn0dsqik21", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/1dd094156b249586b66c16200ecfd365c7428dc0.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "nixos-19.03", + "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": "6420e2649fa9e267481fb78e602022dab9d1dcd1", + "sha256": "1z3hx7gp8nxk3fspi8vik3j9zxpajj3s7nxvjvx3b5igndxwbp74", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/6420e2649fa9e267481fb78e602022dab9d1dcd1.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..d4ac577 --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,93 @@ +# 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. + ''; + + # 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; + + # 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; + + # A wrapper around pkgs.fetchzip that has inspectable arguments, + # annoyingly this means we have to specify them + fetchzip = { url, sha256 }@attrs: 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 (_: 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 = callFunctionWith spec (getFetcher spec) { }; } + else spec + ) sources