From a544f8b4bbbb5690059dd1aa9a27568bb85b5ee1 Mon Sep 17 00:00:00 2001 From: Ian-Woo Kim Date: Thu, 5 May 2022 16:20:03 -0700 Subject: [PATCH 1/6] use nix flakes providing overlay --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..25f68b4c --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1651662302, + "narHash": "sha256-utlTjLa1s4ezdQIUvnBtmA9TBYFrPlXpAJnCXEiZFZI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "dff5496b12817e3d019983827c4b7ba7beb96580", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..2f3afccd --- /dev/null +++ b/flake.nix @@ -0,0 +1,47 @@ +{ + description = "concat"; + inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; }; + outputs = { self, nixpkgs }: + let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + + haskellOverlay = self: super: { + "concat-inline" = pkgs.haskell.lib.dontHaddock + (self.callCabal2nix "concat-inline" ./inline { }); + "concat-plugin" = self.callCabal2nix "concat-plugin" ./plugin { }; + "concat-classes" = self.callCabal2nix "concat-classes" ./classes { }; + "concat-satisfy" = self.callCabal2nix "concat-satisfy" ./satisfy { }; + "concat-known" = self.callCabal2nix "concat-known" ./known { }; + #"concat-hardware" = self.callCabal2nix "concat-hardware" ./hardware { }; + "concat-graphics" = self.callCabal2nix "concat-graphics" ./graphics { }; + "concat-examples" = self.callCabal2nix "concat-examples" ./examples { }; + }; + + newHaskellPackages = + pkgs.haskellPackages.override { overrides = haskellOverlay; }; + + in { + packages.x86_64-linux = { + inherit (newHaskellPackages) + concat-inline concat-plugin concat-classes concat-satisfy concat-known + #concat-hardware + concat-graphics concat-examples; + }; + + # see these issues and discussions: + # - https://github.com/NixOS/nixpkgs/issues/16394 + # - https://github.com/NixOS/nixpkgs/issues/25887 + # - https://github.com/NixOS/nixpkgs/issues/26561 + # - https://discourse.nixos.org/t/nix-haskell-development-2020/6170 + overlay = final: prev: { + haskellPackages = prev.haskellPackages.override (old: { + overrides = final.lib.composeExtensions (old.overrides or (_: _: { })) + haskellOverlay; + }); + }; + + devShell.x86_64-linux = let + hsenv = pkgs.haskellPackages.ghcWithPackages (p: [ p.cabal-install ]); + in pkgs.mkShell { buildInputs = [ hsenv ]; }; + }; +} From 7d4670900d838dab7a4b39ddc6b26c788d0cc0da Mon Sep 17 00:00:00 2001 From: Ian-Woo Kim Date: Fri, 6 May 2022 09:26:39 -0700 Subject: [PATCH 2/6] dontHaddock concat-examples --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 2f3afccd..b30d3fa7 100644 --- a/flake.nix +++ b/flake.nix @@ -14,7 +14,8 @@ "concat-known" = self.callCabal2nix "concat-known" ./known { }; #"concat-hardware" = self.callCabal2nix "concat-hardware" ./hardware { }; "concat-graphics" = self.callCabal2nix "concat-graphics" ./graphics { }; - "concat-examples" = self.callCabal2nix "concat-examples" ./examples { }; + "concat-examples" = pkgs.haskell.lib.dontHaddock + (self.callCabal2nix "concat-examples" ./examples { }); }; newHaskellPackages = From d457c17a61c02f99945523c07446f88c3825abdf Mon Sep 17 00:00:00 2001 From: Ian-Woo Kim Date: Tue, 10 May 2022 22:02:07 -0700 Subject: [PATCH 3/6] use flake-utils.eachSystem --- flake.lock | 22 ++++++++++++-- flake.nix | 87 +++++++++++++++++++++++++++++------------------------- 2 files changed, 66 insertions(+), 43 deletions(-) diff --git a/flake.lock b/flake.lock index 25f68b4c..c0d28580 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,27 @@ { "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1651662302, - "narHash": "sha256-utlTjLa1s4ezdQIUvnBtmA9TBYFrPlXpAJnCXEiZFZI=", + "lastModified": 1652020977, + "narHash": "sha256-9hDlNbrxzD/pLlXmoQ6gzxbYiSAKrj7uHYUWNByLFlI=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "dff5496b12817e3d019983827c4b7ba7beb96580", + "rev": "3c5ae9be1f18c790ea890ef8decbd0946c0b4c04", "type": "github" }, "original": { @@ -18,6 +33,7 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index b30d3fa7..b591fbd0 100644 --- a/flake.nix +++ b/flake.nix @@ -1,48 +1,55 @@ { description = "concat"; - inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; }; - outputs = { self, nixpkgs }: - let - pkgs = nixpkgs.legacyPackages.x86_64-linux; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system: + let + pkgs = import nixpkgs { inherit system; }; - haskellOverlay = self: super: { - "concat-inline" = pkgs.haskell.lib.dontHaddock - (self.callCabal2nix "concat-inline" ./inline { }); - "concat-plugin" = self.callCabal2nix "concat-plugin" ./plugin { }; - "concat-classes" = self.callCabal2nix "concat-classes" ./classes { }; - "concat-satisfy" = self.callCabal2nix "concat-satisfy" ./satisfy { }; - "concat-known" = self.callCabal2nix "concat-known" ./known { }; - #"concat-hardware" = self.callCabal2nix "concat-hardware" ./hardware { }; - "concat-graphics" = self.callCabal2nix "concat-graphics" ./graphics { }; - "concat-examples" = pkgs.haskell.lib.dontHaddock - (self.callCabal2nix "concat-examples" ./examples { }); - }; + haskellOverlay = self: super: { + "concat-inline" = pkgs.haskell.lib.dontHaddock + (self.callCabal2nix "concat-inline" ./inline { }); + "concat-plugin" = self.callCabal2nix "concat-plugin" ./plugin { }; + "concat-classes" = self.callCabal2nix "concat-classes" ./classes { }; + "concat-satisfy" = self.callCabal2nix "concat-satisfy" ./satisfy { }; + "concat-known" = self.callCabal2nix "concat-known" ./known { }; + #"concat-hardware" = self.callCabal2nix "concat-hardware" ./hardware { }; + "concat-graphics" = + self.callCabal2nix "concat-graphics" ./graphics { }; + "concat-examples" = pkgs.haskell.lib.dontHaddock + (self.callCabal2nix "concat-examples" ./examples { }); + }; - newHaskellPackages = - pkgs.haskellPackages.override { overrides = haskellOverlay; }; + newHaskellPackages = + pkgs.haskellPackages.override { overrides = haskellOverlay; }; - in { - packages.x86_64-linux = { - inherit (newHaskellPackages) - concat-inline concat-plugin concat-classes concat-satisfy concat-known - #concat-hardware - concat-graphics concat-examples; - }; + in { + packages = { + inherit (newHaskellPackages) + concat-inline concat-plugin concat-classes concat-satisfy + concat-known + #concat-hardware + concat-graphics concat-examples; + }; - # see these issues and discussions: - # - https://github.com/NixOS/nixpkgs/issues/16394 - # - https://github.com/NixOS/nixpkgs/issues/25887 - # - https://github.com/NixOS/nixpkgs/issues/26561 - # - https://discourse.nixos.org/t/nix-haskell-development-2020/6170 - overlay = final: prev: { - haskellPackages = prev.haskellPackages.override (old: { - overrides = final.lib.composeExtensions (old.overrides or (_: _: { })) - haskellOverlay; - }); - }; + # see these issues and discussions: + # - https://github.com/NixOS/nixpkgs/issues/16394 + # - https://github.com/NixOS/nixpkgs/issues/25887 + # - https://github.com/NixOS/nixpkgs/issues/26561 + # - https://discourse.nixos.org/t/nix-haskell-development-2020/6170 + overlay = final: prev: { + haskellPackages = prev.haskellPackages.override (old: { + overrides = + final.lib.composeExtensions (old.overrides or (_: _: { })) + haskellOverlay; + }); + }; - devShell.x86_64-linux = let - hsenv = pkgs.haskellPackages.ghcWithPackages (p: [ p.cabal-install ]); - in pkgs.mkShell { buildInputs = [ hsenv ]; }; - }; + devShell = let + hsenv = pkgs.haskellPackages.ghcWithPackages (p: [ p.cabal-install ]); + in pkgs.mkShell { buildInputs = [ hsenv ]; }; + }); } From 5242d689cea4b21c5a240f4e3cdb080187e7bcdf Mon Sep 17 00:00:00 2001 From: Ian-Woo Kim Date: Tue, 17 May 2022 10:01:38 -0700 Subject: [PATCH 4/6] use parse-cabal-project. --- flake.nix | 75 ++++++++++++++++++++++++----------------- parse-cabal-project.nix | 19 +++++++++++ 2 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 parse-cabal-project.nix diff --git a/flake.nix b/flake.nix index b591fbd0..d1f892dd 100644 --- a/flake.nix +++ b/flake.nix @@ -5,51 +5,64 @@ flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system: + flake-utils.lib.eachSystem flake-utils.lib.allSystems (system: let - pkgs = import nixpkgs { inherit system; }; + haskellLib = (import nixpkgs { inherit system; }).haskell.lib; - haskellOverlay = self: super: { - "concat-inline" = pkgs.haskell.lib.dontHaddock - (self.callCabal2nix "concat-inline" ./inline { }); - "concat-plugin" = self.callCabal2nix "concat-plugin" ./plugin { }; - "concat-classes" = self.callCabal2nix "concat-classes" ./classes { }; - "concat-satisfy" = self.callCabal2nix "concat-satisfy" ./satisfy { }; - "concat-known" = self.callCabal2nix "concat-known" ./known { }; - #"concat-hardware" = self.callCabal2nix "concat-hardware" ./hardware { }; - "concat-graphics" = - self.callCabal2nix "concat-graphics" ./graphics { }; - "concat-examples" = pkgs.haskell.lib.dontHaddock - (self.callCabal2nix "concat-examples" ./examples { }); - }; - - newHaskellPackages = - pkgs.haskellPackages.override { overrides = haskellOverlay; }; - - in { - packages = { - inherit (newHaskellPackages) - concat-inline concat-plugin concat-classes concat-satisfy - concat-known - #concat-hardware - concat-graphics concat-examples; - }; + parseCabalProject = import ./parse-cabal-project.nix; + concatPackages = let + excluded = [ "concat-hardware" ]; + parsed = parseCabalProject ./cabal.project; + in builtins.filter ({ name, ... }: !(builtins.elem name excluded)) + parsed; + concatPackageNames = builtins.map ({ name, ... }: name) concatPackages; + haskellOverlay = self: super: + builtins.listToAttrs (builtins.map ({ name, path }: { + inherit name; + value = self.callCabal2nix name (./. + "/${path}") { }; + }) concatPackages); # see these issues and discussions: # - https://github.com/NixOS/nixpkgs/issues/16394 # - https://github.com/NixOS/nixpkgs/issues/25887 # - https://github.com/NixOS/nixpkgs/issues/26561 # - https://discourse.nixos.org/t/nix-haskell-development-2020/6170 - overlay = final: prev: { + fullOverlay = final: prev: { haskellPackages = prev.haskellPackages.override (old: { overrides = final.lib.composeExtensions (old.overrides or (_: _: { })) haskellOverlay; }); }; + in { + overlay = fullOverlay; + + devShells = let + mkDevShell = ghcVer: + let + overlayGHC = final: prev: { + haskellPackages = prev.haskell.packages.${ghcVer}; + }; - devShell = let - hsenv = pkgs.haskellPackages.ghcWithPackages (p: [ p.cabal-install ]); - in pkgs.mkShell { buildInputs = [ hsenv ]; }; + newPkgs = import nixpkgs { + # Here we use the full overlays from this flake, but the categorifier-* + # packages will not be provided in the shell. The overlay is only used + # to extract dependencies. + overlays = [ overlayGHC fullOverlay ]; + inherit system; + }; + + in newPkgs.haskellPackages.shellFor { + packages = ps: builtins.map (name: ps.${name}) concatPackageNames; + buildInputs = [ newPkgs.haskellPackages.cabal-install ] ++ + # haskell-language-server on GHC 9.2.1 is broken yet. + newPkgs.lib.optional (ghcVer != "ghc921") + [ newPkgs.haskell-language-server ]; + withHoogle = false; + }; + in { + "ghc8107" = mkDevShell "ghc8107"; + "ghc921" = mkDevShell "ghc921"; + }; }); } diff --git a/parse-cabal-project.nix b/parse-cabal-project.nix new file mode 100644 index 00000000..3d9e73ff --- /dev/null +++ b/parse-cabal-project.nix @@ -0,0 +1,19 @@ +# Ideally, parsing cabal.project should be done via official tools +# Related discussion here: +# https://github.com/NixOS/cabal2nix/issues/286 + +cabalProject: +let + content = builtins.readFile cabalProject; + lines = builtins.filter builtins.isString (builtins.split '' + [ + ]'' content); + matches = + builtins.map (builtins.match "[[:space:]]*[.]/(.*)/(.*)[.]cabal$") lines; + projects = builtins.concatMap (match: + if builtins.isList match && builtins.length match == 2 then [{ + name = builtins.elemAt match 1; + path = builtins.elemAt match 0; + }] else + [ ]) matches; +in projects From 866ee27b655e5d13d8b917ca591e7547ae2d5550 Mon Sep 17 00:00:00 2001 From: Ian-Woo Kim Date: Tue, 17 May 2022 10:04:26 -0700 Subject: [PATCH 5/6] remove irrelevant comment. --- flake.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/flake.nix b/flake.nix index d1f892dd..f88841ba 100644 --- a/flake.nix +++ b/flake.nix @@ -45,9 +45,6 @@ }; newPkgs = import nixpkgs { - # Here we use the full overlays from this flake, but the categorifier-* - # packages will not be provided in the shell. The overlay is only used - # to extract dependencies. overlays = [ overlayGHC fullOverlay ]; inherit system; }; From c4b2711222727a9f5cbcc5e80681c1de1e6f6035 Mon Sep 17 00:00:00 2001 From: Ian-Woo Kim Date: Tue, 17 May 2022 10:29:18 -0700 Subject: [PATCH 6/6] dontHaddock, dontCheck for some packages --- flake.nix | 63 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index f88841ba..fdc20e55 100644 --- a/flake.nix +++ b/flake.nix @@ -9,17 +9,32 @@ let haskellLib = (import nixpkgs { inherit system; }).haskell.lib; + excludedPackages = [ "concat-hardware" ]; + noHaddockPackages = + [ "concat-examples" "concat-inline" "concat-plugin" ]; + # need display, graphviz for testing. disable test for now. + noCheckPackages = [ "concat-graphics" "concat-plugin" ]; + parseCabalProject = import ./parse-cabal-project.nix; - concatPackages = let - excluded = [ "concat-hardware" ]; - parsed = parseCabalProject ./cabal.project; - in builtins.filter ({ name, ... }: !(builtins.elem name excluded)) - parsed; + concatPackages = let parsed = parseCabalProject ./cabal.project; + in builtins.filter + ({ name, ... }: !(builtins.elem name excludedPackages)) parsed; concatPackageNames = builtins.map ({ name, ... }: name) concatPackages; + haskellOverlay = self: super: builtins.listToAttrs (builtins.map ({ name, path }: { inherit name; - value = self.callCabal2nix name (./. + "/${path}") { }; + value = let + p = self.callCabal2nix name (./. + "/${path}") { }; + p1 = if builtins.elem name noHaddockPackages then + haskellLib.dontHaddock p + else + p; + p2 = if builtins.elem name noCheckPackages then + haskellLib.dontCheck p1 + else + p1; + in p2; }) concatPackages); # see these issues and discussions: @@ -35,6 +50,42 @@ }); }; in { + # This package set is only useful for CI build test. + # In practice, users will create a development environment composed by overlays. + packages = let + packagesOnGHC = ghcVer: + let + overlayGHC = final: prev: { + haskellPackages = prev.haskell.packages.${ghcVer}; + }; + + newPkgs = import nixpkgs { + overlays = [ overlayGHC fullOverlay ]; + inherit system; + }; + + individualPackages = builtins.listToAttrs (builtins.map + ({ name, ... }: { + name = ghcVer + "_" + name; + value = builtins.getAttr name newPkgs.haskellPackages; + }) concatPackages); + + allEnv = let + hsenv = newPkgs.haskellPackages.ghcWithPackages (p: + let + deps = + builtins.map ({ name, ... }: p.${name}) concatPackages; + in deps); + in newPkgs.buildEnv { + name = "all-packages"; + paths = [ hsenv ]; + }; + in individualPackages // { "${ghcVer}_all" = allEnv; }; + + in packagesOnGHC "ghc8107" // packagesOnGHC "ghc884" + // packagesOnGHC "ghc901" // packagesOnGHC "ghc921" + // packagesOnGHC "ghcHEAD"; + overlay = fullOverlay; devShells = let