-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
183 lines (181 loc) · 5.79 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
nix-plop.url = "gitlab:cbleslie/nix-plop";
nix-testcafe.url = "gitlab:cbleslie/nix-testcafe";
ignoreBoy.url = "github:Ookiiboy/ignoreBoy";
# Non-flake
stylelint-config-recommended.url = "github:stylelint/stylelint-config-recommended";
stylelint-config-recommended.flake = false;
editorconfig.url = "github:Ookiiboy/editor-config/";
editorconfig.flake = false;
};
outputs = {
self,
systems,
nixpkgs,
pre-commit-hooks,
nix-plop,
nix-testcafe,
stylelint-config-recommended,
editorconfig,
ignoreBoy,
...
}: let
forAllSystems = nixpkgs.lib.genAttrs (import systems);
# This just holds metadata about the project to reuse across the file.
meta = rec {
version = "${self.shortRev or "dirty"}";
name = "hyoketsu";
pname = name;
tag = version;
};
in {
packages = forAllSystems (system: let
pkgs = import nixpkgs {inherit system;};
in rec {
default = docker;
hyoketsu = pkgs.stdenv.mkDerivation {
inherit (meta) version pname;
src = ./.;
# Don't build because dependencies are gathered on first run by Deno.
# Should still be reproduceable because of deno.lock.
dontBuild = true;
installPhase = ''
DEPS=(
"components"
"islands"
"lib"
"routes"
"static"
"deno.json"
"deno.lock"
"fresh.config.ts"
"fresh.gen.ts"
"Licence"
"main.ts"
)
mkdir -p $out/bin
cp -r "''${DEPS[@]}" $out/bin
'';
};
# This makes sure deno is in the path (with any other deps) and runs the
# server. This is here so we can run with the server with deps, the same
# way as the server itself.
hyoketsuRunScript = pkgs.writeShellApplication {
inherit (meta) name;
runtimeInputs = with pkgs; [deno hyoketsu];
# We should figure out exactly what runtime permissions we need. -A is
# less than ideal.
text = ''
deno run -A ${hyoketsu}/bin/main.ts
'';
};
docker = pkgs.dockerTools.buildImage {
inherit (meta) name tag;
config = {
ExposedPorts = {"8000" = {};};
Cmd = ["${hyoketsuRunScript}/bin/hyoketsu"];
};
};
});
formatter = forAllSystems (system: let
pkgs = import nixpkgs {inherit system;};
in
pkgs.alejandra);
# https://github.com/cachix/git-hooks.nix?tab=readme-ov-file
# https://devenv.sh/reference/options/?query=pre-commit.hooks
checks = forAllSystems (system: let
pkgs = import nixpkgs {inherit system;};
in {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
# Nix
alejandra.enable = true;
deadnix.enable = true;
statix.enable = true;
flake-checker.enable = true;
# Makefiles
checkmake.enable = true;
# Deno
denofmt.enable = true;
denolint.enable = true;
# Shell Scripts
shellcheck.enable = true;
beautysh.enable = true;
# JSON
check-json.enable = true;
# Github Actions
actionlint.enable = true;
# Markdown
typos.enable = true;
# Generic - .editorconfig
editorconfig-checker.enable = true;
check-toml.enable = true;
# CSS - .stylelint.json
stylelint = {
enable = true;
name = "Stylelint";
entry = "${pkgs.stylelint}/bin/stylelint --fix";
files = "\\.(css)$";
types = ["text" "css"];
language = "system";
pass_filenames = true;
};
};
};
});
devShells = forAllSystems (system: let
pkgs = import nixpkgs {inherit system;};
ignoreSettings = {
ignores = ["Node" "community/JavaScript/Vue"];
# Anything custom you might want in your .gitignore you can place in extraConfig.
extraConfig = ''
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# Fresh build directory
_fresh/
# npm dependencies
node_modules/
.pre-commit-config.yaml
# Symlinked Flake Inputs
stylelint.config.mjs
.editorconfig
'';
};
in {
default = pkgs.mkShell {
name = "Local Development Shell";
# We're going to make a symlink and create a direct reference to the
# stylelint config, rather than have a copy. No, npm or yarn
# package.json to install this file, so we fetch it directly from the
# github repo itself. This keeps the install and deps clean.
shellHook = ''
ln -sf ${stylelint-config-recommended}/index.js ./stylelint.config.mjs
ln -sf ${editorconfig}/.editorconfig ./.editorconfig
${self.checks.${system}.pre-commit-check.shellHook}
${ignoreBoy.lib.${system}.gitignore ignoreSettings}
'';
ENV = "dev"; # Used in the event we need a development environment hook.
PORT = 6969; # Sets the development server's port
buildInputs = with pkgs;
[
nix-plop.packages.${system}.default
nix-testcafe.packages.${system}.default
gnumake
deno
nix-tree
# Typescript LSP for SublimeText runs on node
nodejs_20
]
++ self.checks.${system}.pre-commit-check.enabledPackages;
};
});
};
}