Created
January 19, 2020 16:26
-
-
Save alexpeits/215a3b37688c595bd52dc0cf58161ce8 to your computer and use it in GitHub Desktop.
generic haskell + nix configuration (here copied from `harg`)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to see ghc versions: | |
# nix-instantiate --eval -E "with import ./nix/nixpkgs.nix {}; lib.attrNames haskell.compiler" | |
{ pkgs ? null, compiler ? null, withHoogle ? true }: | |
let | |
nixpkgs = if isNull pkgs then | |
import (import ./nix/sources.nix).nixos-stable { } | |
else if builtins.typeOf pkgs == "set" then | |
pkgs | |
else | |
import (builtins.getAttr pkgs (import ./nix/sources.nix)) { }; | |
inShell = nixpkgs.lib.inNixShell; | |
haskellPackagesNoHoogle = if isNull compiler then | |
nixpkgs.haskellPackages | |
else | |
nixpkgs.haskell.packages.${compiler}; | |
haskellPackagesWithHoogle = haskellPackagesNoHoogle.override { | |
overrides = (self: super: { | |
ghc = super.ghc // { withPackages = super.ghc.withHoogle; }; | |
ghcWithPackages = self.ghc.withPackages; | |
}); | |
}; | |
haskellPackages = if (inShell && withHoogle) then | |
haskellPackagesWithHoogle | |
else | |
haskellPackagesNoHoogle; | |
src = nixpkgs.nix-gitignore.gitignoreSource [ ] ./.; | |
overrides = import ./nix/overrides.nix { | |
pkgs = nixpkgs; | |
haskellPackages = haskellPackages; | |
}; | |
harg = haskellPackages.callCabal2nix "harg" src overrides; | |
shell = nixpkgs.mkShell { | |
inputsFrom = [ harg.env ]; | |
shellHook = '' | |
alias ghcid-orig="$(which ghcid)" | |
alias ghcid="ghcid -a --command='cabal new-repl' --restart=harg.cabal" | |
''; | |
buildInputs = [ haskellPackages.ghcid haskellPackages.cabal-install ]; | |
}; | |
in if inShell then shell else harg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs, haskellPackages }: | |
let | |
higgledy-src = pkgs.fetchFromGitHub { | |
owner = "i-am-tom"; | |
repo = "higgledy"; | |
rev = "476d73a92e3ef6e1dc879555d751f877b0f91de8"; | |
sha256 = "1vg9ha3knggyh5a76678y808c29v9p1mai9bq355q7amy0icy46j"; | |
}; | |
in { higgledy = haskellPackages.callCabal2nix "higgledy" higgledy-src { }; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nixos-stable": { | |
"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": "8bf142e001b6876b021c8ee90c2c7cec385fe8e9", | |
"sha256": "1z8id8ix24ds9i7cm8g33v54j7xbhcpwzw50wlq00alj00xrq307", | |
"type": "tarball", | |
"url": "https://github.com/NixOS/nixpkgs-channels/archive/8bf142e001b6876b021c8ee90c2c7cec385fe8e9.tar.gz", | |
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | |
}, | |
"nixpkgs-master": { | |
"branch": "749dccbedbc9d538f94f172a705c5784cf5a752e", | |
"description": "Nix Packages collection", | |
"homepage": null, | |
"owner": "NixOS", | |
"repo": "nixpkgs", | |
"rev": "749dccbedbc9d538f94f172a705c5784cf5a752e", | |
"sha256": "15xrxzfnpx1hm4s36srvb71zzjm6j2dnk7g3v33x51qmf8bp9mw9", | |
"type": "tarball", | |
"url": "https://github.com/NixOS/nixpkgs/archive/749dccbedbc9d538f94f172a705c5784cf5a752e.tar.gz", | |
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 <nixpkgs> {} | |
else | |
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; | |
sources_nixpkgs = | |
if builtins.hasAttr "nixpkgs" sources | |
then sources.nixpkgs | |
else abort | |
'' | |
Please specify either <nixpkgs> (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 <nixpkgs>).success; | |
hasThisAsNixpkgsPath = | |
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.; | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment