Skip to content

Commit d094c67

Browse files
authored
news: create an individual file for each news entry (#6747)
The current way to define a news entry in Home-Manager is error prone (since you need to type the date manually) and also it is common cause of conflicts after merges because all entries are defined in the same file. This commit fixes this: we can now create individual news entries for each new entry. A script `create-news-entry.sh` also helps to create it in the correct format (with the correct filenames and structure).
1 parent b5e2956 commit d094c67

File tree

5 files changed

+53
-16
lines changed

5 files changed

+53
-16
lines changed

docs/manual/contributing/news.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ If you do have a change worthy of a news entry then please add one in
1010
[`news.nix`](https://github.com/nix-community/home-manager/blob/master/modules/misc/news.nix)
1111
but you should follow some basic guidelines:
1212

13-
- The entry timestamp should be in ISO-8601 format having \"+00:00\"
14-
as time zone. For example, \"2017-09-13T17:10:14+00:00\". A suitable
15-
timestamp can be produced by the command
13+
- Use the included
14+
[`create-news-entry.sh`](https://github.com/nix-community/home-manager/blob/master/modules/misc/news/create-news-entry.sh)
15+
script to generate a news entry file:
1616

1717
``` shell
18-
$ date --iso-8601=second --universal
18+
$ modules/misc/news/create-news-entry.sh
1919
```
2020

21+
this will create a new file inside `modules/misc/news` directory
22+
with some placeholder information that you can edit.
23+
2124
- The entry condition should be as specific as possible. For example,
2225
if you are changing or deprecating a specific option then you could
2326
restrict the news to those users who actually use this option.

home-manager/build-news.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
let
88
inherit (builtins)
9-
concatStringsSep filter hasAttr isString length optionalString readFile
10-
replaceStrings sort split;
9+
concatStringsSep filter hasAttr isString length readFile replaceStrings sort
10+
split;
1111

1212
newsJson = builtins.fromJSON (builtins.readFile newsJsonFile);
1313

modules/misc/news.nix

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ let
4545
id = lib.mkDefault (builtins.hashString "sha256" config.message);
4646
};
4747
});
48+
49+
isNixFile = n: v: v == "regular" && lib.hasSuffix ".nix" n;
50+
# builtins.attrNames return the values in alphabetical order
51+
newsFiles =
52+
builtins.attrNames (lib.filterAttrs isNixFile (builtins.readDir ./news));
53+
newsEntries =
54+
builtins.map (newsFile: import (./news + "/${newsFile}")) newsFiles;
4855
in {
4956
meta.maintainers = [ lib.maintainers.rycee ];
5057

@@ -96,15 +103,8 @@ in {
96103
news.json.output = pkgs.writeText "hm-news.json"
97104
(builtins.toJSON { inherit (cfg) display entries; });
98105

99-
# Add news entries in chronological order (i.e., latest time
100-
# should be at the bottom of the list). The time should be
101-
# formatted as given in the output of
102-
#
103-
# date --iso-8601=second --universal
104-
#
105-
# On darwin (or BSD like systems) use
106-
#
107-
# date -u +'%Y-%m-%dT%H:%M:%S+00:00'
106+
# DO NOT define new entries here, instead use the `./create-news-entry.sh`
107+
# script and create an individual news file inside `news` sub-directory.
108108
news.entries = [
109109
{
110110
time = "2021-06-02T04:24:10+00:00";
@@ -2231,6 +2231,6 @@ in {
22312231
See https://github.com/ivaaaan/smug for more information.
22322232
'';
22332233
}
2234-
];
2234+
] ++ newsEntries;
22352235
};
22362236
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
time = "2025-04-02T13:01:34+00:00";
3+
condition = true;
4+
message = ''
5+
A new way to define news is available.
6+
7+
Instead of editing the previous news.nix file, you can now define entries
8+
using individual files. This should reduce the number of merge conflicts.
9+
'';
10+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env nix-shell
2+
#! nix-shell -I https://github.com/NixOS/nixpkgs/archive/05f0934825c2a0750d4888c4735f9420c906b388.tar.gz -i bash -p coreutils
3+
4+
DATE="$(date --iso-8601=second --universal)"
5+
FILENAME="$(date --date="$DATE" +"%Y-%m-%d_%H-%M-%S").nix"
6+
DIRNAME="$(dirname -- "${BASH_SOURCE[0]}")"
7+
8+
cd "$DIRNAME" || {
9+
>&2 echo "Failed to change to the script directory: $DIRNAME"
10+
exit 1
11+
}
12+
13+
cat - << EOF > "$FILENAME"
14+
{
15+
time = "$DATE";
16+
condition = true;
17+
message = ''
18+
PLACEHOLDER
19+
'';
20+
}
21+
EOF
22+
23+
echo "Successfully created a news file: $DIRNAME/$FILENAME"
24+
echo "You can open the file above in your text editor and edit now."

0 commit comments

Comments
 (0)