From ff8f308e4ce17ebdc88cdf1574538d210df8edc1 Mon Sep 17 00:00:00 2001 From: Gabriella Gonzalez Date: Thu, 1 Dec 2022 12:32:58 -0800 Subject: [PATCH 1/5] Flake-enable project The immediate motivation for doing this was that the old `shell.nix` failed with the `nixpkgs` channel that I had installed. While I was fixing this to pin `nixpkgs` I figured this would be a good time to flake-enable the project. --- default.nix | 10 ++++++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++ flake.nix | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 48 ++++++----------------------- 4 files changed, 168 insertions(+), 38 deletions(-) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/default.nix b/default.nix new file mode 100644 index 000000000..2cccff28d --- /dev/null +++ b/default.nix @@ -0,0 +1,10 @@ +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..e8e5e7e3a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1652776076, + "narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "v1.0.0", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1669926280, + "narHash": "sha256-FP+ko5UBkGDWzmS12aP2yq7ZMVYC25JkpBpWzWSKjqI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b7143a45499e7c2689ef13e0962751ab39347ed9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..81bc6389d --- /dev/null +++ b/flake.nix @@ -0,0 +1,87 @@ +{ inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/release-22.11"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + + flake-utils.url = "github:numtide/flake-utils/v1.0.0"; + }; + + outputs = { nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + ghcVersion = "ghc90"; + + config = { }; + + overlay = self: super: { + haskell = super.haskell // { + packages = super.haskell.packages // { + "${ghcVersion}" = super.haskell.packages."${ghcVersion}".override (old: { + overrides = + self.lib.composeExtensions + (old.overrides or (_: _: { })) + (hself: hsuper: { + # The reason we stick these underneath a `local` attribute + # is to avoid infinite recursion (because `callCabal2nix` + # depends on all of these packages. + local = rec { + cabal2nix = + hself.callCabal2nix "cabal2nix" ./cabal2nix { + inherit distribution-nixpkgs hackage-db; + }; + + distribution-nixpkgs = + hself.callCabal2nix + "distribution-nixpkgs" + ./distribution-nixpkgs + { inherit language-nix; }; + + hackage-db = + hself.callCabal2nix "hackage-db" ./hackage-db { }; + + language-nix = + hself.callCabal2nix "language-nix" ./language-nix { }; + }; + }); + }); + }; + }; + }; + + pkgs = + import nixpkgs { inherit config system; overlays = [ overlay ]; }; + + in + rec { + packages = rec { + inherit (pkgs.haskell.packages."${ghcVersion}".local) + cabal2nix + hackage-db + distribution-nixpkgs + language-nix + ; + + default = cabal2nix; + }; + + devShells = rec { + cabal2nix = + pkgs.haskell.packages."${ghcVersion}".local.cabal2nix.env; + + distribution-nixpkgs = + pkgs.haskell.packages."${ghcVersion}".local.distribution-nixpkgs.env; + + hackage-db = + pkgs.haskell.packages."${ghcVersion}".local.hackage-db.env; + + language-nix = + pkgs.haskell.packages."${ghcVersion}".local.language-nix.env; + + default = cabal2nix; + }; + } + ); +} diff --git a/shell.nix b/shell.nix index 76f794e5d..6234bb4d6 100644 --- a/shell.nix +++ b/shell.nix @@ -1,38 +1,10 @@ -{ pkgs ? import { } -, ghcVersion ? pkgs.haskellPackages.ghc.version -, withHls ? true -}: - -let - haskellPackages = pkgs.haskell.packages."ghc${ - builtins.replaceStrings [ "." ] [ "" ] ghcVersion - }"; - ghc = haskellPackages.ghcWithHoogle (hps: [ - hps.ansi-wl-pprint - hps.hopenssl - hps.hpack - hps.lens - hps.optparse-applicative - hps.pretty - hps.split - hps.yaml - hps.monad-par - hps.monad-par-extras - hps.tasty - hps.tasty-golden - hps.utf8-string - hps.tar - hps.hspec - hps.parsec-class - ]); - -in pkgs.mkShell { - packages = [ - ghc - pkgs.cabal-install - pkgs.haskell-ci - (pkgs.lib.getLib pkgs.openssl) - ] ++ pkgs.lib.optionals withHls [ - haskellPackages.haskell-language-server - ]; -} +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).shellNix From 8227124903f8b35d7811328a20e827bf9ac131e0 Mon Sep 17 00:00:00 2001 From: Gabriella Gonzalez Date: Thu, 1 Dec 2022 13:48:59 -0800 Subject: [PATCH 2/5] Track `nixpkgs-unstable` instead of a specific release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … so that developers can easily track changes to `nixpkgs` … based on feedback from @sternenseemann --- flake.lock | 8 ++++---- flake.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index e8e5e7e3a..7c5aa683b 100644 --- a/flake.lock +++ b/flake.lock @@ -34,16 +34,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1669926280, - "narHash": "sha256-FP+ko5UBkGDWzmS12aP2yq7ZMVYC25JkpBpWzWSKjqI=", + "lastModified": 1669900182, + "narHash": "sha256-EKxjHxRJnP1w+2nnm8pq4Uqkqa5McnfPXcO8cG8Mxzc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b7143a45499e7c2689ef13e0962751ab39347ed9", + "rev": "bcb6dbbe30ce7631e5a0865dff1ab9b63d92977d", "type": "github" }, "original": { "owner": "NixOS", - "ref": "release-22.11", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 81bc6389d..9855c4789 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/release-22.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-compat = { url = "github:edolstra/flake-compat"; From 01313894074ec23914b63dba1df28779f3545da1 Mon Sep 17 00:00:00 2001 From: Gabriella Gonzalez Date: Thu, 1 Dec 2022 13:49:59 -0800 Subject: [PATCH 3/5] Remove `package` outputs In other words, only use the flake to provide development shells This is based on feedback from @sternenseemann that we don't want downstream flakes to depend on `cabal2nix` as a flake input --- flake.nix | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/flake.nix b/flake.nix index 9855c4789..80d3cd022 100644 --- a/flake.nix +++ b/flake.nix @@ -56,17 +56,6 @@ in rec { - packages = rec { - inherit (pkgs.haskell.packages."${ghcVersion}".local) - cabal2nix - hackage-db - distribution-nixpkgs - language-nix - ; - - default = cabal2nix; - }; - devShells = rec { cabal2nix = pkgs.haskell.packages."${ghcVersion}".local.cabal2nix.env; From 5278239988b77cf20dc1918bc8866e27503b04bf Mon Sep 17 00:00:00 2001 From: Gabriella Gonzalez Date: Thu, 1 Dec 2022 13:52:09 -0800 Subject: [PATCH 4/5] Add `language-nix` dependency to `cabal2nix` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … as caught by @sternenseemann --- flake.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 80d3cd022..3d42acde0 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,11 @@ local = rec { cabal2nix = hself.callCabal2nix "cabal2nix" ./cabal2nix { - inherit distribution-nixpkgs hackage-db; + inherit + distribution-nixpkgs + hackage-db + language-nix + ; }; distribution-nixpkgs = From 3f39ad651476f87bbe27a31b1ef705dfb6eea64e Mon Sep 17 00:00:00 2001 From: Gabriella Gonzalez Date: Thu, 1 Dec 2022 13:54:23 -0800 Subject: [PATCH 5/5] Remove `default.nix` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … which doesn't work now because we removed the packages from the outputs --- default.nix | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 default.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index 2cccff28d..000000000 --- a/default.nix +++ /dev/null @@ -1,10 +0,0 @@ -(import - ( - let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } - ) - { src = ./.; } -).defaultNix