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,8 +196,9 @@ in
}
];
installationScript =
# bash
installationScript = builtins.concatStringsSep "\n" [
(
if cfg.installPath == null then
''
if ! type -t git >/dev/null; then
# This happens in pure shells, including lorri
@ -205,8 +214,15 @@ in
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"}
'';
''
else
''
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")
];
};
}