Skip to content

Add niv sources at haskell-nix.sources #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ let haskellNix = {
checkMaterialization ? false, # Allows us to easily switch on materialization checking
defaultCompilerNixName ? null, # Quick way to override the default compiler e.g. "ghc883"
system ? builtins.currentSystem,
... }: rec {
sources = {
inherit (import ./nixpkgs/default.nix) nixpkgs-1909 nixpkgs-2003 nixpkgs-default;
};
sourcesOverride ? {},
... }@args: rec {
sources = (import ./nix/sources.nix) // sourcesOverride;

config = import ./config.nix;
overlays = [ allOverlays.combined ] ++ (
Expand All @@ -29,7 +28,7 @@ let haskellNix = {
)]
else []
);
allOverlays = import ./overlays;
allOverlays = import ./overlays args;
nixpkgsArgs = { inherit config overlays system; };
pkgs = import sources.nixpkgs-default nixpkgsArgs;
};
Expand Down
50 changes: 50 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "f73bf8d584148677b01859677a63191c31911eae",
"sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-1909": {
"branch": "nixpkgs-19.09-darwin",
"description": "Nix Packages collection",
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9237a09d8edbae9951a67e9a3434a07ef94035b7",
"sha256": "05bizymljzzd665bpsjbhxamcgzq7bkjjzjfapkl2nicy774ak4x",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/9237a09d8edbae9951a67e9a3434a07ef94035b7.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-2003": {
"branch": "nixpkgs-20.03-darwin",
"description": "Nix Packages collection",
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "cac363c661817666e43d047addfaa722610d425f",
"sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/cac363c661817666e43d047addfaa722610d425f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-default": {
"branch": "nixpkgs-20.03-darwin",
"description": "Nix Packages collection",
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "cac363c661817666e43d047addfaa722610d425f",
"sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/cac363c661817666e43d047addfaa722610d425f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
134 changes: 134 additions & 0 deletions nix/sources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# This file has been generated by Niv.

let

#
# The fetchers. fetch_<type> fetches specs of type <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 <package> -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 <package> -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:
let
sourcesNixpkgs =
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {}
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your 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))
);

# 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;

# 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;
};
in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
16 changes: 2 additions & 14 deletions nixpkgs/default.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
# see ../docs/dev/nixpkgs-pin.md
let
fetch = jsonFile:
with builtins;
let spec = fromJSON (readFile jsonFile);
in fetchTarball {
name = "nixpkgs";
inherit (spec) sha256;
url = "${spec.url}/archive/${spec.rev}.tar.gz";
};
in
# This file is for backwards compatibility only
{
nixpkgs-2003 = fetch (./. + "/release-20.03.json");
nixpkgs-1909 = fetch (./. + "/release-19.09.json");
nixpkgs-default = fetch (./. + "/github.json");
inherit (import ../nix/sources.nix) nixpkgs-2003 nixpkgs-1909 nixpkgs-default;
}
9 changes: 0 additions & 9 deletions nixpkgs/github.json

This file was deleted.

Empty file removed nixpkgs/hackage-src.json
Empty file.
9 changes: 0 additions & 9 deletions nixpkgs/release-19.09.json

This file was deleted.

9 changes: 0 additions & 9 deletions nixpkgs/release-20.03.json

This file was deleted.

4 changes: 3 additions & 1 deletion overlays/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
args:

let
overlays = {
wine = import ./wine.nix;
#ghcjs = import ./ghcjs-asterius-triple.nix;
#python = import ./python.nix;
haskell = import ./haskell.nix;
haskell = import ./haskell.nix args;
hackage-quirks = import ./hackage-quirks.nix;
bootstrap = import ./bootstrap.nix;
ghc = import ./ghc.nix;
Expand Down
35 changes: 24 additions & 11 deletions overlays/haskell.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{ sourcesOverride ? {}
, ... }:
# The haskell.nix infrastructure
#
# for hygenic reasons we'll use haskell-nix as a prefix.
Expand All @@ -10,6 +12,26 @@ final: prev: {
# overlays.
defaultModules = [];

# Niv based source pins. See https://github.com/nmattia/niv#niv
# for details on how to update this using the niv tool
# or edit nix/sources.json manually if you prefer.
sources = {
# Hackage and stackage still updated by scripts
# that predate our use of niv. We have moved them
# here though so that you can still use the
# sourcesOverride arg or `niv add` to replace them.
hackage = fetchExternal {
name = "hackage-exprs-source";
specJSON = hackageSourceJSON;
override = "hackage";
};
stackage = fetchExternal {
name = "stackage-snapshot-source";
specJSON = stackageSourceJSON;
override = "stackage";
};
} // (import ../nix/sources.nix) // sourcesOverride;

# We provide a `callPackage` function to consumers for
# convenience. We will however refrain from using it
# here and be explicit about imports and dependencies.
Expand Down Expand Up @@ -37,24 +59,15 @@ final: prev: {
cleanSourceHaskell;

# All packages from Hackage as Nix expressions
hackageSrc = fetchExternal {
name = "hackage-exprs-source";
specJSON = hackageSourceJSON;
override = "hackage";
};
hackageSrc = sources.hackage;
hackage = import hackageSrc;

# Contains the hashes of the cabal 01-index.tar.gz for given
# index states. Starting from April 1st 2019.
indexStateHashesPath = hackageSrc + "/index-state-hashes.nix";

# The set of all Stackage snapshots
stackageSrc = fetchExternal {
name = "stackage-snapshot-source";
specJSON = stackageSourceJSON;
override = "stackage";
};

stackageSrc = sources.stackage;
stackage = import stackageSrc;

# Utility functions for working with the component builder.
Expand Down