-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
146 lines (141 loc) · 4.13 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
description = "Today I Log";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
nix-filter.url = "github:numtide/nix-filter";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
weeder-nix.url = "github:NorfairKing/weeder-nix";
weeder-nix.inputs = {
nixpkgs.follows = "nixpkgs";
pre-commit-hooks.follows = "pre-commit-hooks";
};
feedback.url = "github:NorfairKing/feedback";
};
outputs = inputs @ {
self,
nixpkgs,
flake-utils,
nix-filter,
pre-commit-hooks,
...
}: let
pkgsFor = system:
import nixpkgs {
inherit system;
overlays = [self.overlays.default];
};
filteredSrc = nix-filter.lib {
root = ./.;
include = [
"src/"
"test/"
"package.yaml"
"LICENSE"
];
};
in
{
overlays.default = final: prev: rec {
til = final.haskell.lib.justStaticExecutables (
haskellPackages.til.overrideAttrs (oldAttrs: {
configureFlags = oldAttrs.configureFlags ++ ["--ghc-option=-O2"];
})
);
haskellPackages = prev.haskellPackages.override (old: {
overrides =
final.lib.composeExtensions
(old.overrides or (_: _: {}))
(self: super: {
til =
self.generateOptparseApplicativeCompletions
["til"]
(self.callCabal2nix "til" filteredSrc {});
});
});
};
homeManagerModules.default = {
config,
pkgs,
lib,
...
}:
with lib; let
cfg = config.programs.til;
in {
options.programs.til = {
enable = mkEnableOption "til";
editor = mkOption {
type = types.str;
description = "The text editor to open markdown files.";
default = "$EDITOR";
};
directory = mkOption {
type = types.str;
description = "The directory containing the log markdown files";
default = "$HOME/til";
};
};
config = let
til-app = self.apps.${pkgs.system}.til.program;
til = pkgs.writeShellScriptBin "til" ''
${til-app} --editor ${cfg.editor} --directory ${cfg.directory} $@
'';
in
mkIf cfg.enable {home.packages = [til];};
};
}
// flake-utils.lib.eachDefaultSystem (
system: let
pkgs = pkgsFor system;
precommitCheck = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
actionlint.enable = true;
hlint.enable = true;
hpack.enable = true;
markdownlint.enable = true;
nil.enable = true;
alejandra.enable = true;
ormolu.enable = true;
};
};
in rec {
packages.til = pkgs.haskellPackages.til;
packages.default = packages.til;
apps.til = flake-utils.lib.mkApp {drv = pkgs.til;};
apps.default = apps.til;
devShells.default = pkgs.haskellPackages.shellFor {
packages = p: [p.til];
buildInputs = with pkgs; [
actionlint
cabal-install
ghcid
haskell-language-server
haskellPackages.implicit-hie
hlint
mdr
nil
alejandra
ormolu
statix
inputs.feedback.packages.${system}.default
];
inherit (precommitCheck) shellHook;
};
checks = {
pre-commit-check = precommitCheck;
weeder-check = inputs.weeder-nix.lib.${system}.makeWeederCheck {
haskellPackages = pkgs.haskellPackages;
packages = ["til"];
reportOnly = true;
};
};
}
);
nixConfig = {
extra-substituters = "https://opensource.cachix.org";
extra-trusted-public-keys = "opensource.cachix.org-1:6t9YnrHI+t4lUilDKP2sNvmFA9LCKdShfrtwPqj2vKc=";
};
}