chore: initialize project template

This commit is contained in:
♥ Minnie ♥ 2025-02-20 13:43:07 +08:00
commit 3857b5dfa3
Signed by: jasmine
GPG key ID: 8563E358D4E8040E
15 changed files with 3728 additions and 0 deletions

2
.envrc Normal file
View file

@ -0,0 +1,2 @@
watch_file *.cabal nix/modules/flake-parts/*.nix
use flake

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
flake.lock linguist-generated=true

14
.gitignore vendored Normal file
View file

@ -0,0 +1,14 @@
# cabal
dist
dist-*
cabal.project.local
cabal.project.local~
# nix
result
result-*
# direnv
.direnv
/.pre-commit-config.yaml

3293
.hlint.yaml Normal file

File diff suppressed because it is too large Load diff

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Jasmine Marie Wilson
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.

44
README.md Normal file
View file

@ -0,0 +1,44 @@
# xmonad-config
Get a Haskell development environment up and running quickly. Thanks to Nix, this template is optimized for a fully reproducible and friendly development environment. It is based on:
- [Nix](https://srid.ca/haskell-nix) + [Flakes](https://serokell.io/blog/practical-nix-flakes) (via [`github:srid/haskell-flake`](https://github.com/srid/haskell-flake)) + GHC 9.6
- VSCode + [HLS](https://github.com/haskell/haskell-language-server)
- [fourmolu](https://github.com/fourmolu/fourmolu) autoformatting
- [Relude](https://github.com/kowainik/relude) as Prelude.
- `.hlint.yaml` is [from relude](https://github.com/kowainik/relude/blob/main/.hlint.yaml)
- Devshell commands are provided via [just](https://just.systems/); run `just` in devshell.
If you have an *existing* Haskell project, you should probably use https://github.com/srid/haskell-flake instead.
## Getting Started
Initialize this template using:
```sh
nix --accept-flake-config run github:juspay/omnix -- \
init github:srid/xmonad-config -o ./yourproject
```
*tldr: [Install Nix](https://nixos.asia/en/install), [setup direnv](https://nixos.asia/en/direnv), open in VSCode, install recommended extensions and run `just run`.*
Full instructions: https://srid.ca/xmonad-config/start
Recommended dev environment setup: https://nixos.asia/en/direnv
## Tips
- Run `nix flake update` to update all flake inputs.
- Run `nix --accept-flake-config run github:juspay/omnix ci` to build _all_ outputs.
- [pre-commit] hooks will automatically be setup in Nix shell. You can also run `pre-commit run -a` manually to run the hooks (e.g.: to autoformat the project tree using fourmolu, nixpkgs-fmt, etc. as well run programs like hlint). The hooks will checked as part of flake checks (thus CI).
- Run `just docs` to start Hoogle with packages in your cabal file.
- Run the application without installing: `nix run github:srid/xmonad-config` (or `nix run .` from checkout)
- Common workflows
- Adding library dependencies in Nix: https://community.flake.parts/haskell-flake/dependency
- Adding tests: https://srid.ca/xmonad-config/tests
## Discussions
Questions? Ideas? Suggestions? Join our [NixOS Zulip](https://nixos.zulipchat.com/#narrow/stream/413949-haskell-flake) or post in [Github Discussions](https://github.com/srid/xmonad-config/discussions).
[pre-commit]: https://github.com/cachix/git-hooks.nix

113
flake.lock generated Normal file
View file

@ -0,0 +1,113 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1738453229,
"narHash": "sha256-7H9XgNiGLKN1G1CgRh0vUL4AheZSYzPm+zmZ7vxbJdo=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "32ea77a06711b758da0ad9bd6a844c5740a87abd",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"fourmolu-nix": {
"locked": {
"lastModified": 1707266073,
"narHash": "sha256-tCFzZQJicDdYjnuJiNK4hiiRAH7c2wQzMhOCdUMbVKE=",
"owner": "jedimahdi",
"repo": "fourmolu-nix",
"rev": "717f5a91b0d7b97b1be7ecc3a0fd42d37ffe1c9b",
"type": "github"
},
"original": {
"owner": "jedimahdi",
"repo": "fourmolu-nix",
"type": "github"
}
},
"git-hooks": {
"flake": false,
"locked": {
"lastModified": 1737465171,
"narHash": "sha256-R10v2hoJRLq8jcL4syVFag7nIGE7m13qO48wRIukWNg=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"haskell-flake": {
"locked": {
"lastModified": 1738519333,
"narHash": "sha256-QK7DIUmUC76cEBlntkDyBrhrZMD5fioCT2Xd6RbA8a8=",
"owner": "srid",
"repo": "haskell-flake",
"rev": "dcca937807b7190934118ae476865301885aef15",
"type": "github"
},
"original": {
"owner": "srid",
"repo": "haskell-flake",
"type": "github"
}
},
"nixos-unified": {
"locked": {
"lastModified": 1738770348,
"narHash": "sha256-PQYCNoZ0QvaX8kmMVTaPn8z+EDPsl0tZG3+o0Z1+9CM=",
"owner": "srid",
"repo": "nixos-unified",
"rev": "be4ce51cae1dda99e8fd57036215b19ef37bd7fd",
"type": "github"
},
"original": {
"owner": "srid",
"repo": "nixos-unified",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1738734093,
"narHash": "sha256-UEYOKfXXKU49fR7dGB05As0s2pGbLK4xDo48Qtdm7xs=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5b2753b0356d1c951d7a3ef1d086ba5a71fff43c",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"fourmolu-nix": "fourmolu-nix",
"git-hooks": "git-hooks",
"haskell-flake": "haskell-flake",
"nixos-unified": "nixos-unified",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

22
flake.nix Normal file
View file

@ -0,0 +1,22 @@
{
description = "Nix template for Haskell projects";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nixos-unified.url = "github:srid/nixos-unified";
haskell-flake.url = "github:srid/haskell-flake";
fourmolu-nix.url = "github:jedimahdi/fourmolu-nix";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.flake = false;
};
outputs = inputs:
# This will import ./nix/modules/flake/*.nix
# cf. https://nixos-unified.org/autowiring.html#flake-parts
#
# To write your own Nix, add or edit files in ./nix/modules/flake/
inputs.nixos-unified.lib.mkFlake
{ inherit inputs; root = ./.; };
}

2
hie.yaml Normal file
View file

@ -0,0 +1,2 @@
cradle:
cabal:

15
justfile Normal file
View file

@ -0,0 +1,15 @@
default:
@just --list
# Run hoogle
docs:
echo http://127.0.0.1:8888
hoogle serve -p 8888 --local
# Run cabal repl
repl *ARGS:
cabal repl {{ ARGS }}
# Run ghcid -- auto-recompile and run `main` function
run:
ghcid -T :main

View file

@ -0,0 +1,19 @@
{
perSystem = { config, pkgs, ... }: {
# Default shell.
devShells.default = pkgs.mkShell {
name = "xmonad-config";
meta.description = "Haskell development environment";
# See https://community.flake.parts/haskell-flake/devshell#composing-devshells
inputsFrom = [
config.haskellProjects.default.outputs.devShell # See ./nix/modules/haskell.nix
config.pre-commit.devShell # See ./nix/modules/formatter.nix
];
packages = with pkgs; [
just
nixd
ghciwatch
];
};
};
}

View file

@ -0,0 +1,62 @@
{ root, inputs, ... }:
{
imports = [
inputs.haskell-flake.flakeModule
];
perSystem = { self', lib, config, pkgs, ... }: {
# Our only Haskell project. You can have multiple projects, but this template
# has only one.
# See https://github.com/srid/haskell-flake/blob/master/example/flake.nix
haskellProjects.default = {
# To avoid unnecessary rebuilds, we filter projectRoot:
# https://community.flake.parts/haskell-flake/local#rebuild
projectRoot = builtins.toString (lib.fileset.toSource {
inherit root;
fileset = lib.fileset.unions [
(root + /src)
(root + /xmonad-config.cabal)
(root + /LICENSE)
(root + /README.md)
];
});
# The base package set (this value is the default)
# basePackages = pkgs.haskellPackages;
# Packages to add on top of `basePackages`
packages = {
# Add source or Hackage overrides here
# (Local packages are added automatically)
/*
aeson.source = "1.5.0.0" # Hackage version
shower.source = inputs.shower; # Flake input
*/
};
# Add your package overrides here
settings = {
xmonad-config = {
stan = true;
# haddock = false;
};
/*
aeson = {
check = false;
};
*/
};
# Development shell configuration
devShell = {
hlsCheck.enable = false;
};
# What should haskell-flake add to flake outputs?
autoWire = [ "packages" "apps" "checks" ]; # Wire all but the devShell
};
# Default package & app.
packages.default = self'.packages.xmonad-config;
apps.default = self'.apps.xmonad-config;
};
}

