From 0fca1ef401cad90821296bab1b1fdcaf11d0d65a Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Wed, 15 Dec 2021 19:00:41 +0100 Subject: [PATCH] build: add flake.nix run `nix develop` to get a development environment --- flake.lock | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 47 ++++++++++++++++++++++++++++++++++++++++++ shell.nix | 38 ++++++++-------------------------- 3 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..3f4705262 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1641205782, + "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1646939531, + "narHash": "sha256-bxOjVqcsccCNm+jSmEh/bm0tqfE3SdjwS+p+FZja3ho=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "fcd48a5a0693f016a5c370460d0c2a8243b882dc", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "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..2a31ca2e5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,47 @@ +{ + description = "Generate Nix build instructions from a Cabal file"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: let + + pkgs = nixpkgs.legacyPackages.${system}; + + ghc8107 = pkgs.haskell.packages."ghc8107"; + + # modifier used in haskellPackages.developPackage + myModifier = hsPkgs: drv: + pkgs.haskell.lib.addBuildTools drv ([ + hsPkgs.cabal-install + hsPkgs.haskell-language-server + ]); + + mkPackage = hsPkgs: + hsPkgs.developPackage { + root = pkgs.lib.cleanSource ./. ; + name = "cabal2nix"; + returnShellEnv = false; + withHoogle = true; + modifier = myModifier hsPkgs; + }; + + in { + packages = { + cabal2nix = self.packages.${system}.cabal2nix-8107; + cabal2nix-8107 = mkPackage ghc8107; + }; + + devShell = self.packages.${system}.cabal2nix.envFunc {}; + + defaultPackage = self.packages.${system}.cabal2nix; + }); +} diff --git a/shell.nix b/shell.nix index 44f4e07c4..77bbd229b 100644 --- a/shell.nix +++ b/shell.nix @@ -1,31 +1,9 @@ -{ pkgs ? import {} }: - +(import ( let - haskellPackages = pkgs.haskellPackages; - ghc = haskellPackages.ghcWithHoogle (hps: [ - hps.ansi-wl-pprint - hps.distribution-nixpkgs - hps.hackage-db - hps.hopenssl - hps.hpack - hps.language-nix - hps.lens - hps.optparse-applicative - hps.pretty - hps.split - hps.yaml - hps.monad-par - hps.monad-par-extras - hps.tasty - hps.tasty-golden - ]); - -in pkgs.stdenv.mkDerivation { - name = "shell"; - buildInputs = [ - ghc - haskellPackages.cabal-install - haskellPackages.haskell-language-server - (pkgs.lib.getLib pkgs.openssl) - ]; -} + 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