From 5d02a9e42405a7db46b11db7d3916cc202d7d9d9 Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Mon, 9 Oct 2023 18:45:47 +0200 Subject: [PATCH] Instantiate haskell template --- .envrc | 1 + .gitignore | 3 ++ README.org | 7 +++++ app/filepack.hs | 6 ++++ filepack.cabal | 39 ++++++++++++++++++++++++ flake.lock | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 67 +++++++++++++++++++++++++++++++++++++++++ package.yaml | 29 ++++++++++++++++++ src/FilePack.hs | 11 +++++++ 9 files changed, 242 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 README.org create mode 100644 app/filepack.hs create mode 100644 filepack.cabal create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.yaml create mode 100644 src/FilePack.hs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6622ec1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.pre-commit-config.yaml +result +.direnv diff --git a/README.org b/README.org new file mode 100644 index 0000000..0ec719a --- /dev/null +++ b/README.org @@ -0,0 +1,7 @@ +#+TITLE: FilePack - A library and tool to bundle up files + +* What is it? + +#+begin_quote +Throughout this chapter, you’ll work through building a library for a tool called filepack. The FilePack library that we build will allow users to create archives of files that can be saved to disk, stored in a database, or sent over the internet. The examples you build as you work through this chapter will only support the programmatic creation and extraction of archives, but you are encouraged to create a complete application around this library as an additional example. +#+end_quote diff --git a/app/filepack.hs b/app/filepack.hs new file mode 100644 index 0000000..85d2730 --- /dev/null +++ b/app/filepack.hs @@ -0,0 +1,6 @@ +module Main (main) where + +import FilePack (greet) + +main :: IO () +main = greet "Hello, World!" diff --git a/filepack.cabal b/filepack.cabal new file mode 100644 index 0000000..39f4312 --- /dev/null +++ b/filepack.cabal @@ -0,0 +1,39 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.34.7. +-- +-- see: https://github.com/sol/hpack + +name: filepack +version: 0.0.1.0 +author: Alexander Kobjolke +maintainer: alex@jakalx.net +copyright: Alexander Kobjolke 2022 +license: MIT +build-type: Simple +extra-source-files: + README.org + +library + exposed-modules: + FilePack + other-modules: + Paths_filepack + hs-source-dirs: + src + ghc-options: -Wall + build-depends: + base >=4.13 && <5 + default-language: GHC2021 + +executable filepack + main-is: filepack.hs + other-modules: + Paths_filepack + hs-source-dirs: + app + ghc-options: -Wall + build-depends: + base >=4.13 && <5 + , filepack + default-language: GHC2021 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..fbc46f6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,79 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "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": 1661626419, + "narHash": "sha256-CjdPtdwH7I5Es4SjdCGuNfeulIyaM1LP0dXGWi4dyuQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a5e05d62460ff0b7627559a8b55ab421041ebf0a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660830093, + "narHash": "sha256-HUhx3a82C7bgp2REdGFeHJdhEAzMGCk3V8xIvfBqg1I=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "8cb8ea5f1c7bc2984f460587fddd5f2e558f6eb8", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5c9dedd --- /dev/null +++ b/flake.nix @@ -0,0 +1,67 @@ +{ + description = "Haskell Nix Template"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + + flake-utils.url = "github:numtide/flake-utils"; + + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }: + flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + overlay = final: prev: { + filepack = final.callCabal2nix "filepack" ./. { }; + }; + + haskellPackages = pkgs.haskell.packages.ghc924.extend overlay; + in { + packages.default = haskellPackages.filepack; + + apps = { + default = { + type = "app"; + program = "${self.defaultPackage.${system}}/bin/hello"; + }; + }; + + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + settings = { ormolu.defaultExtensions = [ "GHC2021" ]; }; + tools.fourmolu = haskellPackages.fourmolu; + hooks = { + nixfmt.enable = true; + fourmolu.enable = true; + hpack.enable = true; + hlint.enable = true; + }; + }; + }; + + devShells.default = haskellPackages.shellFor { + inherit (self.checks.${system}.pre-commit-check) shellHook; + + packages = p: [ p.filepack ]; + + withHoogle = true; + + nativeBuildInputs = with pkgs; [ + haskellPackages.haskell-language-server + haskellPackages.fourmolu + haskellPackages.hspec-discover + haskellPackages.doctest + cabal-install + ghcid + nixfmt + hpack + hlint + ]; + }; + }); +} diff --git a/package.yaml b/package.yaml new file mode 100644 index 0000000..9a610aa --- /dev/null +++ b/package.yaml @@ -0,0 +1,29 @@ +name: filepack +version: 0.0.1.0 +license: MIT +author: "Alexander Kobjolke" +maintainer: "alex@jakalx.net" +copyright: "Alexander Kobjolke 2022" + +extra-source-files: + - README.org + +dependencies: + - base >= 4.13 && < 5 + +ghc-options: + - -Wall + +library: + source-dirs: src + verbatim: + default-language: GHC2021 + +executables: + filepack: + source-dirs: app + main: filepack.hs + dependencies: + - filepack + verbatim: + default-language: GHC2021 diff --git a/src/FilePack.hs b/src/FilePack.hs new file mode 100644 index 0000000..1c106f2 --- /dev/null +++ b/src/FilePack.hs @@ -0,0 +1,11 @@ +module FilePack ( + greet, +) where + +import Control.Monad.IO.Class ( + MonadIO, + liftIO, + ) + +greet :: MonadIO m => String -> m () +greet = liftIO <$> putStrLn