init
This commit is contained in:
24 files changed
+3822
No files matched your search
@@ -0,0 +1,124 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>i-am-gcroot</title>
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #fbfbfa; --fg: #1d1d1b; --dim: #6b6b66; --line: #e3e2de; --row: #f2f1ee;
|
||||
--accent: #2f6fb3; --danger: #b3382f; --ok: #2f7d3a; --mark: #fff4cc;
|
||||
--indirect: #1f7a8c; --profile: #8a3fa0; --direct: #2f6fb3; --dangling: #b3382f; --runtime: #6b6b66;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #17181a; --fg: #e6e4df; --dim: #9a978f; --line: #2c2d30; --row: #1f2023;
|
||||
--accent: #6aa5e6; --danger: #e5776d; --ok: #74c47f; --mark: #3a3420;
|
||||
--indirect: #5cc0d1; --profile: #c48ad6; --direct: #6aa5e6; --dangling: #e5776d; --runtime: #9a978f;
|
||||
}
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, sans-serif; }
|
||||
header { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; position: sticky; top: 0; background: var(--bg); z-index: 1; }
|
||||
h1 { font-size: 16px; margin: 0; font-family: ui-monospace, monospace; }
|
||||
#controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; flex: 1; }
|
||||
input[name=q] { flex: 1; min-width: 240px; padding: 6px 8px; font: 13px ui-monospace, monospace; background: var(--row); color: var(--fg); border: 1px solid var(--line); border-radius: 4px; }
|
||||
label { white-space: nowrap; color: var(--dim); }
|
||||
select, button { font: inherit; padding: 4px 10px; border-radius: 4px; border: 1px solid var(--line); background: var(--row); color: var(--fg); cursor: pointer; }
|
||||
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
|
||||
.actions { display: flex; gap: 8px; align-items: center; padding: 8px 16px; flex-wrap: wrap; }
|
||||
.msg { padding: 8px 16px; }
|
||||
.msg.err { color: var(--danger); }
|
||||
.msg.ok { color: var(--ok); }
|
||||
.dim { color: var(--dim); }
|
||||
.wrap { overflow-x: auto; }
|
||||
table { border-collapse: collapse; width: 100%; font: 12.5px ui-monospace, monospace; }
|
||||
th, td { text-align: left; padding: 3px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
||||
th { position: sticky; top: 0; background: var(--bg); color: var(--dim); font-weight: 600; }
|
||||
td.num { text-align: right; }
|
||||
td.path { max-width: 50vw; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; }
|
||||
tr:hover td { background: var(--row); }
|
||||
tr:has(input:checked) td { background: var(--mark); }
|
||||
.kind { font-weight: 600; }
|
||||
.k-indirect { color: var(--indirect); } .k-profile { color: var(--profile); } .k-direct { color: var(--direct); }
|
||||
.k-dangling { color: var(--dangling); } .k-runtime { color: var(--runtime); }
|
||||
ul.results { margin: 4px 0; font: 12px ui-monospace, monospace; }
|
||||
details summary { cursor: pointer; color: var(--dim); }
|
||||
.htmx-request .spin { visibility: visible; } .spin { visibility: hidden; }
|
||||
</style>
|
||||
</head>
|
||||
<body hx-headers='{"X-Token": "{{.Token}}"}'>
|
||||
<header>
|
||||
<h1>i-am-gcroot</h1>
|
||||
<form id="controls" hx-get="/rows" hx-target="#rows" hx-include="#rows input[name=link]:checked"
|
||||
hx-trigger="input changed delay:300ms from:input[name=q], change, submit" onsubmit="return false">
|
||||
<input type="hidden" name="kinds" value="1">
|
||||
<input name="q" value="{{.Query}}" placeholder="text /re/ kind: owner:me under:/tmp older:30d size>1G -negate" autofocus>
|
||||
{{range kinds}}<label><input type="checkbox" name="kind" value="{{.}}" {{if index $.Kinds .}}checked{{end}}> <span class="k-{{.}}">{{.}}</span></label>{{end}}
|
||||
<label>sort <select name="sort">
|
||||
{{range $s := sorts}}<option {{if eq $s $.Sort}}selected{{end}}>{{$s}}</option>{{end}}
|
||||
</select></label>
|
||||
<label><input type="checkbox" name="desc" value="1" {{if .Desc}}checked{{end}}> desc</label>
|
||||
<label title="nix cache roots such as ~/.cache/nix/flake-registry.json"><input type="checkbox" name="hidden" value="1" {{if .Hidden}}checked{{end}}> hidden</label>
|
||||
</form>
|
||||
</header>
|
||||
<div id="rows">{{template "rows" .}}</div>
|
||||
<script>
|
||||
function selectAll(on) {
|
||||
document.querySelectorAll('#rows input[name=link]:not([data-protected])').forEach(c => c.checked = on);
|
||||
updateSel();
|
||||
}
|
||||
function updateSel() {
|
||||
let n = 0, size = 0;
|
||||
document.querySelectorAll('#rows input[name=link]:checked').forEach(c => { n++; size += +c.dataset.size || 0; });
|
||||
const el = document.getElementById('sel');
|
||||
if (el) el.textContent = n + ' selected, up to ' + human(size);
|
||||
}
|
||||
function human(n) {
|
||||
const u = ['B', 'K', 'M', 'G', 'T']; let i = 0;
|
||||
while (n >= 1024 && i < u.length - 1) { n /= 1024; i++; }
|
||||
return (i ? n.toFixed(1) : n) + u[i];
|
||||
}
|
||||
document.addEventListener('change', e => { if (e.target.name === 'link') updateSel(); });
|
||||
document.body.addEventListener('htmx:afterSwap', updateSel);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
{{define "rows"}}
|
||||
{{if .Err}}<div class="msg err">{{.Err}}</div>{{end}}
|
||||
{{if .Message}}<div class="msg ok">{{.Message}}
|
||||
{{if .Results}}<details {{if lt (len .Results) 15}}open{{end}}><summary>{{len .Results}} result(s)</summary><ul class="results">
|
||||
{{range .Results}}<li>{{if .Err}}<span class="msg err">fail</span> {{.Link}}: {{.Err}}{{else}}ok {{.Action}}{{end}}</li>{{end}}
|
||||
</ul></details>{{end}}
|
||||
</div>{{end}}
|
||||
<div class="actions">
|
||||
<span class="dim">{{.Total}} roots, {{len .Rows}} shown{{if .Status.Sizing}}, sizing {{.Status.SizesDone}}/{{.Status.SizesTodo}}{{end}}</span>
|
||||
<span id="sel" class="dim"></span>
|
||||
<button type="button" onclick="selectAll(true)">select all shown</button>
|
||||
<button type="button" onclick="selectAll(false)">clear</button>
|
||||
<button hx-post="/delete" hx-target="#rows" hx-include="#controls, #rows input[name=link]:checked" hx-vals='{"dry": "1"}'>dry run</button>
|
||||
<button class="danger" hx-post="/delete" hx-target="#rows" hx-include="#controls, #rows input[name=link]:checked"
|
||||
hx-confirm="Delete the selected GC roots?">delete selected</button>
|
||||
<button class="danger" hx-post="/delete" hx-target="#rows" hx-include="#controls, #rows input[name=link]:checked" hx-vals='{"collect": "1"}'
|
||||
hx-confirm="Delete the selected GC roots and garbage collect the store paths only they kept alive?">delete + collect <span class="spin">...</span></button>
|
||||
<button hx-post="/gc" hx-target="#rows" hx-include="#controls, #rows input[name=link]:checked"
|
||||
hx-confirm="Run nix-store --gc now?">run gc <span class="spin">...</span></button>
|
||||
<button hx-post="/refresh" hx-target="#rows" hx-include="#controls, #rows input[name=link]:checked">rescan</button>
|
||||
</div>
|
||||
{{if .Status.Sizing}}<div hx-get="/rows" hx-trigger="every 2s" hx-target="#rows" hx-include="#controls, #rows input[name=link]:checked"></div>{{end}}
|
||||
<div class="wrap"><table>
|
||||
<thead><tr><th></th><th>kind</th><th>owner</th><th>age</th><th>closure</th><th>link</th><th>target</th></tr></thead>
|
||||
<tbody>
|
||||
{{range .Rows}}<tr title="{{.Reason}}">
|
||||
<td>{{if .Deletable}}<input type="checkbox" name="link" value="{{.Link}}" data-size="{{if gt .ClosureSize 0}}{{.ClosureSize}}{{end}}" {{if .Protected}}data-protected{{end}} {{if index $.Checked .Link}}checked{{end}}>{{end}}{{if .Protected}} <span title="{{.Reason}}">!</span>{{end}}</td>
|
||||
<td class="kind k-{{.Kind}}">{{.Kind}}{{if .Current}} (current){{end}}</td>
|
||||
<td>{{.Owner}}</td>
|
||||
<td class="num">{{age .ModTime}}</td>
|
||||
<td class="num">{{if eq .Kind "dangling"}}-{{else}}{{size .ClosureSize}}{{end}}</td>
|
||||
<td class="path" title="{{.Link}}{{if .Via}} (via {{.Via}}){{end}}"><bdi>{{.Link}}{{if .Command}} <span class="dim">{{.Command}}</span>{{end}}</bdi></td>
|
||||
<td title="{{.Target}}">{{if .Target}}{{.TargetName}}{{else if gt .Count 1}}<span class="dim">({{.Count}} paths)</span>{{else if eq .Kind "dangling"}}<span class="dim">(missing)</span>{{else}}<span class="dim">{{.Reason}}</span>{{end}}</td>
|
||||
</tr>{{end}}
|
||||
</tbody></table></div>
|
||||
{{end}}
|
||||
Reference in new issue
Block a user