-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.nix
More file actions
155 lines (150 loc) · 3.89 KB
/
shell.nix
File metadata and controls
155 lines (150 loc) · 3.89 KB
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
{
pkgs ? import <nixpkgs> { },
}:
let
# A dummy derivation to help nix-update. Run
#
# nix-update -f shell.nix hugo-papermod --version branch
#
# to update the version.
inherit (pkgs) lib;
hugo-papermod = pkgs.stdenv.mkDerivation (finalAttrs: {
pname = "hugo-papermod";
version = "8.0-unstable-2026-05-10";
src = pkgs.fetchFromGitHub {
owner = "adityatelange";
repo = "hugo-PaperMod";
rev = "154d006e0182dfc7da38008323976b02e6bfab4a";
hash = "sha256-5g6qI2OxDd//bxIy9nQi9XSDMSgNGk+OLgT2EqIjGRY=";
};
patches = [
# make code copy button respect user-select CSS
./patches/papermod-code-copy-button.patch
# enhance search to contain summary
./patches/papermod-search.patch
];
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r . $out/
runHook postInstall
'';
});
chroma-css =
theme:
pkgs.runCommand "chroma-${theme}.css" { } ''
${lib.getExe pkgs.hugo} gen chromastyles --style ${lib.escapeShellArg theme} > $out
'';
tomlFormat = pkgs.formats.toml { };
yamlFormat = pkgs.formats.yaml { };
treefmt-toml = tomlFormat.generate "treefmt.toml" {
on-unmatched = "fatal";
excludes = [
".gitignore"
"*.patch"
];
formatter.prettier = {
command = lib.getExe pkgs.prettier;
options = [
"--write"
"--config"
prettier-config-yaml
];
includes = [
"*.md"
"*.yaml"
"*.html"
"*.css"
];
};
formatter.nixfmt = {
command = lib.getExe pkgs.nixfmt;
includes = [ "*.nix" ];
};
formatter.shfmt = {
command = lib.getExe pkgs.shfmt;
includes = [ ".envrc" ];
options = [
"-w"
"-i"
"2"
"-s"
];
};
};
pre-commit-config-yaml = yamlFormat.generate "pre-commit-config.yaml" {
repos = [
{
repo = "local";
hooks = [
{
id = "treefmt";
name = "treefmt";
entry = "${lib.getExe pkgs.treefmt} --fail-on-change --no-cache";
language = "system";
types = [ "file" ];
pass_filenames = true;
}
];
}
];
};
# based on https://github.com/hugomods/prettier-config/blob/154d006e0182dfc7da38008323976b02e6bfab4a/index.json
prettier-config-yaml = yamlFormat.generate "prettierrc.yaml" {
bracketSameLine = true;
bracketSpacing = true;
endOfLine = "lf";
goTemplateBracketSpacing = true;
singleQuote = true;
tabWidth = 2;
useTabs = false;
overrides = [
{
files = [
"*.html"
"*.gotmpl"
"*.tmpl.*"
];
options = {
parser = "go-template";
bracketSameLine = true;
};
}
];
plugins = [
"${pkgs.prettier-plugin-go-template}/lib/node_modules/prettier-plugin-go-template/lib/index.js"
];
};
in
pkgs.mkShellNoCC {
packages = with pkgs; [
(hugo.overrideAttrs (oldAttrs: {
postPatch = (oldAttrs.postPatch or "") + ''
go mod edit -replace github.com/alecthomas/chroma/v2=${
# we assume the version of hugo and chroma in nixpkgs matches
runCommand "chroma-source" { inherit (chroma) src; } ''
mkdir -p "$out"
cp -r --no-preserve=mode "$src/." "$out/"
cd "$out"
patch -p1 < ${./patches/chroma-bash-session-lexer.patch}
''
}
'';
}))
nix-update
treefmt
pre-commit
rsync
];
shellHook = ''
ln -sfn ${hugo-papermod} themes/PaperMod
ln -sfn ${treefmt-toml} .treefmt.toml
ln -sfn ${pre-commit-config-yaml} .pre-commit-config.yaml
ln -sfn ${prettier-config-yaml} .prettierrc.yaml
ln -sfn ${chroma-css "github-dark"} assets/css/includes/chroma-styles.css
${lib.getExe pkgs.pre-commit} install
'';
passthru = {
inherit hugo-papermod;
};
}