-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
147 lines (140 loc) · 4.4 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
147
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
gitignore-repo.url = "github:github/gitignore";
gitignore-repo.flake = false;
editorconfig.url = "github:Ookiiboy/editor-config/";
editorconfig.flake = false;
};
outputs = {
self,
systems,
nixpkgs,
pre-commit-hooks,
editorconfig,
gitignore-repo,
...
}: let
forAllSystems = function: nixpkgs.lib.genAttrs (import systems) (system: function nixpkgs.legacyPackages.${system});
in {
formatter = forAllSystems (pkgs: pkgs.alejandra);
checks = forAllSystems (pkgs: {
pre-commit-check = pre-commit-hooks.lib.${pkgs.system}.run {
src = ./.;
hooks = {
# Nix
alejandra.enable = true;
deadnix.enable = true;
statix.enable = true;
flake-checker.enable = true;
# Generic - .editorconfig
editorconfig-checker.enable = true;
};
};
});
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
name = "development";
shellHook = ''
ln -sf ${editorconfig}/.editorconfig ./.editorconfig
${self.checks.${pkgs.system}.pre-commit-check.shellHook}
${self.lib.${pkgs.system}.gitignore {
github.languages = [];
gitignoreio.languages = [];
hash = "";
extraConfig = ''
.editorconfig
.pre-commit-config.yaml
'';
}}
'';
buildInputs = self.checks.${pkgs.system}.pre-commit-check.enabledPackages;
};
});
lib = forAllSystems (pkgs: rec {
toptalGitignoreIo = arguments @ {
languages ? [],
hash ? "",
# Allow variadic arguments so we have one API
...
}:
builtins.fetchurl {
url = "https://www.toptal.com/developers/gitignore/api/${pkgs.lib.concatStringsSep "," arguments.languages}";
name = "toptalGitignoreIo"; # Required as both "," and "%2C" are invalid store paths
# For some godforsaken reason arguments.hash bombs on missing property
sha256 = hash;
};
ignoreRepoFile = file:
# ↓ By the way, how fucking cool is this?! ↓
gitignore-repo + "/${file}.gitignore";
ignoreDirenv = pkgs.writeText "ignoreDirenv" ''
.direnv/
'';
saneDefaults = [
"Global/macOS"
"Global/Windows"
"Global/Linux"
"Global/Patch"
"community/Nix"
];
writeExtraConfig = extra: [
(pkgs.writeText "extraConfig" ''
# User Provided
${extra}
'')
];
generateGitIgnore = settings:
pkgs.concatText ".gitignore" (
[
ignoreDirenv
]
# Sane Defaults - Ingested
++ (
if (!settings ? useSaneDefaults || settings.useSaneDefaults)
then map ignoreRepoFile saneDefaults
else []
)
# API Derrived Ignores
++ (
if
(
builtins.hasAttr "gitignoreio" settings
&& builtins.hasAttr "languages" settings.gitignoreio
# Since this is an API hit, it will return something on an empty
# array
&& settings.gitignoreio.languages != []
)
then [
(toptalGitignoreIo {
inherit (settings.gitignoreio) languages;
hash =
if (builtins.hasAttr "hash" settings.gitignoreio)
then settings.gitignoreio.hash
else "";
})
]
else []
)
++ (
if (builtins.hasAttr "github" settings && builtins.hasAttr "languages" settings.github)
then map ignoreRepoFile settings.github.languages
else []
)
++
# User Defined - These come last in the event that anything should be
# overridden.
(
if builtins.hasAttr "extraConfig" settings
then writeExtraConfig settings.extraConfig
else []
)
);
# We can't link the file in the store. What a crime. Gotta copy.
gitignore = settings: ''
cp -f ${generateGitIgnore settings} ./.gitignore
'';
});
};
}