From 87ec4517bc3f6760a81d28c79e25c386209819ce 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 | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 59 ++++++++++++++++ shell.nix | 9 +++ 3 files changed, 263 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..aad1b2596 --- /dev/null +++ b/flake.lock @@ -0,0 +1,195 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1627913399, + "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1627913399, + "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1629481132, + "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "997f7efcb746a9c140ce1f13c72263189225f482", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "flake": false, + "locked": { + "lastModified": 1611672876, + "narHash": "sha256-qHu3uZ/o9jBHiA3MEKHJ06k7w4heOhA+4HCSIvflRxo=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "211907489e9f198594c0eb0ca9256a1949c9d412", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "hls": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1639549452, + "narHash": "sha256-/LkwuvKeK9e1kCqxXTgWMN54XJ0J2jae36aKyxfw69E=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "854d2c5a1aa3095c93e3f38ef3731be89b4ab09a", + "type": "github" + }, + "original": { + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "854d2c5a1aa3095c93e3f38ef3731be89b4ab09a", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1639357775, + "narHash": "sha256-mJJFCPqZi1ZO3CvgEfN2nFAYv4uAJSRnTKzLFi61+WA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c473cc8714710179df205b153f4e9fa007107ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1639566195, + "narHash": "sha256-ZnTBGSV6bTwopdDibmsBaAkedmTZC/rOgwQzOGcOD+s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3c52ea8c9216a0d5b7a7b4d74a9d2e858b06df5c", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1639525045, + "narHash": "sha256-z4GXFNzO+5V4CAUm2DDMAryLOWUKEbQif2ifvv1Ypg4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a2e281f5770247855b85d70c43454ba5bff34613", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1624971177, + "narHash": "sha256-Amf/nBj1E77RmbSSmV+hg6YOpR+rddCbbVgo5C7BS0I=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "397f0713d007250a2c7a745e555fa16c5dc8cadb", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "hls": "hls", + "nixpkgs": "nixpkgs_3" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..15df1ab23 --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + description = "My haskell library"; + + nixConfig = { + extra-substituters = [ + "https://haskell-language-server.cachix.org" + ]; + extra-trusted-public-keys = [ + "haskell-language-server.cachix.org-1:juFfHrwkOxqIOZShtC4YC1uT1bBcq2RSvC7OMKx0Nz8=" + ]; + }; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + hls.url = "github:haskell/haskell-language-server/854d2c5a1aa3095c93e3f38ef3731be89b4ab09a"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, flake-utils, hls, ... }: + flake-utils.lib.eachSystem ["x86_64-linux"] (system: let + + pkgs = nixpkgs.legacyPackages.${system}; + + ghc8107 = pkgs.haskell.packages."ghc8107"; + + # modifier used in haskellPackages.developPackage + myModifier = hsPkgs: drv: let + compilerVersion = pkgs.lib.replaceStrings [ "." ] [ "" ] hsPkgs.ghc.version; + in + pkgs.haskell.lib.addBuildTools drv ([ + hsPkgs.cabal-install + hls.packages.${system}."haskell-language-server-${compilerVersion}" + pkgs.openssl.dev + pkgs.zlib + ]); + + 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; + }; + + defaultPackage = self.packages.${system}.cabal2nix; + }); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..b769069b9 --- /dev/null +++ b/shell.nix @@ -0,0 +1,9 @@ +(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