From 45633dc6a0512cbbb010bc615b5d1b6e46e57597 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Wed, 22 Jan 2025 13:09:37 +0100 Subject: [PATCH] feat(nix-reuse): Add installPath option This allows installing the REUSE.toml file in a distinct directory from the git toplevel --- modules/reuse.nix | 54 ++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/modules/reuse.nix b/modules/reuse.nix index b9e8729..7a9bbf0 100644 --- a/modules/reuse.nix +++ b/modules/reuse.nix @@ -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") + ]; }; }