Skip to content

Commit bf9f458

Browse files
authored
Merge pull request #61 from chfanghr/connor/templates
Add templates for quickly creating new projects
2 parents d87b623 + 423cfe2 commit bf9f458

40 files changed

+817
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ cabal.sandbox.config
2626
.stack-work/
2727
.HTF/
2828
.ghc.environment.*
29-
.direnv/
29+
.direnv/
30+
dist-newstyle/

flake-lang/flake-haskell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let
66
, name
77
, dependencies ? [ ]
88
, devShellTools ? [ ]
9-
, devShellHook
9+
, devShellHook ? ""
1010
, devShellAdditionalPackages ? _: [ ]
1111
, index-state
1212
, compiler-nix-name

flake.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
outputs = inputs@{ flake-parts, ... }:
5656
flake-parts.lib.mkFlake { inherit inputs; } ({ flake-parts-lib, withSystem, ... }: {
57-
systems = [ "x86_64-linux" "x86_64-darwin" ];
57+
systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
5858

5959
imports = [
6060
# Project configuration
@@ -73,6 +73,8 @@
7373
./examples/build.nix
7474
# Documentation
7575
./docs/build.nix
76+
# Templates
77+
./templates/build.nix
7678
];
7779
});
7880
}

templates/build.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
flake = {
3+
templates = {
4+
haskell = {
5+
path = ./haskell;
6+
description = "A simple GHC/Cabal project using flake-lang.nix";
7+
};
8+
rust = {
9+
path = ./rust;
10+
description = "A simple Rust/Cargo project using flake-lang.nix";
11+
};
12+
rust-monorepo = {
13+
path = ./rust-monorepo;
14+
description = "A project consists of multiple rust crates using flake-lang.nix";
15+
};
16+
typescript = {
17+
path = ./typescript;
18+
description = "A Typescript/NPM project using flake-lang.nix";
19+
};
20+
};
21+
};
22+
}

templates/haskell/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
dist
2+
dist-*
3+
cabal-dev
4+
*.o
5+
*.hi
6+
*.hie
7+
*.chi
8+
*.chs.h
9+
*.dyn_o
10+
*.dyn_hi
11+
.hpc
12+
.hsenv
13+
.cabal-sandbox/
14+
cabal.sandbox.config
15+
*.prof
16+
*.aux
17+
*.hp
18+
*.eventlog
19+
.stack-work/
20+
.HTF/
21+
.ghc.environment.*
22+
.direnv/
23+
dist-newstyle/
24+
25+
result
26+
result-*

templates/haskell/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for example
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.

templates/haskell/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2024 YOUR NAME
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included
12+
in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

templates/haskell/app/Main.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Main where
2+
3+
import qualified MyLib (someFunc)
4+
5+
main :: IO ()
6+
main = do
7+
putStrLn "Hello, Haskell!"
8+
MyLib.someFunc

templates/haskell/build.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{ inputs, ... }: {
2+
perSystem = { system, config, ... }:
3+
let
4+
hsFlake = inputs.flake-lang.lib.${system}.haskellFlake {
5+
src = ./.;
6+
name = "example";
7+
inherit (config.settings.haskell) index-state compiler-nix-name;
8+
};
9+
in
10+
{
11+
inherit (hsFlake) packages checks;
12+
13+
// TODO(chfanghr): Unify the names of dev shells of different lanuages
14+
devShells.dev-example-haskell = hsFlake.devShell;
15+
};
16+
}

templates/haskell/example.cabal

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
cabal-version: 3.0
2+
3+
-- The cabal-version field refers to the version of the .cabal specification,
4+
-- and can be different from the cabal-install (the tool) version and the
5+
-- Cabal (the library) version you are using. As such, the Cabal (the library)
6+
-- version used must be equal or greater than the version stated in this field.
7+
-- Starting from the specification version 2.2, the cabal-version field must be
8+
-- the first thing in the cabal file.
9+
10+
-- Initial package description 'example' generated by
11+
-- 'cabal init'. For further documentation, see:
12+
-- http://haskell.org/cabal/users-guide/
13+
--
14+
-- The name of the package.
15+
name: example
16+
17+
-- The package version.
18+
-- See the Haskell package versioning policy (PVP) for standards
19+
-- guiding when and how versions should be incremented.
20+
-- https://pvp.haskell.org
21+
-- PVP summary: +-+------- breaking API changes
22+
-- | | +----- non-breaking API additions
23+
-- | | | +--- code changes with no API change
24+
version: 0.1.0.0
25+
26+
-- A short (one-line) description of the package.
27+
-- synopsis:
28+
29+
-- A longer description of the package.
30+
-- description:
31+
32+
-- The license under which the package is released.
33+
license: MIT
34+
35+
-- The file containing the license text.
36+
license-file: LICENSE
37+
38+
-- The package author(s).
39+
author: YOUR NAME
40+
41+
-- An email address to which users can send suggestions, bug reports, and patches.
42+
maintainer: [email protected]
43+
44+
-- A copyright notice.
45+
-- copyright:
46+
build-type: Simple
47+
48+
-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README.
49+
extra-doc-files: CHANGELOG.md
50+
51+
-- Extra source files to be distributed with the package, such as examples, or a tutorial module.
52+
-- extra-source-files:
53+
54+
common warnings
55+
ghc-options: -Wall
56+
57+
library
58+
-- Import common warning flags.
59+
import: warnings
60+
61+
-- Modules exported by the library.
62+
exposed-modules: MyLib
63+
64+
-- Modules included in this library but not exported.
65+
-- other-modules:
66+
67+
-- LANGUAGE extensions used by modules in this package.
68+
-- other-extensions:
69+
70+
-- Other library packages from which modules are imported.
71+
build-depends: base ^>=4.18.2.1
72+
73+
-- Directories containing source files.
74+
hs-source-dirs: src
75+
76+
-- Base language which the package is written in.
77+
default-language: Haskell2010
78+
79+
executable example
80+
-- Import common warning flags.
81+
import: warnings
82+
83+
-- .hs or .lhs file containing the Main module.
84+
main-is: Main.hs
85+
86+
-- Modules included in this executable, other than Main.
87+
-- other-modules:
88+
89+
-- LANGUAGE extensions used by modules in this package.
90+
-- other-extensions:
91+
92+
-- Other library packages from which modules are imported.
93+
build-depends:
94+
, base ^>=4.18.2.1
95+
, example
96+
97+
-- Directories containing source files.
98+
hs-source-dirs: app
99+
100+
-- Base language which the package is written in.
101+
default-language: Haskell2010
102+
103+
test-suite example-test
104+
-- Import common warning flags.
105+
import: warnings
106+
107+
-- Base language which the package is written in.
108+
default-language: Haskell2010
109+
110+
-- Modules included in this executable, other than Main.
111+
-- other-modules:
112+
113+
-- LANGUAGE extensions used by modules in this package.
114+
-- other-extensions:
115+
116+
-- The interface type and version of the test suite.
117+
type: exitcode-stdio-1.0
118+
119+
-- Directories containing source files.
120+
hs-source-dirs: test
121+
122+
-- The entrypoint to the test suite.
123+
main-is: Main.hs
124+
125+
-- Test dependencies.
126+
build-depends:
127+
, base ^>=4.18.2.1
128+
, example

0 commit comments

Comments
 (0)