From bc8ca82ea5432adbe80527ba23fb1ff8b37009c0 Mon Sep 17 00:00:00 2001 From: tzlil Date: Sat, 15 Apr 2023 16:17:50 +0300 Subject: improve flake --- .gitignore | 1 + flake.lock | 66 +++++++++++++++------------------------------ flake.nix | 88 ++++++++++++++++++++++++++++++++++++++---------------------- lambda.cabal | 44 +++++++++++++----------------- 4 files changed, 98 insertions(+), 101 deletions(-) diff --git a/.gitignore b/.gitignore index 4fbd9bc..59e0da5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ tests/runtests.log tests/out .stack-work *.lock +dist-newstyle diff --git a/flake.lock b/flake.lock index fe99fdd..7d02ac3 100644 --- a/flake.lock +++ b/flake.lock @@ -1,48 +1,30 @@ { "nodes": { - "flake-parts": { + "flake-utils": { "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] + "systems": "systems" }, "locked": { - "lastModified": 1680392223, - "narHash": "sha256-n3g7QFr85lDODKt250rkZj2IFS3i4/8HBU2yKHO3tqw=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "dcc36e45d054d7bb554c9cdab69093debd91a0b5", + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", "type": "github" }, "original": { - "owner": "hercules-ci", - "repo": "flake-parts", + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1681358109, - "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "lastModified": 1681465517, + "narHash": "sha256-EasJh15/jcJNAHtq2SGbiADRXteURAnQbj1NqBoKkzU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1680945546, - "narHash": "sha256-8FuaH5t/aVi/pR1XxnF0qi4WwMYC+YxlfdsA0V+TEuQ=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "d9f759f2ea8d265d974a6e1259bd510ac5844c5d", + "rev": "abe7316dd51a313ce528972b104f4f04f56eefc4", "type": "github" }, "original": { @@ -54,26 +36,22 @@ }, "root": { "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs", - "treefmt-nix": "treefmt-nix" + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" } }, - "treefmt-nix": { - "inputs": { - "nixpkgs": "nixpkgs_2" - }, + "systems": { "locked": { - "lastModified": 1681115235, - "narHash": "sha256-VCETW6vOzNlByc0A5gTJoFE9L/ikP91rX6XynBUgIno=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "f3dd071be31528261034022020fc7e4c010f7179", + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { - "owner": "numtide", - "repo": "treefmt-nix", + "owner": "nix-systems", + "repo": "default", "type": "github" } } diff --git a/flake.nix b/flake.nix index f513119..3812ed2 100644 --- a/flake.nix +++ b/flake.nix @@ -1,37 +1,61 @@ + { inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; - treefmt-nix.url = "github:numtide/treefmt-nix"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + flake-utils = { + url = "github:numtide/flake-utils"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = inputs: - inputs.flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ "x86_64-linux" ]; - imports = [ - inputs.treefmt-nix.flakeModule - ]; - - perSystem = { pkgs, ... }: { - packages.default = pkgs.haskellPackages.callCabal2nix "example" ./. { }; - - devShells.default = pkgs.haskellPackages.shellFor { - packages = ps: [ ]; - buildInputs = with pkgs.haskellPackages; [ - cabal-install - haskell-language-server - megaparsec - stack + outputs = { flake-utils, nixpkgs, self }: + flake-utils.lib.eachDefaultSystem + (system: + let + config = {}; + + overlays = [ + # This is an overlay we apply on top of Nixpkgs with some of our + # own packages defined. + (final: prev: { + # A Haskell package set with our own overrides and packages defined. + myHaskellPackages = final.haskellPackages.override { + overrides = hfinal: hprev: { + # This is our local Haskell package. + package = + hfinal.callCabal2nix "package" ./. {}; + }; + }; + + # This is just a convenient shortcut to our package from the + # top-level of Nixpkgs. We're also applying the + # justStaticExecutables function to our package in order to + # reduce the size of the output derivation. + package = + final.haskell.lib.compose.justStaticExecutables + final.myHaskellPackages.package; + + # A Haskell development shell for our package that includes + # things like cabal and HLS. + myDevShell = final.myHaskellPackages.shellFor { + packages = p: [ p.package ]; + + nativeBuildInputs = [ + final.cabal-install + final.haskellPackages.haskell-language-server + ]; + }; + }) ]; - }; - treefmt = { - projectRootFile = "flake.nix"; - programs.nixpkgs-fmt.enable = true; - programs.cabal-fmt.enable = true; - programs.ormolu.enable = true; - programs.hlint.enable = true; - programs.ormolu.package = pkgs.haskellPackages.fourmolu; - }; - }; - }; -} + + # Our full Nixpkgs with the above overlay applied. + pkgs = import nixpkgs { inherit config overlays system; }; + in + { + packages.default = pkgs.package; + + devShells.default = pkgs.myDevShell; + } + ); +} \ No newline at end of file diff --git a/lambda.cabal b/lambda.cabal index aee89e6..6189111 100644 --- a/lambda.cabal +++ b/lambda.cabal @@ -1,4 +1,4 @@ -cabal-version: 1.12 +cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.35.2. -- @@ -11,39 +11,33 @@ maintainer: sedwards@cs.columbia.edu copyright: 2023 John Hui and Stephen Edwards license: BSD3 build-type: Simple -extra-source-files: README.md +extra-source-files: + README.md library exposed-modules: - AST - HW - Parse - - other-modules: Paths_lambda - hs-source-dirs: src - ghc-options: - -Wall -Wcompat -Widentities -Wincomplete-record-updates - -Wincomplete-uni-patterns -Wmissing-export-lists - -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints - + AST + HW + Parse + other-modules: + Paths_lambda + hs-source-dirs: + src + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: - base >=4.7 && <5 + base >=4.7 && <5 , containers , megaparsec - default-language: Haskell2010 executable plc - main-is: Main.hs - other-modules: Paths_lambda - hs-source-dirs: plc - ghc-options: - -Wall -Wcompat -Widentities -Wincomplete-record-updates - -Wincomplete-uni-patterns -Wmissing-export-lists - -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints - + main-is: Main.hs + other-modules: + Paths_lambda + hs-source-dirs: + plc + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: - base >=4.7 && <5 + base >=4.7 && <5 , lambda - default-language: Haskell2010 -- cgit 1.4.1