Commit 801bb29b authored by Profpatsch's avatar Profpatsch

containers/helpers: first version of `fetchgit-updater`

`fetchgit-updater` uses `nix-prefetch-git` to check for package updates. It is
passed a json file and returns a possibly updated json file on stdout.
parent 96c6dc8c
......@@ -25,6 +25,7 @@ let
prependPrefix = ./helpers/prepend-prefix.nix;
debugDockerImage = ./helpers/debug-docker-image.nix;
createStandaloneDockerImage = ./helpers/create-standalone-docker-image.nix;
fetchgitUpdater = ./helpers/fetchgit-updater;
}) // {
inherit (self.callPackage ./helpers/nix-json-trans.nix {})
json2json json2string;
......
{ stdenv, helpers, writeScript, writeText, nix-prefetch-scripts }:
let
args = writeText "args.nix" ''
{ nixPrefetchGit = "${nix-prefetch-scripts}/bin/nix-prefetch-git"; }
'';
in writeScript "fetchgit-updater" ''
#!${stdenv.shell}
${helpers.json2string} \
${args} \
${./json-to-prefetch-invocation.nix} \
"$1"
''
{ nixPrefetchGit }:
# Transform a nix-prefetch-git source json file
# to an a nix-prefetch-git invocation that takes
# the correct command line flags.
let
# Some attributes in the json are named differently
# than their command flag. Some even don’t map
# directly (like `deepClone`).
changedKeys = {
"deepClone" = b:
if b then "deepClone" else "no-deepClone";
"leaveDotGit" = const "leave-dotGit";
"fetchSubmodules" = const "fetch-submodules";
};
# keys that should not be passed
filteredKeys = [
# if --sha256 is passed, nix-prefetch-git does nothing
"sha256"
];
# filter out filteredKeys
keyFilter = filterAttrs (k: _: all (k': k != k') filteredKeys);
# transform the keys to their correct flag names
keyTrans = mapAttrs'
(k: v: nameValuePair ((changedKeys.${k} or id) k) v);
# flag invocation
toFlag = k: v: "--${k}"
+ (if isBool v then "" # boolean flag
else " ${toString v}"); # option with value
# the final shell invocation
# $1 still needs the nix-prefetch-git path
toInvoc = flags: ''
${nixPrefetchGit} \
${concatStringsSep " \\\n " (mapAttrsToList toFlag flags)}
'';
in
json: toInvoc (keyTrans (keyFilter json))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment