Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
watch_file \
*.cabal \
nix/modules/flake/*.nix
haskell.nix \
dev/*

use flake
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,11 @@ If you have an *existing* Haskell project, you should probably use https://githu

## Getting Started

Initialize this template using:

```sh
nix run nixpkgs#omnix -- \
init github:srid/haskell-template -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`.*
Initialize this template using the green "Use this template" button above or just clone it, and then [rename it](https://srid.ca/haskell-template/start#rename-the-project).

Full instructions: https://srid.ca/haskell-template/start

Recommended dev environment setup: https://nixos.asia/en/direnv
*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`.*

## Tips

Expand All @@ -39,6 +32,6 @@ Recommended dev environment setup: https://nixos.asia/en/direnv

## Discussions

Questions? Ideas? Suggestions? Join our [NixOS Asia community](https://nixos.asia/en/#community) or post in [Github Discussions](https://github.com/srid/haskell-template/discussions).
Questions? Ideas? Suggestions? Post in [Github Discussions](https://github.com/srid/haskell-template/discussions).

[pre-commit]: https://github.com/cachix/git-hooks.nix
27 changes: 25 additions & 2 deletions nix/modules/flake/pre-commit.nix → dev/flake-module.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
# Git pre-commit hooks are defined here.
# Development-only flake-parts module
# This module is loaded in the "dev" partition and includes devShell, pre-commit hooks, etc.

{ inputs, ... }:
{
imports = [
(inputs.git-hooks + /flake-module.nix)
inputs.fourmolu-nix.flakeModule
../haskell.nix
];
perSystem = { config, ... }: {

perSystem = { config, pkgs, ... }: {
# Development shell
devShells.default = pkgs.mkShell {
name = "haskell-template";
meta.description = "Haskell development environment";

# See https://community.flake.parts/haskell-flake/devshell#composing-devshells
inputsFrom = [
config.haskellProjects.default.outputs.devShell
config.pre-commit.devShell
];

# Development packages
packages = with pkgs; [
just
nixd
ghciwatch
];
};

# Git pre-commit hooks
pre-commit.settings = {
hooks = {
nixpkgs-fmt.enable = true;
Expand Down
76 changes: 76 additions & 0 deletions dev/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions dev/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
description = "Development inputs for haskell-template";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.flake = false;
fourmolu-nix.url = "github:jedimahdi/fourmolu-nix";
haskell-flake.url = "github:srid/haskell-flake";
};

# This flake exists only for its inputs; see ./flake-module.nix for outputs.
outputs = { ... }: { };
}
24 changes: 24 additions & 0 deletions dev/partition.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Partition configuration for development outputs
# This routes devShells and checks to the dev partition
{ inputs, ... }:

{
imports = [
inputs.flake-parts.flakeModules.partitions
];
# Partition development outputs to avoid fetching dev-only inputs
# when users only need packages/apps
partitionedAttrs = {
devShells = "dev";
checks = "dev";
};

partitions.dev = {
extraInputsFlake = ./.;
module = {
imports = [
./flake-module.nix
];
};
};
}
68 changes: 16 additions & 52 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 8 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
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 = ./.; };
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
imports = [
./haskell.nix
./dev/partition.nix # Development stuff decoupled; https://flake.parts/options/flake-parts-partitions.html
];
};
}
25 changes: 14 additions & 11 deletions nix/modules/flake/haskell.nix → haskell.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
# haskell-flake configuration goes in this module.

{ root, inputs, ... }:
{ inputs, ... }:
{
imports = [
inputs.haskell-flake.flakeModule
];
perSystem = { self', lib, config, pkgs, ... }: {
perSystem = { self', lib, ... }: {
# 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 = {
# The base project is at the flake root
# 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 + /haskell-template.cabal)
(root + /LICENSE)
(root + /README.md)
];
});
projectRoot =
let root = ./.;
in builtins.toString (lib.fileset.toSource {
inherit root;
fileset = lib.fileset.unions [
(root + /src)
(root + /haskell-template.cabal)
(root + /LICENSE)
(root + /README.md)
];
});

# The base package set (this value is the default)
# basePackages = pkgs.haskellPackages;
Expand Down
25 changes: 0 additions & 25 deletions nix/modules/flake/devshell.nix

This file was deleted.

Loading