This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
86 lines (76 loc) · 2.26 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
inputs = {
systems.url = "github:nix-systems/default";
};
outputs = {
systems,
nixpkgs,
...
} @ inputs: let
inherit (nixpkgs) lib;
eachSystem = nixpkgs.lib.genAttrs (import systems);
defaultCommitCallback =
# Reset the committer to prevent adding the rewriter's identity.
# Provided by Иван Жеков at
# https://github.com/newren/git-filter-repo/issues/379#issuecomment-1182480579
''
commit.committer_name = commit.author_name
commit.committer_email = commit.author_email
commit.committer_date = commit.author_date
'';
in {
packages = eachSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in rec {
default = lib.makeOverridable (
{
commitCallback ? defaultCommitCallback,
force ? false,
}:
pkgs.writeShellApplication {
name = "default";
runtimeInputs = [
pkgs.git-filter-repo
];
meta.mainProgram = "default";
text = ''
usage() {
echo "Usage: default <upstream ref>" >&2
}
if [[ $# -eq 0 ]]; then
usage
exit 1
fi
case "$1" in
-h|--help)
usage
exit
;;
*)
upstream="$1" ;;
esac
start="$(git rev-parse HEAD)"
branch="$(git symbolic-ref --short HEAD)"
tmp="recipes-$(date +%s)"
base=$(git merge-base "$upstream" "$start")
git switch -c "$tmp" "$upstream"
cleanup() {
git branch -D "$tmp"
}
trap cleanup ERR EXIT
git filter-repo --path recipes/ --refs "$base..HEAD" ${
lib.optionalString (commitCallback != null)
("--commit-callback '\n" + commitCallback + "'")
} ${lib.optionalString force "--force"}
git rebase "$start"
git switch "$branch"
git merge --ff-only "$tmp"
'';
}
) {};
forceUpdate = default.override {
force = true;
};
});
};
}