summaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rwxr-xr-xpkgs/shell/plans82
1 files changed, 39 insertions, 43 deletions
diff --git a/pkgs/shell/plans b/pkgs/shell/plans
index 16e84187..94f7395f 100755
--- a/pkgs/shell/plans
+++ b/pkgs/shell/plans
@@ -8,10 +8,13 @@
# ~/sync/src/NAME/cabal.nix a Haskell checkout's (cabal2nix)
# ~/sync/src/hrm/pkgs/rust/NAME/Cargo.json
# one kept in hrm, for where there's
-# no checkout, like the hosts
+# no checkout, like the hosts, unused
+# if the package's source has a
+# Cargo.json of its own
# Without --update, says for each, or each of the named projects, whether
-# its plan is current, stale or missing, as hrm's evaluation sees it. With
-# --update, makes them again.
+# its plan is current, stale or missing, as hrm's evaluation sees it, and
+# whether a plan kept in hrm is unused. With --update, makes them all again,
+# unused ones too, as they may be used on a builder.
set -efu
@@ -79,70 +82,63 @@ eval_plans() {
"
}
-# NAME KIND PLAN STATE for each selected plan. Current means that hrm's
-# evaluation accepts it.
-states() {
+# For each selected plan, one line: NAME KIND PLAN STATE SOURCE FLAGS...
+# STATE is current if hrm's evaluation accepts the plan, stale if not,
+# missing if there is none; a plan kept in hrm whose package's source has
+# a plan of its own is unused/current or unused/stale. SOURCE and FLAGS
+# are what to make a Rust plan from: the source, and crate2nix's feature
+# flags. All in one evaluation.
+report() {
eval_plans '
pkgs: map ({ name, kind, plan }: let
accepted = x: (builtins.tryEval (builtins.seq x true)).success;
+ lib = pkgs.lib;
+ unused = kind == "hrm" && builtins.pathExists "${args.src}/Cargo.json";
+ args = {
+ rust = pkgs.rustCrateArgs.${name};
+ haskell = { src = ""; };
+ hrm = pkgs.rustHrmCrateArgs.${name};
+ }.${kind};
check = {
- rust = (pkgs.crate2nixPackage pkgs.rustCrateArgs.${name}).workspaceMembers;
+ rust = (pkgs.crate2nixPackage args).workspaceMembers;
haskell = pkgs.haskellPackages.${name};
- hrm = (pkgs.crate2nixPackage pkgs.rustHrmCrateArgs.${name}).workspaceMembers;
+ # This plan, even where the plan of the source wins over it.
+ hrm = (pkgs.crate2nixPackage (args // { resolvedJson = plan; })).workspaceMembers;
};
in {
inherit name kind plan;
+ # To make a plan from: the source itself, not its copy in the store,
+ # which can leave Cargo.lock out.
+ src = if args ? cargoLock then dirOf (toString args.cargoLock) else "${args.src}";
+ features = args.features or [ "default" ];
state =
if !builtins.pathExists plan then "missing"
- else if accepted check.${kind} then "current"
- else "stale";
+ else (lib.optionalString unused "unused/")
+ + (if accepted check.${kind} then "current" else "stale");
})
' |
- jq -r '.[] | "\(.name) \(.kind) \(.plan) \(.state)"'
-}
-
-# The source to make a Rust plan from, and crate2nix's feature flags for it,
-# from hrm's arguments for the package: SOURCE FLAGS...
-rust_args() {
- nix-instantiate --eval --strict --json --read-write-mode \
- --arg hrm "$hrm" --argstr name "$1" --argstr kind "$2" \
- -E '
- { hrm, name, kind }: let
- pkgs = (import hrm {}).pkgs;
- args = {
- rust = pkgs.rustCrateArgs.${name};
- hrm = pkgs.rustHrmCrateArgs.${name};
- }.${kind};
- in {
- src = "${args.src}";
- features = args.features or [ "default" ];
- }
- ' |
jq -r '
- [
- .src,
+ .[] | [
+ .name, .kind, .plan, .state, (if .src == "" then "-" else .src end),
(if .features | index("default") then "--default-features" else "--no-default-features" end),
(.features[] | select(. != "default") | "--features", .)
] | join(" ")
'
}
-# Makes the plan PLAN of the project NAME, of kind KIND.
+# Makes the plan PLAN of the project NAME, of kind KIND, from SOURCE with
+# FLAGS.
make_plan() {
- name=$1 kind=$2 plan=$3
+ name=$1 kind=$2 plan=$3 source=$4
+ shift 4
case $kind in
rust)
# In the checkout, as crate2nix writes paths relative to its output.
- set -- $(rust_args "$name" "$kind")
- shift
(cd "$src/$name" && crate2nix generate --format json -o .Cargo.json.tmp "$@")
mv "$src/$name/.Cargo.json.tmp" "$plan"
;;
hrm)
# In a writable copy of the package's source, for the same reason.
- set -- $(rust_args "$name" "$kind")
- source=$1
- shift
work=$(mktemp -d --tmpdir plans.XXXXXXXX)
cp -R "$source"/. "$work"
chmod -R u+w "$work"
@@ -161,11 +157,11 @@ make_plan() {
}
if $update; then
- printf '%s\n' "$selected" |
- while read -r name kind plan; do
+ report |
+ while read -r name kind plan state source flags; do
echo "plans: making $plan" >&2
- make_plan "$name" "$kind" "$plan"
+ make_plan "$name" "$kind" "$plan" "$source" $flags
done
fi
-states | sed "s|$src/||" | column -t
+report | cut -d ' ' -f 1-4 | sed "s|$src/||" | column -t