This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
190 lines (174 loc) · 6.24 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
184
185
186
187
188
189
190
{
description = "Description for the project";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# nixpkgs with autmatically migrated nixdoc comments
nixpkgs-migrated.url = "github:hsjobeki/nixpkgs/migrated";
# a POC in nix for docstrings
nix.url = "github:hsjobeki/nix/?ref=feat/doc-comments";
# A nice unit testing framework
nix-unit.url = "github:nix-community/nix-unit";
nix-unit.inputs.nixpkgs.follows = "nixpkgs";
nix-unit.inputs.flake-parts.follows = "flake-parts";
dream2nix.url = "github:nix-community/dream2nix";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs @ {
flake-parts,
nixpkgs,
crane,
dream2nix,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
}: let
##### SITE / URL Settings ################
# e.g. https://nix-community.github.io
# Used to generate a 'Sitemap'.
# This is an XML file that outlines all of the pages, videos, and files on the site.
# Search engines like Google read this file to crawl the site more efficiently.
# See Google’s own advice on sitemaps to learn more.
siteUrl = "https://nix-community.github.io";
prefix = "docnix";
# -> Static assets are served via: https://nix-community.github.io/docnix
##########################
craneLib = crane.lib.${system};
codemodSrc = craneLib.cleanCargoSource (craneLib.path ./codemod);
commonArgs = {
src = codemodSrc;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, reusing the dependency
# artifacts from above.
codemod = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
});
in {
packages =
{
default = self'.packages.static-docs;
codemod = codemod;
nixpkgs-migrated = pkgs.stdenv.mkDerivation {
name = "nixpkgs-migrated";
src = nixpkgs;
buildPhase = ''
${self'.packages.codemod}/bin/codemod .
cp -r . $out
'';
};
code-docs = let
nix = inputs'.nix.packages.nix-clangStdenv;
nixpkgs = self'.packages.nixpkgs-migrated;
in
pkgs.stdenv.mkDerivation {
name = "code-docs";
src = ./code-docs;
nativeBuildInputs = [nix];
buildPhase = ''
nix-instantiate --eval --strict --json --store $PWD \
mkDocs.nix --arg 'pkgs' 'import ${nixpkgs} {}' -A docs \
> $out
'';
};
markdown = pkgs.stdenv.mkDerivation {
name = "markdown-docs";
src = ./json-to-md;
nativeBuildInputs = [pkgs.nodejs_20];
env.PREFIX = prefix;
buildPhase = ''
cp ${self'.packages.code-docs} data.json
node convert.mjs
mkdir -p $out
cp -r ./dist/* $out
'';
};
}
// (dream2nix.lib.importPackages {
projectRoot = ./.;
# can be changed to ".git" or "flake.nix" to get rid of .project-root
projectRootFile = "flake.nix";
packagesDir = ./packages;
packageSets.nixpkgs = pkgs;
specialArgs = {
md-docs = self'.packages.markdown;
PREFIX = prefix;
SITE = siteUrl;
};
});
devShells = {
default = pkgs.mkShell {
name = "doc-comment-devshell";
packages = [
inputs'.nixpkgs.legacyPackages.nodejs_20
inputs'.nix.packages.nix-clangStdenv
(inputs'.nix-unit.packages.nix-unit.override {
nix = inputs'.nix.packages.nix-clangStdenv;
})
];
shellHook = ''
rm -rf ./json-to-md/data.json
cp -rf ${self'.packages.code-docs} ./json-to-md/data.json
chmod +w ./json-to-md/data.json
rm -rf ./packages/static-docs/src/content/docs/reference/pkgs
rm -rf ./packages/static-docs/src/content/docs/reference/builtins
rm -rf ./packages/static-docs/src/content/docs/reference/lib
cp -rf ${self'.packages.markdown}/* ./packages/static-docs/src/content/docs/reference
chmod -R +w ./packages/static-docs/src/content/docs/reference
'';
};
codemod = craneLib.devShell {
# Inherit inputs from checks.
checks = self'.checks;
};
};
checks = {
inherit codemod;
codemod-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
codemod-doc = craneLib.cargoDoc (commonArgs
// {
inherit cargoArtifacts;
});
# Check formatting
codemod-fmt = craneLib.cargoFmt {
src = codemodSrc;
};
# Run tests with cargo-nextest
# Consider setting `doCheck = false` on `my-crate` if you do not want
# the tests to run twice
codemod-nextest = craneLib.cargoNextest (commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
});
};
};
flake = {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.
};
};
}