View file

@ -0,0 +1,32 @@
{ inputs, ... }:
{
imports = [
(inputs.git-hooks + /flake-module.nix)
inputs.fourmolu-nix.flakeModule
];
perSystem = { config, ... }: {
pre-commit.settings = {
hooks = {
nixpkgs-fmt.enable = true;
cabal-fmt.enable = true;
fourmolu = {
enable = true;
package = config.fourmolu.wrapper;
};
hlint.enable = true;
};
};
fourmolu.settings = {
indentation = 2;
comma-style = "leading";
record-brace-space = true;
indent-wheres = true;
import-export-style = "diff-friendly";
respectful = true;
haddock-style = "multi-line";
newlines-between-decls = 1;
extensions = [ "ImportQualifiedPost" ];
};
};
}

20
src/Main.hs Normal file
View file

@ -0,0 +1,20 @@
module Main where
import Main.Utf8 qualified as Utf8
data Example = Example
{ name :: Text
, age :: Int
}
deriving stock (Show, Eq)
{- |
Main entry point.
`just run` will invoke this function.
-}
main :: IO ()
main = do
-- For withUtf8, see https://serokell.io/blog/haskell-with-utf8
Utf8.withUtf8 $ do
putTextLn "Hello 🌎 (from xmonad-config)"

