From c7461df026b2736fb6d1a91c2289e0e2c4e4489e Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Fri, 7 Jul 2023 17:11:15 +0800 Subject: [PATCH] modules/mutable-files: add gopass fetch type --- modules/home-manager/files/mutable-files.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/home-manager/files/mutable-files.nix b/modules/home-manager/files/mutable-files.nix index ea7447fb..f77e6e88 100644 --- a/modules/home-manager/files/mutable-files.nix +++ b/modules/home-manager/files/mutable-files.nix @@ -37,7 +37,7 @@ let }; type = lib.mkOption { - type = lib.types.enum [ "git" "fetch" "archive" ]; + type = lib.types.enum [ "git" "fetch" "archive" "gopass" ]; description = lib.mkDoc '' Type that configures the behavior for fetching the URL. @@ -47,6 +47,7 @@ let - For `git`, it will be fetched with `git clone`. - For `archive`, the file will be fetched with `curl` and extracted before putting the file. + - For `gopass`, the file will be cloned with `gopass`. The default type is `fetch`. ''; @@ -116,11 +117,12 @@ in url = lib.escapeShellArg value.url; path = lib.escapeShellArg value.path; extraArgs = lib.escapeShellArgs value.extraArgs; + isFetchType = type: lib.optionalString (value.type == type); in '' - ${lib.optionalString (value.type == "git") "[ -d ${path} ] || git clone ${extraArgs} ${url} ${path}"} - ${lib.optionalString (value.type == "fetch") "[ -e ${path} ] || curl ${extraArgs} ${url} --output ${path}"} - ${lib.optionalString (value.type == "archive") '' + ${isFetchType "git" "[ -d ${path} ] || git clone ${extraArgs} ${url} ${path}"} + ${isFetchType "fetch" "[ -e ${path} ] || curl ${extraArgs} ${url} --output ${path}"} + ${isFetchType "archive" '' [ -e ${path} ] || { filename=$(curl ${extraArgs} --output-dir /tmp --silent --show-error --write-out '%{filename_effective}' --remote-name --remote-header-name --location ${url}) ${if (value.extractPath != null) then @@ -130,6 +132,9 @@ in } } ''} + ${isFetchType "gopass" '' + [ -e ${path} ] || gopass clone ${extraArgs} ${url} --path ${path} ${extraArgs} + ''} '') cfg;