about summary refs log tree commit diff
path: root/flake.nix
diff options
context:
space:
mode:
authortzlil <tzlils@protonmail.com>2023-04-15 16:17:50 +0300
committertzlil <tzlils@protonmail.com>2023-04-15 16:17:50 +0300
commitbc8ca82ea5432adbe80527ba23fb1ff8b37009c0 (patch)
tree3f1b19af47c95f3bc23297f09f3dc66a6e03e5c4 /flake.nix
parent13c980689fa9f0b4f1adb32a8b46b31ac3a19903 (diff)
improve flake
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix88
1 files changed, 56 insertions, 32 deletions
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