68
xmonad-config.cabal Normal file
View file

@ -0,0 +1,68 @@
cabal-version: 2.4
name: xmonad-config
version: 0.1.0.0
license: MIT
copyright: 2022 Jasmine Marie Wilson
maintainer: srid@srid.ca
author: Jasmine Marie Wilson
category: Web
homepage: https://srid.ca/xmonad-config
-- TODO: Before hackage release.
-- A short (one-line) description of the package.
synopsis: A template for Haskell projects using Nix
-- A longer description of the package.
-- description:
-- A URL where users can report bugs.
-- bug-reports:
extra-source-files:
LICENSE
README.md
common shared
ghc-options:
-Wall -Wincomplete-record-updates -Wincomplete-uni-patterns
-Wmissing-deriving-strategies -Wunused-foralls -Wunused-foralls
-fprint-explicit-foralls -fprint-explicit-kinds
mixins:
base hiding (Prelude),
relude (Relude as Prelude, Relude.Container.One),
relude
default-extensions:
DataKinds
DerivingStrategies
DerivingVia
LambdaCase
MultiWayIf
NoStarIsType
OverloadedStrings
StrictData
TypeFamilies
ViewPatterns
build-depends:
, aeson
, async
, base >=4 && <5
, data-default
, directory
, filepath
, mtl
, optics-core
, profunctors
, relude >=1.0
, shower
, time
, with-utf8
hs-source-dirs: src
default-language: GHC2021
executable xmonad-config
import: shared
main-is: Main.hs