Skip to content

Commit 60fe9c6

Browse files
committed
feat: Persist the header data
1 parent f75e9ad commit 60fe9c6

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

pkgs/emacs/data/default.nix

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ in
2525
inventories,
2626
flakeLockFile,
2727
archiveLockFile,
28+
headersJsonFile,
2829
inputOverrides,
2930
elispPackagePins,
3031
defaultMainIsAscii,
@@ -48,6 +49,11 @@ in
4849
then lib.importJSON archiveLockFile
4950
else {};
5051

52+
headerData =
53+
if mode == "build" && pathExists headersJsonFile
54+
then toLockData (lib.importJSON headersJsonFile)
55+
else {};
56+
5157
makeInventory = import ./inventory {
5258
inherit lib flakeLockData archiveLockData;
5359
};
@@ -92,8 +98,11 @@ in
9298
or (throw "Inventory named ${pin} does not exist")
9399
);
94100

101+
getPackageData0 =
102+
import ./package.nix {inherit lib linkFarm defaultMainIsAscii headerData;};
103+
95104
getPackageData = revDep: ename:
96-
lib.makeExtensible (import ./package.nix {inherit lib linkFarm defaultMainIsAscii;}
105+
lib.makeExtensible (getPackageData0
97106
ename
98107
# It would be nice if it were possible to set the pin from inside
99108
# overrideInputs, but it causes infinite recursion unfortunately :(

pkgs/emacs/data/package.nix

+13-11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ in
2626
lib,
2727
linkFarm,
2828
defaultMainIsAscii,
29+
headerData,
2930
}: ename: mkAttrs: self: let
3031
attrs =
3132
if isAttrs mkAttrs
@@ -64,17 +65,18 @@ in
6465
# effectively prevents you from adding elisp packages directly to the flake
6566
# outputs.
6667
headers =
67-
lib.parseElispHeaders
68-
(
69-
# Add support for an option to remove IFD.
70-
if self.mainIsAscii or defaultMainIsAscii
71-
then builtins.readFile (self.src + "/${self.mainFile}")
72-
else
73-
(lib.readFirstBytes
74-
# magit.el has a relatively long header, so other libraries would be shorter.
75-
1500
76-
(self.src + "/${self.mainFile}"))
77-
);
68+
headerData.${ename}
69+
or (lib.parseElispHeaders
70+
(
71+
# Add support for an option to remove IFD.
72+
if self.mainIsAscii or defaultMainIsAscii
73+
then builtins.readFile (self.src + "/${self.mainFile}")
74+
else
75+
(lib.readFirstBytes
76+
# magit.el has a relatively long header, so other libraries would be shorter.
77+
1500
78+
(self.src + "/${self.mainFile}"))
79+
));
7880
in
7981
lib.getAttrs
8082
(filter (name: hasAttr name attrs) [

pkgs/emacs/default.nix

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ in
7070

7171
archiveLockFile = lockDir + "/archive.lock";
7272

73+
headersJsonFile = lockDir + "/headers.json";
74+
7375
userConfig = lib.pipe self.initFiles [
7476
(map initReader)
7577
lib.zipAttrs
@@ -104,6 +106,7 @@ in
104106
lib
105107
flakeLockFile
106108
archiveLockFile
109+
headersJsonFile
107110
builtinLibraries
108111
inputOverrides
109112
defaultMainIsAscii
@@ -234,6 +237,7 @@ in
234237
excludeLocalPackages (enumerateConcretePackageSet "update" explicitPackages);
235238
flakeNix = true;
236239
archiveLock = true;
240+
headersJson = true;
237241
})
238242
.writerScript {inherit postCommandOnGeneratingLockDir;};
239243

@@ -248,6 +252,7 @@ in
248252
excludeLocalPackages (enumerateConcretePackageSet "lock" explicitPackages);
249253
flakeNix = true;
250254
archiveLock = true;
255+
headersJson = true;
251256
postCommand = "nix flake lock";
252257
})
253258
.asAppWritingToRelativeDir
@@ -260,6 +265,7 @@ in
260265
packageInputs =
261266
excludeLocalPackages (enumerateConcretePackageSet "update" explicitPackages);
262267
archiveLock = true;
268+
headersJson = true;
263269
})
264270
.asAppWritingToRelativeDir
265271
lockDirName;

pkgs/emacs/lock/default.nix

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
packageInputs,
1414
flakeNix ? false,
1515
archiveLock ? false,
16+
headersJson ? false,
1617
# Command run after writing the directory in asAppWritingToRelativeDir
1718
postCommand ? null,
1819
}:
@@ -30,6 +31,8 @@ assert (flakeNix || archiveLock); let
3031
]))
3132
];
3233

34+
headerData = mapAttrs (_: {headers, ...}: headers) packageInputs;
35+
3336
data = {
3437
flakeNix = lib.toNix {
3538
description = "THIS IS AN AUTO-GENERATED FILE. PLEASE DON'T EDIT IT MANUALLY.";
@@ -40,11 +43,13 @@ assert (flakeNix || archiveLock); let
4043
outputs = {...}: {};
4144
};
4245
archiveLock = toJSON archiveLockData;
46+
headersJson = toJSON headerData;
4347
};
4448

4549
passAsFile =
4650
lib.optional flakeNix "flakeNix"
47-
++ lib.optional archiveLock "archiveLock";
51+
++ lib.optional archiveLock "archiveLock"
52+
++ lib.optional headersJson "headersJson";
4853

4954
# HACK: Use sed to convert JSON to Nix
5055
#
@@ -60,6 +65,10 @@ assert (flakeNix || archiveLock); let
6065
${jq}/bin/jq . "$archiveLockPath" > "$out/archive.lock"
6166
'';
6267

68+
generateHeadersJson = ''
69+
${jq}/bin/jq . "$headersJsonPath" > "$out/headers.json"
70+
'';
71+
6372
src =
6473
runCommandLocal "emacs-twist-lock" ({
6574
inherit passAsFile;
@@ -70,6 +79,7 @@ assert (flakeNix || archiveLock); let
7079
7180
${lib.optionalString flakeNix generateFlakeNix}
7281
${lib.optionalString archiveLock generateArchiveLock}
82+
${lib.optionalString headersJson generateHeadersJson}
7383
'';
7484
in {
7585
asAppWritingToRelativeDir = outDir: {

0 commit comments

Comments
 (0)