From b79f17db158b6d483a0ba065b0013bc22c727918 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Tue, 27 Sep 2022 11:00:05 +0800 Subject: [PATCH 1/2] feat(deps): update nixpkgs and nixpkgs-unstable source revisions --- nix/sources.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index 96e5d19..b5e8573 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7e27b838cd7ac90fed03d0d5a8487848c4b0b6d2", - "sha256": "027l6ihbgaqk2k20x5zq9x55vgs556xlv5yfdjbvd4v35dclx55m", + "rev": "82379884b2e9cf1ba65f5b14bbcb9d1438abb745", + "sha256": "0zh7h0hsbasl4d527zz7mr2msnffpf269si3jpw2sd62lk8zikz4", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/7e27b838cd7ac90fed03d0d5a8487848c4b0b6d2.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/82379884b2e9cf1ba65f5b14bbcb9d1438abb745.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs-unstable": { @@ -17,10 +17,10 @@ "homepage": "", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e14f9fb57315f0d4abde222364f19f88c77d2b79", - "sha256": "0hzdy6bfj9xn5yjksa918n1hsj1kd584mapyyvhspbcqlr2b096h", + "rev": "ff9793cfd1a25145a7e591af604675b3d6f68987", + "sha256": "087fgyq4q1nr44h52zz3q3h21i1svgip27fp5csa5mz6yzqkqakv", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/e14f9fb57315f0d4abde222364f19f88c77d2b79.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/ff9793cfd1a25145a7e591af604675b3d6f68987.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } From 969d4ab92d29e06bdce9bb461d4c47fb8c6ec43d Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Tue, 27 Sep 2022 12:26:19 +0800 Subject: [PATCH 2/2] feat: rewrite existing mandate 1. Do not import Nix packages. Instead, expose them as Nix packages sources and let the call-site decide what to do with them. Therefore, renamed top-level `pkgs` attribute to `pkgs-sources`. 2. Make haskell tools agnostic to the Nix packages sources and compiler. Instead, expose functions to let the call-site decide which Nix packages sources or GHC compiler to use. --- README.md | 11 +++---- default.nix | 16 +++++++--- nix/default.nix | 15 --------- tools/haskell.nix | 79 ++++++++++++++++++++++++++++++++++++----------- 4 files changed, 77 insertions(+), 44 deletions(-) delete mode 100644 nix/default.nix diff --git a/README.md b/README.md index 4329c6f..9cde15d 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,11 @@ niv add telostat/telos.nix -n telosnix -b Currently, following expressions are exported: -| Path | Description | -| --------------------------------- | ----------------------------------------------------------------- | -| `pkgs.stable` | Stable `nixpkgs` (based on `release-22.05` `nixpkgs` branch) | -| `pkgs.unstable` | Unstable `nixpkgs` (based on `nixpkgs-unstable` `nixpkgs` branch) | -| `tools.haskell.haskell` | Haskell set based on `ghc902` compiler with overrides | -| `tools.haskell.packages.fourmolu` | [fourmolu](https://hackage.haskell.org/package/fourmolu) v0.8.2.0 | +| Path | Description | +| ----------------------- | ------------------------------------------------------------------------ | +| `pkgs-sources.stable` | Stable `nixpkgs` source (based on `release-22.05` `nixpkgs` branch) | +| `pkgs-sources.unstable` | Unstable `nixpkgs` source (based on `nixpkgs-unstable` `nixpkgs` branch) | +| `tools.haskell` | Various functions to make building Haskell development tools | ## License diff --git a/default.nix b/default.nix index 8a11ce4..d360428 100644 --- a/default.nix +++ b/default.nix @@ -1,13 +1,19 @@ +{ ... }: + let - nix = (import ./nix); + sources = import ./nix/sources.nix; in { - pkgs = { - stable = nix.pkgs; - unstable = nix.pkgs-unstable; + ## Pinned Nix package sources. + ## + ## These can be used in various projects to benefit from Nix caching. + pkgs-sources = { + stable = sources.nixpkgs; + unstable = sources.nixpkgs-unstable; }; + ## Categorized tools. tools = { - haskell = import ./tools/haskell.nix { }; + haskell = import ./tools/haskell.nix; }; } diff --git a/nix/default.nix b/nix/default.nix deleted file mode 100644 index 3a039f4..0000000 --- a/nix/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -let - ## Import sources: - sources = import ../nix/sources.nix; - - ## Pinned nixpkgs: - pkgs = import sources.nixpkgs { }; - - ## Pinned unstable nixpkgs: - pkgs-unstable = import sources.nixpkgs-unstable { }; -in -{ - sources = sources; - pkgs = pkgs; - pkgs-unstable = pkgs-unstable; -} diff --git a/tools/haskell.nix b/tools/haskell.nix index 6c79533..7db50eb 100644 --- a/tools/haskell.nix +++ b/tools/haskell.nix @@ -1,24 +1,67 @@ -{ compiler ? "ghc902" -, ... -}: - let - ## Pinned nixpkgs: - pkgs = (import ../nix).pkgs-unstable; - - ## Get the haskell set with overrides: - haskell = pkgs.haskell.packages.${compiler}.override { - overrides = self: super: with pkgs.haskell.lib; { - fourmolu = super.fourmolu_0_8_2_0; - Cabal = super.Cabal_3_6_3_0; - ghc-lib-parser = super.ghc-lib-parser_9_2_4_20220729; + ## Nix packages override configuration for Haskell development + ## tools. + ## + ## Usage: + ## + ## devpkgs = import { inherit config-dev-hs; }; + ## devpkgs = import telosnix.pkgs-sources.unstable { inherit config-dev-hs; }; + ## + ## Note that this is NOT for the package being developed. It can + ## have its own Nix packages source and configuration. This is + ## rather for the Haskell tools such as language server, linters, + ## formatters etc... + ## + ## The motivation is to: + ## + ## 1. Use latest Haskell development tools. + ## 2. Benefit from Nix binary caches. + ## + ## For the latter, you should be using the same underlying package + ## sources and GHC. + config-dev-hs = { + packageOverrides = pkgs: rec { + haskellPackages = pkgs.haskellPackages.override { + overrides = new: old: rec { + apply-refact = old.apply-refact_0_10_0_0; + Cabal = old.Cabal_3_6_3_0; + fourmolu = old.fourmolu_0_8_2_0; + ghc-lib-parser = old.ghc-lib-parser_9_2_4_20220729; + hlint = old.hlint_3_5; + }; + }; }; }; + + ## Imports and returns a given Nix packages source with our custom + ## Nix packages override configuration for Haskell development + ## tools. + get-haskell-development-packages = source: + import source { inherit config-dev-hs; }; + + ## Imports and returns a compiler specific Haskell packages set with + ## our custom Nix packages override configuration for Haskell + ## development tools. + get-haskell-development-compiler = source: compiler: + (get-haskell-development-packages source).haskell.packages.${compiler}; + + ## Returns common Haskell development tools for the given Nix + ## packages source with our custom Nix packages override + ## configuration for Haskell development tools. + get-haskell-development-tools = source: compiler: + let + haskell = get-haskell-development-compiler source compiler; + in + [ + haskell.apply-refact + haskell.fourmolu + haskell.haskell-language-server + haskell.hlint + ]; in { - haskell = haskell; - - packages = { - fourmolu = haskell.fourmolu; - }; + config-dev-hs = config-dev-hs; + get-haskell-development-packages = get-haskell-development-packages; + get-haskell-development-compiler = get-haskell-development-compiler; + get-haskell-development-tools = get-haskell-development-tools; }