From 14d4edbe7776d674878f214bfd2875257b005293 Mon Sep 17 00:00:00 2001 From: pingu Date: Thu, 12 Oct 2023 15:01:36 +0200 Subject: [PATCH] Cabal init and added nix --- .envrc | 1 + .gitignore | 2 +- CHANGELOG.md | 5 ++++ LICENSE | 23 +++++++++++---- app/Main.hs | 4 +++ flake.lock | 61 ++++++++++++++++++++++++++++++++++++++ flake.nix | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hcdu.cabal | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 249 insertions(+), 7 deletions(-) create mode 100644 .envrc create mode 100644 CHANGELOG.md create mode 100644 app/Main.hs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 hcdu.cabal 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 index 6a62767..6cb66f1 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ cabal.project.local cabal.project.local~ .HTF/ .ghc.environment.* - +.direnv/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c5c0d02 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for hcdu + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/LICENSE b/LICENSE index b2aa40e..867b40a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,9 +1,20 @@ -MIT License +Copyright (c) 2023 Nor Führ -Copyright (c) 2023 pingu +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..65ae4a0 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello, Haskell!" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..51042c7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "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": 1696879762, + "narHash": "sha256-Ud6bH4DMcYHUDKavNMxAhcIpDGgHMyL/yaDEAVSImQY=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f99e5f03cc0aa231ab5950a15ed02afec45ed51a", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "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..85407e1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,82 @@ +{ + description = "hcdu goes flakes"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + nixConfig.allow-import-from-derivation = true; # cabal2nix uses IFD + + outputs = { self, nixpkgs, flake-utils }: + let + ghcVer = "ghc962"; + makeHaskellOverlay = overlay: final: prev: { + haskell = prev.haskell // { + packages = prev.haskell.packages // { + ${ghcVer} = prev.haskell.packages."${ghcVer}".override (oldArgs: { + overrides = + prev.lib.composeExtensions (oldArgs.overrides or (_: _: { })) + (overlay prev); + }); + }; + }; + }; + + out = system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ self.overlays.default ]; + config.allowBroken = true; + }; + + in + { + packages = rec { + default = hcdu; + hcdu = pkgs.haskell.packages.${ghcVer}.hcdu; + }; + + checks = { + inherit (self.packages.${system}) hcdu; + }; + + # for debugging + # inherit pkgs; + + devShells.default = + let haskellPackages = pkgs.haskell.packages.${ghcVer}; + in + haskellPackages.shellFor { + packages = p: [ self.packages.${system}.hcdu ]; + withHoogle = true; + buildInputs = + [ pkgs.docker ] ++ + (with haskellPackages; [ + haskell-language-server + cabal-install + ]); + # Change the prompt to show that you are in a devShell + # shellHook = "export PS1='\\e[1;34mdev > \\e[0m'"; + }; + }; + in + flake-utils.lib.eachDefaultSystem out // { + # this stuff is *not* per-system + overlays = { + default = makeHaskellOverlay (prev: hfinal: hprev: + let hlib = prev.haskell.lib; in + { + hcdu = hprev.callCabal2nix "hcdu" ./. { }; + + # here's how to do hacks to the package set + # don't run the test suite + # fast-tags = hlib.dontCheck hprev.fast-tags; + # + # don't check version bounds + # friendly = hlib.doJailbreak hprev.friendly; + }); + }; + }; +} diff --git a/hcdu.cabal b/hcdu.cabal new file mode 100644 index 0000000..7b6b8ee --- /dev/null +++ b/hcdu.cabal @@ -0,0 +1,78 @@ +cabal-version: 3.4 +-- The cabal-version field refers to the version of the .cabal specification, +-- and can be different from the cabal-install (the tool) version and the +-- Cabal (the library) version you are using. As such, the Cabal (the library) +-- version used must be equal or greater than the version stated in this field. +-- Starting from the specification version 2.2, the cabal-version field must be +-- the first thing in the cabal file. + +-- Initial package description 'hcdu' generated by +-- 'cabal init'. For further documentation, see: +-- http://haskell.org/cabal/users-guide/ +-- +-- The name of the package. +name: hcdu + +-- The package version. +-- See the Haskell package versioning policy (PVP) for standards +-- guiding when and how versions should be incremented. +-- https://pvp.haskell.org +-- PVP summary: +-+------- breaking API changes +-- | | +----- non-breaking API additions +-- | | | +--- code changes with no API change +version: 0.1.0.0 + +-- A short (one-line) description of the package. +-- synopsis: + +-- A longer description of the package. +-- description: + +-- The license under which the package is released. +license: MIT + +-- The file containing the license text. +license-file: LICENSE + +-- The package author(s). +author: Nor Führ + +-- An email address to which users can send suggestions, bug reports, and patches. +maintainer: nor@acorneroftheweb.com + +-- A copyright notice. +-- copyright: +category: System +build-type: Simple + +-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: + +common warnings + ghc-options: -Wall + +executable hcdu + -- Import common warning flags. + import: warnings + + -- .hs or .lhs file containing the Main module. + main-is: Main.hs + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + other-extensions: + LambdaCase + + -- Other library packages from which modules are imported. + build-depends: base ^>=4.18.1.0 + + -- Directories containing source files. + hs-source-dirs: app + + -- Base language which the package is written in. + default-language: GHC2021