Flake & cabal setup
This commit is contained in:
commit
fda4e7530c
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
.stack-work/
|
||||
dist-newstyle
|
||||
.vscode/
|
||||
*.swp
|
||||
result
|
||||
bench.html
|
||||
7
LICENSE
Normal file
7
LICENSE
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright 2025 Paul Brinkmeier
|
||||
|
||||
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 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.
|
||||
18
app/Main.hs
Normal file
18
app/Main.hs
Normal file
@ -0,0 +1,18 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import Database.PostgreSQL.LibPQ (connectdb)
|
||||
|
||||
import qualified Yore.DB
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
conn <- connectdb "host=localhost port=5432"
|
||||
result <- Yore.DB.getTables conn
|
||||
|
||||
case result of
|
||||
Left e ->
|
||||
putStrLn $ "Got error: " ++ show e
|
||||
Right rows ->
|
||||
mapM_ print rows
|
||||
107
flake.lock
generated
Normal file
107
flake.lock
generated
Normal file
@ -0,0 +1,107 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1709087332,
|
||||
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1752536923,
|
||||
"narHash": "sha256-fdgPZR7VFSSRIQKOJLcs3qCJBWM64Uak0gAGtWTYAd8=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c665e4d918eda5d78a175ed8d300809c44932160",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "release-25.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"opium": {
|
||||
"inputs": {
|
||||
"flake-utils": [
|
||||
"flake-utils"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1752596794,
|
||||
"narHash": "sha256-1J3tNaosj3DCQuzDCPdbEbOd5ZQuqIOAVD7o5hFNx+g=",
|
||||
"ref": "main",
|
||||
"rev": "3879c2603fa124087a3ed810903bf75d38a27598",
|
||||
"revCount": 56,
|
||||
"type": "git",
|
||||
"url": "https://git.pbrinkmeier.de/paul/opium"
|
||||
},
|
||||
"original": {
|
||||
"ref": "main",
|
||||
"type": "git",
|
||||
"url": "https://git.pbrinkmeier.de/paul/opium"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"gitignore": "gitignore",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"opium": "opium"
|
||||
}
|
||||
},
|
||||
"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
|
||||
}
|
||||
80
flake.nix
Normal file
80
flake.nix
Normal file
@ -0,0 +1,80 @@
|
||||
{
|
||||
description = "Le olde newspaper display";
|
||||
|
||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/release-25.05";
|
||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||
inputs.gitignore = {
|
||||
url = "github:hercules-ci/gitignore.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
inputs.opium = {
|
||||
url = "git+https://git.pbrinkmeier.de/paul/opium?ref=main";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.flake-utils.follows = "flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, gitignore, opium }:
|
||||
flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux" "aarch64-darwin"] (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
|
||||
inherit (pkgs.haskell.lib) compose;
|
||||
|
||||
# Include opium in package set
|
||||
addOpium = self: super: {
|
||||
opium = opium.packages.${system}.opium;
|
||||
};
|
||||
|
||||
# For building the package, we use only the files not ignored by Git as inputs.
|
||||
# Also, flake.nix and flake.lock are not included to avoid rebuilds when
|
||||
# working on them.
|
||||
src = pkgs.lib.cleanSourceWith {
|
||||
src = gitignore.lib.gitignoreSource ./.;
|
||||
filter = path: type: builtins.elem (builtins.baseNameOf path) [ "flake.nix" "flake.lock" ];
|
||||
};
|
||||
|
||||
yore = pkgs.lib.pipe
|
||||
# The basic package
|
||||
(pkgs.haskellPackages.developPackage {
|
||||
root = ./.;
|
||||
overrides = addOpium;
|
||||
})
|
||||
# And some build configuration.
|
||||
# See https://nixos.org/manual/nixpkgs/unstable/#haskell-packaging-helpers.
|
||||
[
|
||||
# Remove warp which pulls GHC into the runtime deps for some reason.
|
||||
(compose.overrideCabal (drv: {
|
||||
postInstall = ''
|
||||
remove-references-to -t ${pkgs.haskellPackages.warp} $out/bin/yore
|
||||
'';
|
||||
}))
|
||||
# Return only the bin folder to curb image size
|
||||
compose.justStaticExecutables
|
||||
];
|
||||
in {
|
||||
packages = rec {
|
||||
docker =
|
||||
pkgs.dockerTools.buildImage {
|
||||
name = "git.pbrinkmeier.de/paul/yore";
|
||||
tag = yore.version;
|
||||
config.Cmd = [ "${yore}/bin/yore" ];
|
||||
};
|
||||
|
||||
default = yore;
|
||||
|
||||
opium_ = opium.packages.${system}.opium;
|
||||
};
|
||||
|
||||
devShells.default =
|
||||
(pkgs.haskellPackages.developPackage {
|
||||
root = ./.;
|
||||
modifier = drv:
|
||||
pkgs.haskell.lib.addBuildTools drv [
|
||||
pkgs.cabal-install
|
||||
pkgs.haskellPackages.implicit-hie
|
||||
pkgs.haskell-language-server
|
||||
];
|
||||
overrides = addOpium;
|
||||
}).env;
|
||||
});
|
||||
}
|
||||
7
hie.yaml
Normal file
7
hie.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
cradle:
|
||||
cabal:
|
||||
- path: "src"
|
||||
component: "lib:yore"
|
||||
|
||||
- path: "app/Main.hs"
|
||||
component: "yore:exe:yore"
|
||||
21
src/Yore/DB.hs
Normal file
21
src/Yore/DB.hs
Normal file
@ -0,0 +1,21 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Yore.DB
|
||||
( Table (..)
|
||||
, getTables
|
||||
) where
|
||||
|
||||
import Database.PostgreSQL.LibPQ (Connection)
|
||||
import GHC.Generics (Generic)
|
||||
|
||||
import qualified Database.PostgreSQL.Opium as Opium
|
||||
|
||||
data Table = Table
|
||||
{ schema :: String
|
||||
, name :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
instance Opium.FromRow Table
|
||||
|
||||
getTables :: Connection -> IO (Either Opium.Error [Table])
|
||||
getTables = Opium.fetch_ "SELECT table_schema AS schema, table_name AS name FROM information_schema.tables"
|
||||
13
src/Yore/Repl.hs
Normal file
13
src/Yore/Repl.hs
Normal file
@ -0,0 +1,13 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Yore.Repl (connect, exec) where
|
||||
|
||||
import qualified Database.PostgreSQL.LibPQ as LibPQ
|
||||
|
||||
import Database.PostgreSQL.LibPQ (Connection)
|
||||
|
||||
connect :: IO Connection
|
||||
connect = LibPQ.connectdb "host=localhost"
|
||||
|
||||
exec :: (Connection -> IO a) -> IO a
|
||||
exec f = f =<< connect
|
||||
64
yore.cabal
Normal file
64
yore.cabal
Normal file
@ -0,0 +1,64 @@
|
||||
cabal-version: 3.4
|
||||
|
||||
name: yore
|
||||
version: 0
|
||||
author: Paul Brinkmeier
|
||||
maintainer: hallo@pbrinkmeier.de
|
||||
copyright: 2023 Paul Brinkmeier
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
build-type: Simple
|
||||
extra-source-files:
|
||||
README.md
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: https://git.pbrinkmeier.de/paul/yore
|
||||
|
||||
common shared-options
|
||||
ghc-options:
|
||||
-Wall
|
||||
-Wcompat
|
||||
-Widentities
|
||||
-Wincomplete-record-updates
|
||||
-Wincomplete-uni-patterns
|
||||
-Wmissing-export-lists
|
||||
-Wmissing-home-modules
|
||||
-Wpartial-fields
|
||||
-Wredundant-constraints
|
||||
default-language: GHC2021
|
||||
|
||||
library
|
||||
import: shared-options
|
||||
exposed-modules:
|
||||
Yore.DB
|
||||
, Yore.Repl
|
||||
hs-source-dirs:
|
||||
src
|
||||
build-depends:
|
||||
base >=4.18 && <5
|
||||
, opium
|
||||
, postgresql-libpq
|
||||
|
||||
executable yore
|
||||
import: shared-options
|
||||
main-is: Main.hs
|
||||
hs-source-dirs:
|
||||
app
|
||||
ghc-options:
|
||||
-threaded
|
||||
-rtsopts
|
||||
-with-rtsopts=-N
|
||||
-ghci-script=.ghci
|
||||
build-depends:
|
||||
yore
|
||||
, base >=4.18 && <5
|
||||
, blaze-html
|
||||
, bytestring
|
||||
, http-media
|
||||
, opium
|
||||
, postgresql-libpq
|
||||
, servant-server
|
||||
, text
|
||||
, wai
|
||||
, warp
|
||||
Loading…
x
Reference in New Issue
Block a user