feat(nix-reuse): Add installPath option

This allows installing the REUSE.toml file in a distinct directory from
the git toplevel
This commit is contained in:
Tom Hubrecht 2025-01-22 13:09:37 +01:00
parent 2f45f2e7e6
commit 45633dc6a0
Signed by: thubrecht
SSH key fingerprint: SHA256:CYNvFo44Ar9qCNnWNnvJVhs0QXO9AZjOLlPeWcSij3Q

View file

@ -64,6 +64,14 @@ in
readOnly = true;
};
installPath = mkOption {
type = nullOr str;
default = null;
description = ''
Where to place the REUSE.toml generated file, if `null`, the file will be placed in the git toplevel directory.
'';
};
defaultLicense = mkOption {
type = nullOr str;
default = null;
@ -188,25 +196,33 @@ in
}
];
installationScript =
# bash
''
if ! type -t git >/dev/null; then
# This happens in pure shells, including lorri
echo 1>&2 "WARNING: nix-reuse: git command not found; skipping installation."
elif ! git rev-parse --git-dir &> /dev/null; then
echo 1>&2 "WARNING: nix-reuse: .git not found; skipping installation."
installationScript = builtins.concatStringsSep "\n" [
(
if cfg.installPath == null then
''
if ! type -t git >/dev/null; then
# This happens in pure shells, including lorri
echo 1>&2 "WARNING: nix-reuse: git command not found; skipping installation."
elif ! git rev-parse --git-dir &> /dev/null; then
echo 1>&2 "WARNING: nix-reuse: .git not found; skipping installation."
else
GIT_WC=`git rev-parse --show-toplevel`
# Install REUSE.toml
if [ ! -f "$GIT_WC/REUSE.toml" ] || ! ${getExe' pkgs.diffutils "cmp"} -s "$GIT_WC/REUSE.toml" ${result} ; then
# Copy the updated workflow definition
cp --no-preserve=mode,ownership ${result} "$GIT_WC/REUSE.toml" && echo "nix-reuse: Updated REUSE.toml"
fi
fi
''
else
GIT_WC=`git rev-parse --show-toplevel`
# Install REUSE.toml
if [ ! -f "$GIT_WC/REUSE.toml" ] || ! ${getExe' pkgs.diffutils "cmp"} -s "$GIT_WC/REUSE.toml" ${result} ; then
# Copy the updated workflow definition
cp --no-preserve=mode,ownership ${result} "$GIT_WC/REUSE.toml" && echo "nix-reuse: Updated REUSE.toml"
fi
fi
${optionalString config.downloadLicenses "${getExe pkgs.reuse} download --all"}
'';
''
if [ ! -f "${cfg.installPath}/REUSE.toml" ] || ! ${getExe' pkgs.diffutils "cmp"} -s "${cfg.installPath}/REUSE.toml" ${result} ; then
cp --no-preserve=mode,ownership ${result} "${cfg.installPath}/REUSE.toml" && echo "nix-reuse: Updated REUSE.toml"
fi
''
)
(optionalString config.downloadLicenses "${getExe pkgs.reuse} download --all")
];
};
}