Skip to content

Commit 2eb44bd

Browse files
committed
Add support for writing the build revision in built environment
1 parent d46f8b4 commit 2eb44bd

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

modules/build.nix

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,20 @@ in {
112112
113113
mkdir -p "\$dest"
114114
115-
echo "switching manifests"
116-
117-
${pkgs.rsync}/bin/rsync --recursive --delete -L "${config.build.environmentPackage}/" "\$dest"
118-
119-
echo "done!"
115+
# We need to check if there is a difference between
116+
# the newly built environment and the destination
117+
# excluding `.revision` because that will most likely
118+
# always change when going through CI, avoiding infinite
119+
# loop.
120+
if ! ${pkgs.diffutils}/bin/diff -q -r --exclude .revision "${config.build.environmentPackage}" "\$dest" &>/dev/null; then
121+
echo "switching manifests"
122+
123+
${pkgs.rsync}/bin/rsync --recursive --delete -L "${config.build.environmentPackage}/" "\$dest"
124+
125+
echo "done!"
126+
else
127+
echo "no changes!"
128+
fi
120129
EOF
121130
122131
chmod +x $out/activate

modules/nixidy.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ in {
6262
};
6363
};
6464

65+
build = {
66+
revision = mkOption {
67+
type = types.nullOr types.str;
68+
default = null;
69+
example = literalExpression ''
70+
if (self ? rev) then self.rev else self.dirtyRev
71+
'';
72+
description = "The revision being built. Will be written to `.revision` in the environment destination directory.";
73+
};
74+
};
75+
6576
extraFiles = mkOption {
6677
type = types.attrsOf (types.submodule extraFilesOpts);
6778
default = {};
@@ -181,5 +192,9 @@ in {
181192

182193
_module.args.charts = config.nixidy.charts;
183194
nixidy.charts = lib.optionalAttrs (cfg.chartsDir != null) (mkChartAttrs cfg.chartsDir);
195+
196+
nixidy.extraFiles = lib.optionalAttrs (cfg.build.revision != null) {
197+
".revision".text = cfg.build.revision;
198+
};
184199
};
185200
}

0 commit comments

Comments
 (0)