From e11b00e307da605cd1fa1f4efd177660cc6e7144 Mon Sep 17 00:00:00 2001 From: David Johnson Date: Sun, 18 Jul 2021 12:33:14 -0500 Subject: [PATCH] Initial commit of haskell.nix. --- .gitignore | 1 + .travis.yml | 2 +- default.nix | 74 +++------- miso.cabal | 8 +- nix/default.nix | 15 -- nix/haskell/packages/ghc865/default.nix | 28 ---- nix/haskell/packages/ghcARM/default.nix | 43 ------ nix/haskell/packages/ghcjs/default.nix | 46 ------- nix/haskell/packages/source.nix | 67 --------- nix/nixpkgs.json | 4 - nix/overlay.nix | 65 --------- nix/sources.json | 122 +++++++++++++++++ nix/sources.nix | 174 ++++++++++++++++++++++++ 13 files changed, 321 insertions(+), 328 deletions(-) delete mode 100644 nix/default.nix delete mode 100644 nix/haskell/packages/ghc865/default.nix delete mode 100644 nix/haskell/packages/ghcARM/default.nix delete mode 100644 nix/haskell/packages/ghcjs/default.nix delete mode 100644 nix/haskell/packages/source.nix delete mode 100644 nix/nixpkgs.json delete mode 100644 nix/overlay.nix create mode 100644 nix/sources.json create mode 100644 nix/sources.nix diff --git a/.gitignore b/.gitignore index 621a07d1..3771e177 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ dist *.o *.hi *.jsexe +/TAGS diff --git a/.travis.yml b/.travis.yml index 31b933b5..4b27f9ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,5 +12,5 @@ before_install: - nix-build -A pkgs.yarn default.nix && nix-env -i ./result script: - - nix-build --arg examples true + - nix-build -A miso - cd tests && yarn && yarn test diff --git a/default.nix b/default.nix index ef0a5c8d..aff46f50 100644 --- a/default.nix +++ b/default.nix @@ -1,58 +1,26 @@ -{ haddock ? true -, tests ? false -, examples ? false -, ios ? false -, overlays ? [] -, system ? builtins.currentSystem -, crossSystem ? null -, crossOverlays ? [] -, allowBroken ? false -, allowUnfree ? true -}: let - options = - { inherit - haddock - tests - examples - ios - overlays - system - crossSystem - crossOverlays - allowBroken - allowUnfree; + sources = import ./nix/sources.nix {}; + haskellNix = import sources.haskellNix {}; + args = haskellNix.nixpkgsArgs // { config.allowUnfree = true; }; + pkgs = import haskellNix.sources.nixpkgs-unstable args; + miso = pkgs.haskell-nix.project { + src = pkgs.haskell-nix.haskellLib.cleanGit { + name = "miso"; + src = ./.; }; - pkgs = import ./nix options; - armPkgs = - with pkgs; with pkgs.lib; - optionalAttrs (options.ios && stdenv.isDarwin) - { miso-arm = pkgsCross.iphone64.haskell.packages.integer-simple.ghc865.miso; }; - release = - with pkgs.haskell.packages.ghc865; - with pkgs.haskell.lib; - sdistTarball (buildStrictly miso); - release-examples = - with pkgs.haskell.packages.ghc865; - with pkgs.haskell.lib; - sdistTarball (buildStrictly miso-examples-jsaddle); - examplePkgs = with pkgs; with pkgs.lib; - let - examplePkgs = optionalAttrs options.examples { - inherit (haskell.packages.ghc865) miso-examples-jsaddle; - inherit (haskell.packages.ghcjs86) miso-examples; - inherit s3; - }; - in - examplePkgs // - optionalAttrs (stdenv.isDarwin && options.examples && options.ios) - { inherit (pkgsCross.iphone64.haskell.packages.integer-simple.ghc865) miso-examples-arm; - }; + compiler-nix-name = "ghc8105"; + }; + examples = pkgs.haskell-nix.project { + src = pkgs.haskell-nix.haskellLib.cleanGit { + name = "miso-examples"; + src = ./examples; + }; + compiler-nix-name = "ghc8105"; + }; in { inherit pkgs; - miso-ghcjs = pkgs.haskell.packages.ghcjs86.miso; - miso-ghc = pkgs.haskell.packages.ghc865.miso; - inherit (pkgs.haskell.packages.ghc865) miso-jsaddle; - inherit release release-examples; -} // examplePkgs // armPkgs + miso = miso.projectCross.ghcjs.hsPkgs.miso.components.library; +} + + diff --git a/miso.cabal b/miso.cabal index 78618e1a..7a6fa0a9 100644 --- a/miso.cabal +++ b/miso.cabal @@ -10,7 +10,7 @@ copyright: Copyright (c) 2017-2020 David M. Johnson bug-reports: https://github.com/dmjio/miso/issues build-type: Simple extra-source-files: README.md -cabal-version: >=1.22 +cabal-version: 1.22 synopsis: A tasty Haskell front-end framework description: Miso is a small, production-ready, "isomorphic" Haskell front-end framework featuring a virtual-dom, recursive diffing / patching algorithm, event delegation, event batching, SVG, Server-sent events, Websockets, type-safe servant-style routing and an extensible Subscription-based subsystem. Inspired by Elm, Redux and Bobril. Miso is pure by default, but side effects (like XHR) can be introduced into the system via the Effect data type. Miso makes heavy use of the GHCJS FFI and therefore has minimal dependencies. @@ -20,7 +20,7 @@ extra-source-files: flag tests default: - False + True description: Builds Miso's tests @@ -181,8 +181,6 @@ library jsbits/delegate.js jsbits/isomorphic.js jsbits/util.js - hs-source-dirs: - frontend-src build-depends: containers, scientific, @@ -192,8 +190,6 @@ library else build-depends: vector - hs-source-dirs: - backend-src if impl(ghcjs) hs-source-dirs: ghcjs-src diff --git a/nix/default.nix b/nix/default.nix deleted file mode 100644 index 7b52f69b..00000000 --- a/nix/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -options: -with (builtins.fromJSON (builtins.readFile ./nixpkgs.json)); -let - nixpkgs = builtins.fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; - inherit sha256; - }; - config.allowUnfree = options.allowUnfree; - config.allowBroken = options.allowBroken; - overlays = [ (import ./overlay.nix options) ] ++ options.overlays; -in - import nixpkgs - { inherit (options) crossSystem crossOverlays system; - inherit overlays config; - } diff --git a/nix/haskell/packages/ghc865/default.nix b/nix/haskell/packages/ghc865/default.nix deleted file mode 100644 index c15dd08b..00000000 --- a/nix/haskell/packages/ghc865/default.nix +++ /dev/null @@ -1,28 +0,0 @@ -pkgs: -let - source = import ../source.nix pkgs; -in -with pkgs.haskell.lib; -self: super: -{ - jsaddle = self.callCabal2nix "jsaddle" "${source.jsaddle}/jsaddle" {}; - jsaddle-dom = self.callCabal2nix "jsaddle-dom" source.jsaddle-dom {}; - miso = self.callCabal2nix "miso" source.miso {}; - miso-jsaddle = self.callCabal2nixWithOptions "miso" source.miso "-fjsaddle" {}; - miso-examples-jsaddle = - self.callCabal2nixWithOptions "miso-examples" source.examples "-fjsaddle" { miso = self.miso-jsaddle; }; - jsaddle-warp = dontCheck (self.callCabal2nix "jsaddle-warp" "${source.jsaddle}/jsaddle-warp" {}); - webkit2gtk3-javascriptcore = self.callCabal2nix "webkit2gtk3-javascriptcore" source.webkit2gtk3-javascriptcore {}; - jsaddle-wkwebview = dontCheck (overrideCabal (self.callCabal2nix "jsaddle-wkwebview" "${source.jsaddle}/jsaddle-wkwebview" {}) (drv: { - libraryFrameworkDepends = - (drv.libraryFrameworkDepends or []) ++ - (if pkgs.stdenv.hostPlatform.useiOSPrebuilt - then [ "${pkgs.buildPackages.darwin.xcode}/Contents/Developer/Platforms/${pkgs.stdenv.hostPlatform.xcodePlatform}.platform/Developer/SDKs/${pkgs.stdenv.hostPlatform.xcodePlatform}.sdk/System" ] - else (with pkgs.buildPackages.darwin.apple_sdk.frameworks; [ Cocoa WebKit ])); - buildDepends = pkgs.lib.optional (!pkgs.stdenv.hostPlatform.useiOSPrebuilt) [ pkgs.buildPackages.darwin.cf-private ]; - })); - jsaddle-webkit2gtk = self.callCabal2nix "jsaddle-webkit2gtk" "${source.jsaddle}/jsaddle-webkit2gtk" {}; - ghcjs-dom-jsaddle = self.callCabal2nix "ghcjs-dom-jsaddle" "${source.ghcjs-dom}/ghcjs-dom-jsaddle" {}; - ghcjs-dom-jsffi = self.callCabal2nix "ghcjs-dom-jsffi" "${source.ghcjs-dom}/ghcjs-dom-jsffi" {}; - ghcjs-dom = self.callCabal2nix "ghcjs-dom" "${source.ghcjs-dom}/ghcjs-dom" {}; -} diff --git a/nix/haskell/packages/ghcARM/default.nix b/nix/haskell/packages/ghcARM/default.nix deleted file mode 100644 index 6009278b..00000000 --- a/nix/haskell/packages/ghcARM/default.nix +++ /dev/null @@ -1,43 +0,0 @@ -pkgs: -let - source = import ../source.nix pkgs; -in -with pkgs.haskell.lib; -self: super: -{ - mkDerivation = args: super.mkDerivation (args // { - enableLibraryProfiling = false; - doCheck = false; - doHaddock = false; - }); - ghc = super.ghc.overrideAttrs (drv: { - patchPhase = '' - sed -i -e '4092,4093d' compiler/main/DynFlags.hs - ''; - }); - ghcjs-dom-jsaddle = self.callCabal2nix "ghcjs-dom-jsaddle" "${source.ghcjs-dom}/ghcjs-dom-jsaddle" {}; - ghcjs-dom-jsffi = self.callCabal2nix "ghcjs-dom-jsffi" "${src.ghcjs-dom}/ghcjs-dom-jsffi" {}; - ghcjs-dom = self.callCabal2nix "ghcjs-dom" "${src.ghcjs-dom}/ghcjs-dom" {}; - jsaddle = self.callCabal2nix "jsaddle" "${source.jsaddle}/jsaddle" {}; - jsaddle-dom = self.callCabal2nix "jsaddle-dom" "${source.jsaddle}/jsaddle-dom" {}; - jsaddle-wkwebview = self.callCabal2nix "jsaddle-wkwebview" "${source.jsaddle}/jsaddle-wkwebview" {}; - servant = pkgs.lib.overrideDerivation (super.servant) (drv: { - postInstall = ""; - postUnpack = '' - ${pkgs.gnused}/bin/sed -i '135d' servant*/servant.cabal - ${pkgs.gnused}/bin/sed -i '137d' servant*/servant.cabal - ''; - }); - aeson = dontCheck super.aeson; - QuickCheck = disableCabalFlag (super.QuickCheck) "templatehaskell"; - miso-examples-arm = self.callCabal2nixWithOptions "miso-examples" source.examples "-fjsaddle -fios" {}; - miso = pkgs.lib.overrideDerivation - (self.callCabal2nixWithOptions "miso" source.miso "-fjsaddle -fios" {}) - (drv: { - preConfigure = - let - ghc = pkgs.haskellPackages.ghcWithPackages (p: with p; [hjsmin]); - in - "${ghc}/bin/runghc minify-inline/Main.hs && mv JSBits.hs frontend-src/Miso/"; - }); -} diff --git a/nix/haskell/packages/ghcjs/default.nix b/nix/haskell/packages/ghcjs/default.nix deleted file mode 100644 index c03022dc..00000000 --- a/nix/haskell/packages/ghcjs/default.nix +++ /dev/null @@ -1,46 +0,0 @@ -options: pkgs: -let - source = import ../source.nix pkgs; -in -with pkgs.haskell.lib; -with pkgs.lib; -self: super: -{ - inherit (pkgs.haskell.packages.ghc865) hpack; - jsaddle = self.callCabal2nix "jsaddle" "${source.jsaddle}/jsaddle" {}; - jsaddle-dom = self.callCabal2nix "jsaddle-dom" source.jsaddle-dom {}; - jsaddle-warp = dontCheck (self.callCabal2nix "jsaddle-warp" "${source.jsaddle}/jsaddle-warp" {}); - jsaddle-webkit2gtk = self.callCabal2nix "jsaddle-webkit2gtk" "${source.jsaddle}/jsaddle-webkit2gtk" {}; - ghcjs-dom-jsaddle = self.callCabal2nix "ghcjs-dom-jsaddle" "${source.ghcjs-dom}/ghcjs-dom-jsaddle" {}; - ghcjs-dom-jsffi = self.callCabal2nix "ghcjs-dom-jsffi" "${source.ghcjs-dom}/ghcjs-dom-jsffi" {}; - ghcjs-dom = self.callCabal2nix "ghcjs-dom" "${source.ghcjs-dom}/ghcjs-dom" {}; - flatris = self.callCabal2nix "hs-flatris" source.flatris {}; - the2048 = self.callCabal2nix "2048" source.the2048 {}; - snake = self.callCabal2nix "miso-snake" source.snake {}; - mkDerivation = args: super.mkDerivation (args // { doCheck = false; }); - doctest = null; - miso-examples = (self.callCabal2nixWithOptions "miso-examples" source.examples "-fjsaddle" {}).overrideDerivation (drv: { - doHaddock = options.haddock; - postInstall = '' - mkdir -p $out/bin/mario.jsexe/imgs - cp -r ${drv.src}/mario/imgs $out/bin/mario.jsexe/ - cp ${drv.src}/xhr/index.html $out/bin/xhr.jsexe/ - ${pkgs.closurecompiler}/bin/closure-compiler --compilation_level ADVANCED_OPTIMIZATIONS \ - --jscomp_off=checkVars \ - --externs=$out/bin/todo-mvc.jsexe/all.js.externs \ - $out/bin/todo-mvc.jsexe/all.js > temp.js - mv temp.js $out/bin/todo-mvc.jsexe/all.js - ''; - }); - miso-jsaddle = self.callCabal2nixWithOptions "miso" source.miso "-fjsaddle" {}; - miso = (self.callCabal2nixWithOptions "miso" source.miso "-ftests" {}).overrideDerivation (drv: { - doHaddock = options.haddock; - postInstall = pkgs.lib.optionalString options.tests '' - ${pkgs.closurecompiler}/bin/closure-compiler --compilation_level ADVANCED_OPTIMIZATIONS \ - --jscomp_off=checkVars \ - --externs=$out/bin/tests.jsexe/all.js.externs \ - $out/bin/tests.jsexe/all.js > temp.js - mv temp.js $out/bin/tests.jsexe/all.js - ''; - }); -} diff --git a/nix/haskell/packages/source.nix b/nix/haskell/packages/source.nix deleted file mode 100644 index bb4b6733..00000000 --- a/nix/haskell/packages/source.nix +++ /dev/null @@ -1,67 +0,0 @@ -{ lib, fetchFromGitHub, fetchgit, fetchzip, ... }: -with lib; -let - make-src-filter = src: with lib; - cleanSourceWith { - inherit src; - filter = - name: type: let baseName = baseNameOf (toString name); in - ((type == "regular" && hasSuffix ".hs" baseName) || - (hasSuffix ".yaml" baseName) || - (hasSuffix ".cabal" baseName) || - (hasSuffix ".css" baseName) || - (hasSuffix ".html" baseName) || - (hasSuffix ".png" baseName) || - (hasSuffix ".js" baseName) || - (baseName == "README.md") || - (baseName == "LICENSE") || - (type == "directory" && baseName != "examples") || - (type == "directory" && baseName != "dist")); - }; -in -{ - miso = make-src-filter ../../..; - examples = make-src-filter ../../../examples; - jsaddle = fetchFromGitHub { - owner = "ghcjs"; - repo = "jsaddle"; - rev = "d569be43f92b9b8c01dc3ee4c41401ab406a2076"; - sha256 = "1m1xxy4l9ii91k1k504qkxh9k1ybprm1m66mkb9dqlwcpyhcccmv"; - }; - jsaddle-dom = fetchFromGitHub { - owner = "ghcjs"; - repo = "jsaddle-dom"; - rev = "6ce23c5"; - sha256 = "1wpwf025czibkw6770c99zk7r30j6nh7jdzhzqbi2z824qyqzbnw"; - }; - ghcjs-dom = fetchFromGitHub { - owner = "ghcjs"; - repo = "ghcjs-dom"; - rev = "b8e483a"; - sha256 = "06qlbbhjd0mlv5cymp5q0rb69a333l0fcif5zwa83h94dh25c1g7"; - }; - webkit2gtk3-javascriptcore = fetchFromGitHub { - owner = "gtk2hs"; - repo = "webkit-javascriptcore"; - rev = "5868624"; - sha256 = "0aj0cvcbnzrdi1ynahpb4034vadfrs99n5qa8dar1srhijv55g8b"; - }; - flatris = fetchFromGitHub { - repo = "hs-flatris"; - owner = "ptigwe"; - rev = "5b386e35db143205b4bd8d45cdf98423ed51b713"; - sha256 = "0wll5fizkdmj2hgd71v9klnnr6wxvvf36imchh2chm1slqm78zca"; - }; - the2048 = fetchFromGitHub { - repo = "hs2048"; - owner = "dmjio"; - rev = "07dbed79a012240bfe19b836b6d445bb16a0602a"; - sha256 = "00rqix5g8s8y6ngxnjskvcyj19g639havn9pgpkdpxp8ni6g7xsm"; - }; - snake = fetchFromGitHub { - repo = "miso-snake"; - owner = "dmjio"; - rev = "c38947cd9417ab8bf8a8d3652d8bf549e35f14af"; - sha256 = "17rdc7fisqgf8zq90c3cw9c08b1qac6wirqmwifw2a0xxbigz4qc"; - }; -} diff --git a/nix/nixpkgs.json b/nix/nixpkgs.json deleted file mode 100644 index 323a69d4..00000000 --- a/nix/nixpkgs.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "rev" : "4dd5c93998da55002fdec1c715c680531420381c", - "sha256" : "06paxakic36nbdnwkkb1094fzp3lpzxxb1r57gmb3py6pb6xrcnh" -} diff --git a/nix/overlay.nix b/nix/overlay.nix deleted file mode 100644 index 43129f0a..00000000 --- a/nix/overlay.nix +++ /dev/null @@ -1,65 +0,0 @@ -options: self: super: { - darwin = super.darwin // { - xcode = super.darwin.xcode.overrideAttrs (drv: { - outputHash = "ec9f78b948abe341000d31f21b66051741b71163d778702b3e2e01659d60e3d2"; - }); - }; - pkgsCross = super.pkgsCross // { - iphone64 = super.pkgsCross.iphone64 // { - haskell = super.pkgsCross.iphone64.haskell // { - packages = super.pkgsCross.iphone64.haskell.packages // { - integer-simple = super.pkgsCross.iphone64.haskell.packages.integer-simple // { - ghc865 = super.pkgsCross.iphone64.haskell.packages.integer-simple.ghc865.override { - overrides = import ./haskell/packages/ghcARM self; - }; - }; - }; - }; - }; - }; - haskell = super.haskell // { - packages = super.haskell.packages // { - ghc865 = super.haskell.packages.ghc865.override { - overrides = import ./haskell/packages/ghc865 self; - }; - ghc864 = super.haskell.packages.ghc864.override { - overrides = selfGhc864: superGhc864: with super.haskell.lib; { - happy = dontCheck (selfGhc864.callHackage "happy" "1.19.9" {}); - mkDerivation = args: superGhc864.mkDerivation (args // { - enableLibraryProfiling = false; - doCheck = false; - doHaddock = false; - }); - }; - }; - ghcjs86 = super.haskell.packages.ghcjs86.override { - overrides = import ./haskell/packages/ghcjs options self; - }; - }; - }; - more-examples = { inherit (self.haskell.packages.ghcjs) flatris the2048 snake; }; - uploadCoverage = self.writeScriptBin "upload-coverage.sh" '' - #!/usr/bin/env bash - export PATH=$PATH:${self.nodePackages.yarn}/bin - cd tests && yarn test - cd coverage - ${self.s3cmd}/bin/s3cmd sync --recursive lcov-report/ s3://aws-website-coverage-j7fc9/ - ''; - s3 = with self.haskell.packages.ghcjs86; - with self; - self.writeScriptBin "s3.sh" '' - ${s3cmd}/bin/s3cmd sync --recursive ${more-examples.flatris}/bin/app.jsexe/ s3://aws-website-flatris-b3cr6/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso}/bin/simple.jsexe/ s3://aws-website-simple-4yic3/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso-examples}/bin/mario.jsexe/ s3://aws-website-mario-5u38b/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso-examples}/bin/todo-mvc.jsexe/ s3://aws-website-todo-mvc-hs61i/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso-examples}/bin/websocket.jsexe/ s3://aws-website-websocket-0gx34/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso-examples}/bin/router.jsexe/ s3://aws-website-router-gfy22/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso-examples}/bin/xhr.jsexe/ s3://aws-website-xhr-gvnhn/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso-examples}/bin/svg.jsexe/ s3://aws-website-svg-wa5mj/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso-examples}/bin/file-reader.jsexe/ s3://aws-website-file-reader-q1rpg/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso-examples}/bin/canvas2d.jsexe/ s3://aws-website-canvas-y63zw/ - ${s3cmd}/bin/s3cmd sync --recursive ${miso}/bin/tests.jsexe/ s3://aws-website-tests-xc9ud - ${s3cmd}/bin/s3cmd sync --recursive ${more-examples.snake}/bin/app.jsexe/ s3://aws-website-snake-9o0ge/ - ${s3cmd}/bin/s3cmd sync --recursive ${more-examples.the2048}/* s3://aws-website--6uw7z/ - ''; -} diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 00000000..a9b661c6 --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,122 @@ +{ + "ghcjs-dom": { + "branch": "master", + "description": "Make Document Object Model (DOM) apps that run in any browser and natively using WebKitGtk", + "homepage": "", + "owner": "ghcjs", + "repo": "ghcjs-dom", + "rev": "749963557d878d866be2d0184079836f367dd0ea", + "sha256": "0cv4avpjp6j6z9i1w4405vi13h76baaw29s99rmndbi2phm1agcf", + "type": "tarball", + "url": "https://github.com/ghcjs/ghcjs-dom/archive/749963557d878d866be2d0184079836f367dd0ea.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "haskellNix": { + "branch": "master", + "description": "Alternative Haskell Infrastructure for Nixpkgs", + "homepage": "https://input-output-hk.github.io/haskell.nix", + "owner": "input-output-hk", + "repo": "haskell.nix", + "rev": "ac52977939bb0462b45189274e5b89ab36ee4a17", + "sha256": "0zzygwi5pv74msnva3akaa86r2bpzqgkcl7xqsh43cpnqjgxsiff", + "type": "tarball", + "url": "https://github.com/input-output-hk/haskell.nix/archive/ac52977939bb0462b45189274e5b89ab36ee4a17.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "hs-flatris": { + "branch": "master", + "description": "An implementation of Flatris using Haskell and Miso", + "homepage": "https://flatris.haskell-miso.org", + "owner": "ptigwe", + "repo": "hs-flatris", + "rev": "e428d3825a0cf60e4182f8e7c6de652fbc1f3360", + "sha256": "033qj2j4fv5xdis2sxxpiiwka8qsb17q71rkglx4gn5ggcqp0vaw", + "type": "tarball", + "url": "https://github.com/ptigwe/hs-flatris/archive/e428d3825a0cf60e4182f8e7c6de652fbc1f3360.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "hs2048": { + "branch": "master", + "description": null, + "homepage": null, + "owner": "dmjio", + "repo": "hs2048", + "rev": "07dbed79a012240bfe19b836b6d445bb16a0602a", + "sha256": "00rqix5g8s8y6ngxnjskvcyj19g639havn9pgpkdpxp8ni6g7xsm", + "type": "tarball", + "url": "https://github.com/dmjio/hs2048/archive/07dbed79a012240bfe19b836b6d445bb16a0602a.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "jsaddle": { + "branch": "master", + "description": "JavaScript interface that works with GHCJS or GHC", + "homepage": "", + "owner": "ghcjs", + "repo": "jsaddle", + "rev": "376df8ecf96a809d4088786989c7885f53c00a4e", + "sha256": "1vmm7s39a56dm13fb4nmzbfprkwsir22faj9ja1rc670s7hlrq99", + "type": "tarball", + "url": "https://github.com/ghcjs/jsaddle/archive/376df8ecf96a809d4088786989c7885f53c00a4e.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "jsaddle-dom": { + "branch": "master", + "description": "DOM library that uses jsaddle to support both GHCJS and WebKitGTK", + "homepage": null, + "owner": "ghcjs", + "repo": "jsaddle-dom", + "rev": "5f5094277d4b11f3dc3e2df6bb437b75712d268f", + "sha256": "07azigc19wjkni49f5mrvr75vd276w0616sb28j0y63q54gp2k3p", + "type": "tarball", + "url": "https://github.com/ghcjs/jsaddle-dom/archive/5f5094277d4b11f3dc3e2df6bb437b75712d268f.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "miso-snake": { + "branch": "master", + "description": "Snake game, made with haskell-miso", + "homepage": null, + "owner": "dmjio", + "repo": "miso-snake", + "rev": "c38947cd9417ab8bf8a8d3652d8bf549e35f14af", + "sha256": "17rdc7fisqgf8zq90c3cw9c08b1qac6wirqmwifw2a0xxbigz4qc", + "type": "tarball", + "url": "https://github.com/dmjio/miso-snake/archive/c38947cd9417ab8bf8a8d3652d8bf549e35f14af.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070", + "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "release-20.03", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "eb73405ecceb1dc505b7cbbd234f8f94165e2696", + "sha256": "06k21wbyhhvq2f1xczszh3c2934p0m02by3l2ixvd6nkwrqklax7", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/eb73405ecceb1dc505b7cbbd234f8f94165e2696.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "webkit-javascriptcore": { + "branch": "master", + "description": "webkit javascriptcore library FFI", + "homepage": null, + "owner": "gtk2hs", + "repo": "webkit-javascriptcore", + "rev": "099f587d87ffeaaa8d734a9c9472211b834ad050", + "sha256": "1mxmwn39hp8icvh42cyyxzi3w9ar7xf7nrk25rzw3zah7alkpqf5", + "type": "tarball", + "url": "https://github.com/gtk2hs/webkit-javascriptcore/archive/099f587d87ffeaaa8d734a9c9472211b834ad050.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 00000000..1938409d --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,174 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + if spec ? ref then spec.ref else + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + in + builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import {} + else + abort + '' + Please specify either (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 name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # 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)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else {}; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + 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 = replace name (fetch config.pkgs name spec); } + ) config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: 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); }