Skip to content

Commit

Permalink
Refactor into individual update scripts
Browse files Browse the repository at this point in the history
Makes the diff smaller for a future non-trivial update script
  • Loading branch information
infinisil committed Apr 10, 2024
1 parent 3f361a4 commit 0d33bd1
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,44 @@ let
};

# Run regularly by CI and turned into a PR
autoPrUpdate = pkgs.writeShellApplication {
name = "auto-pr-update";
runtimeInputs = with pkgs; [
npins
cargo
];
text =
let
commands = {
"npins changes" = ''
npins update --directory "$REPO_ROOT/npins"'';
"cargo changes" = ''
cargo update --manifest-path "$REPO_ROOT/Cargo.toml"'';
autoPrUpdate =
let
updateScripts = {
npins = pkgs.writeShellApplication {
name = "update-npins";
runtimeInputs = with pkgs; [
npins
];
text = ''
echo -e '<details><summary>npins changes</summary>\n\n```'
npins update --directory "$1/npins" 2>&1
echo -e '```\n</details>'
'';
};
in
''
REPO_ROOT=$1
echo "Run automated updates"
''
+ pkgs.lib.concatStrings (pkgs.lib.mapAttrsToList (title: command: ''
echo -e '<details><summary>${title}</summary>\n\n```'
${command} 2>&1
echo -e '```\n</details>'
'') commands);
};
cargo = pkgs.writeShellApplication {
name = "update-cargo";
runtimeInputs = with pkgs; [
cargo
];
text = ''
echo -e '<details><summary>cargo changes</summary>\n\n```'
cargo update --manifest-path "$1/Cargo.toml" 2>&1
echo -e '```\n</details>'
'';
};
};
in
pkgs.writeShellApplication {
name = "auto-pr-update";
text = ''
# Prevent impurities
unset PATH
${lib.concatMapStringsSep "\n" (script: ''
echo >&2 "Running ${script}"
${lib.getExe script} "$1"
'') (lib.attrValues updateScripts)}
'';
};

# Tests the tool on the pinned Nixpkgs tree, this is a good sanity check
nixpkgsCheck = pkgs.runCommand "test-nixpkgs-check-by-name" {
Expand Down

0 comments on commit 0d33bd1

Please sign in to comment.