From ee72ffbd8cb4f180e19a83927c346bcc3c1e6806 Mon Sep 17 00:00:00 2001 From: Dhananjay Balan Date: Wed, 15 Nov 2023 09:47:53 +0100 Subject: [PATCH] flake: init flake support --- blogng.cabal | 6 +++--- default.nix | 21 ------------------ flake.lock | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 24 deletions(-) delete mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/blogng.cabal b/blogng.cabal index 729b714..fe419ac 100644 --- a/blogng.cabal +++ b/blogng.cabal @@ -5,9 +5,9 @@ cabal-version: >= 1.10 executable site main-is: site.hs - build-depends: base == 4.* - , hakyll == 4.13.* - , filepath >= 1.4 + build-depends: base + , hakyll + , filepath , regex-compat ghc-options: -threaded default-language: Haskell2010 diff --git a/default.nix b/default.nix deleted file mode 100644 index 7b0292b..0000000 --- a/default.nix +++ /dev/null @@ -1,21 +0,0 @@ -# Development workflow -# - Executing nix-build builds the packages -# - Executing nix-shell returns a shell environment containing -# 1. Haskell packages needed -# 2. Hoogle files for packages -# 3. cabal and ghcid installed -{ pkgs ? import {} -}: -pkgs.haskellPackages.developPackage { - root = ./.; - name = "blogng"; - modifier = drv: - # add buildtools such as cabal - pkgs.haskell.lib.addBuildTools drv - (with pkgs.haskellPackages; [ - cabal-install - ghcid - # install hoogle files for packages we use. - #(hoogleLocal {packages = drv.propagatedBuildInputs;}) - ]); -} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ba7113d --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700037593, + "narHash": "sha256-Jy5mdQKTONK5M3pE7aQUFudDOOz+prpwJYAL2HbJsE4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "28189330044e1fe145c55dc9560474121ae21ad9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..30c77d0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,55 @@ +{ + description = "blogng"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + haskellPackages = pkgs.haskellPackages; + + builder = pkgs.haskellPackages.callCabal2nix "blogng" ./. { }; + in { + + packages.default = self.packages.${system}.website; + defaultPackage = self.packages.${system}.default; + + packages.website = pkgs.stdenv.mkDerivation rec { + name = "blog"; + LANG = "en_US.UTF-8"; + LC_ALL = "en_US.UTF-8"; + LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; + + src = ./.; + + # use the haskell package to build the website + buildInputs = [ builder ]; + allowSubstitutes = false; + buildPhase = '' + mkdir public + ${builder}/bin/site build + ''; + installPhase = '' + mkdir -p $out/ + cp -R public/* $out/ + ''; + dontStrip = true; + }; + + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + haskellPackages.haskell-language-server # you must build it with your ghc to work + ghcid + cabal-install + ]; + inputsFrom = + map (__getAttr "env") (__attrValues self.packages.${system}); + }; + devShell = self.devShells.${system}.default; + }); +}