forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

appview: pages/templates/repo: tabular commit log

anirudh.fi 9c1dd0c0 5d021119

verified
Changed files
+438 -517
appview
pages
templates
repo
state
+1
.gitignore
···
appview/pages/static/*
result
!.gitkeep
+
out/
+59 -150
appview/pages/templates/repo/log.html
···
{{ define "title" }}commits · {{ .RepoInfo.FullName }}{{ end }}
-
{{ define "repoContent" }}
-
<section id="commit-message">
-
{{ $commit := index .Commits 0 }}
-
{{ $messageParts := splitN $commit.Message "\n\n" 2 }}
-
<div>
-
<a href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}" class="dark:text-white">
-
<p class="pb-5">{{ index $messageParts 0 }}</p>
-
{{ if gt (len $messageParts) 1 }}
-
<p class="mt-1 text-sm cursor-text pb-5">
-
{{ nl2br (unwrapText (index $messageParts 1)) }}
-
</p>
-
{{ end }}
-
</a>
-
</div>
-
-
<div class="text-sm text-gray-500 dark:text-gray-400">
-
<span class="font-mono">
-
<a
-
href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}"
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ slice $commit.Hash.String }}</a
-
>
-
</span>
-
<span class="mx-2 before:content-['·'] before:select-none"></span>
-
<span>
-
{{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }}
-
{{ if $didOrHandle }}
-
<a
-
href="/{{ $didOrHandle }}"
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ $didOrHandle }}</a
-
>
-
{{ else }}
-
<a
-
href="mailto:{{ $commit.Author.Email }}"
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ $commit.Author.Name }}</a
-
>
-
{{ end }}
-
</span>
-
<div
-
class="inline-block px-1 select-none after:content-['·']"
-
></div>
-
<span>{{ timeFmt $commit.Author.When }}</span>
-
</div>
-
</section>
-
{{ end }}
-
-
{{ define "repoAfter" }}
-
<main>
-
<div id="commit-log" class="flex-1 relative">
-
<div class="absolute left-8 top-0 bottom-0 w-px bg-gray-300 dark:bg-gray-600"></div>
-
{{ $end := length .Commits }}
-
{{ $commits := subslice .Commits 1 $end }}
-
{{ range $commits }}
-
<div class="flex flex-row justify-between items-center">
-
<div
-
class="relative w-full px-4 py-4 mt-4 rounded-sm bg-white dark:bg-gray-800"
-
>
-
<div id="commit-message">
-
{{ $messageParts := splitN .Message "\n\n" 2 }}
-
<div class="text-base cursor-pointer">
-
<div>
-
<div>
-
<a
-
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
-
class="inline no-underline hover:underline dark:text-white"
-
>{{ index $messageParts 0 }}</a
-
>
-
{{ if gt (len $messageParts) 1 }}
-
-
<button
-
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 dark:bg-gray-700 dark:hover:bg-gray-600 rounded"
-
hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')"
-
>
-
{{ i "ellipsis" "w-3 h-3" }}
-
</button>
-
{{ end }}
-
</div>
-
{{ if gt (len $messageParts) 1 }}
-
<p
-
class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300"
-
>
-
{{ nl2br (index $messageParts 1) }}
-
</p>
-
{{ end }}
-
</div>
-
</div>
+
<section id="commit-table">
+
<table class="w-full border-collapse">
+
<thead class="bg-gray-100 dark:bg-gray-700">
+
<tr>
+
<th class="px-4 py-2 text-sm text-left text-gray-700 dark:text-gray-300 uppercase font-bold">Author</th>
+
<th class="px-4 py-2 text-sm text-left text-gray-700 dark:text-gray-300 uppercase font-bold">Commit</th>
+
<th class="px-4 py-2 text-sm text-left text-gray-700 dark:text-gray-300 uppercase font-bold">Message</th>
+
<th class="px-4 py-2 text-sm text-left text-gray-700 dark:text-gray-300 uppercase font-bold">Date</th>
+
</tr>
+
</thead>
+
<tbody>
+
{{ range $index, $commit := .Commits }}
+
{{ $messageParts := splitN $commit.Message "\n\n" 2 }}
+
<tr class="border-b border-gray-200 dark:border-gray-700">
+
<td class="px-4 py-3 align-top">
+
{{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }}
+
{{ if $didOrHandle }}
+
<a href="/{{ $didOrHandle }}" class="text-gray-700 dark:text-gray-300 no-underline hover:underline">{{ $didOrHandle }}</a>
+
{{ else }}
+
<a href="mailto:{{ $commit.Author.Email }}" class="text-gray-700 dark:text-gray-300 no-underline hover:underline">{{ $commit.Author.Name }}</a>
+
{{ end }}
+
</td>
+
<td class="px-4 py-3 align-top font-mono flex items-end">
+
<a href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}" class="text-gray-700 dark:text-gray-300 no-underline hover:underline">{{ slice $commit.Hash.String 0 8 }}</a>
+
<div class="inline-flex">
+
<button class="p-1 mx-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded"
+
title="Copy SHA"
+
onclick="navigator.clipboard.writeText('{{ $commit.Hash.String }}'); this.innerHTML=`{{ i "copy-check" "w-4 h-4" }}`; setTimeout(() => this.innerHTML=`{{ i "copy" "w-4 h-4" }}`, 1500)">
+
{{ i "copy" "w-4 h-4" }}
+
</button>
+
<a href="/{{ $.RepoInfo.FullName }}/tree/{{ $commit.Hash.String }}" class="p-1 mx-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded" title="Browse repository at this commit">
+
{{ i "folder-code" "w-4 h-4" }}
+
</a>
</div>
-
-
<div class="text-sm text-gray-500 dark:text-gray-400 mt-3">
-
<span class="font-mono">
-
<a
-
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ slice .Hash.String 0 8 }}</a
-
>
-
</span>
-
<span
-
class="mx-2 before:content-['·'] before:select-none"
-
></span>
-
<span>
-
{{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }}
-
{{ if $didOrHandle }}
-
<a
-
href="/{{ $didOrHandle }}"
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ $didOrHandle }}</a
-
>
-
{{ else }}
-
<a
-
href="mailto:{{ .Author.Email }}"
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ .Author.Name }}</a
-
>
+
</td>
+
<td class="px-4 py-3 align-top">
+
{{ if eq $index 0 }}
+
<a href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}" class="dark:text-white no-underline hover:underline">
+
<p>{{ index $messageParts 0 }}</p>
+
{{ if gt (len $messageParts) 1 }}<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">{{ nl2br (unwrapText (index $messageParts 1)) }}</p>{{ end }}
+
</a>
+
{{ else }}
+
<div>
+
<a href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}" class="dark:text-white no-underline hover:underline">{{ index $messageParts 0 }}</a>
+
{{ if gt (len $messageParts) 1 }}
+
<button class="ml-2 py-1/2 px-1 bg-gray-200 hover:bg-gray-400 dark:bg-gray-700 dark:hover:bg-gray-600 rounded" hx-on:click="this.nextElementSibling.classList.toggle('hidden')">{{ i "ellipsis" "w-3 h-3" }}</button>
+
<p class="hidden mt-1 text-sm text-gray-600 dark:text-gray-400">{{ nl2br (index $messageParts 1) }}</p>
{{ end }}
-
</span>
-
<div
-
class="inline-block px-1 select-none after:content-['·']"
-
></div>
-
<span>{{ timeFmt .Author.When }}</span>
-
</div>
-
</div>
-
</div>
-
{{ end }}
-
</div>
-
-
{{ $commits_len := len .Commits }}
-
<div class="flex justify-end mt-4 gap-2">
-
{{ if gt .Page 1 }}
-
<a
-
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
-
hx-boost="true"
-
onclick="window.location.href = window.location.pathname + '?page={{ sub .Page 1 }}'"
-
>
-
{{ i "chevron-left" "w-4 h-4" }}
-
previous
-
</a>
-
{{ else }}
-
<div></div>
+
</div>
+
{{ end }}
+
</td>
+
<td class="px-4 py-3 align-top text-gray-500 dark:text-gray-400">{{ timeFmt $commit.Author.When }}</td>
+
</tr>
{{ end }}
+
</tbody>
+
</table>
+
</section>
-
{{ if eq $commits_len 30 }}
-
<a
-
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
-
hx-boost="true"
-
onclick="window.location.href = window.location.pathname + '?page={{ add .Page 1 }}'"
-
>
-
next
-
{{ i "chevron-right" "w-4 h-4" }}
-
</a>
-
{{ end }}
-
</div>
-
</main>
+
{{ $commits_len := len .Commits }}
+
<div class="flex justify-end mt-4 gap-2">
+
{{ if gt .Page 1 }}<a class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700" hx-boost="true" onclick="window.location.href = window.location.pathname + '?page={{ sub .Page 1 }}'">{{ i "chevron-left" "w-4 h-4" }} previous</a>{{ else }}<div></div>{{ end }}
+
{{ if eq $commits_len 60 }}<a class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700" hx-boost="true" onclick="window.location.href = window.location.pathname + '?page={{ add .Page 1 }}'">next {{ i "chevron-right" "w-4 h-4" }}</a>{{ end }}
+
</div>
{{ end }}
+1 -1
appview/state/repo.go
···
protocol = "https"
}
-
resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/log/%s?page=%d&per_page=30", protocol, f.Knot, f.OwnerDid(), f.RepoName, ref, page))
+
resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/log/%s?page=%d&per_page=60", protocol, f.Knot, f.OwnerDid(), f.RepoName, ref, page))
if err != nil {
log.Println("failed to reach knotserver", err)
return
+377 -366
flake.nix
···
};
};
-
outputs = {
-
self,
-
nixpkgs,
-
indigo,
-
htmx-src,
-
lucide-src,
-
gitignore,
-
inter-fonts-src,
-
ibm-plex-mono-src,
-
}: let
-
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
-
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
-
nixpkgsFor = forAllSystems (system:
-
import nixpkgs {
-
inherit system;
-
overlays = [self.overlays.default];
-
});
-
inherit (gitignore.lib) gitignoreSource;
-
in {
-
overlays.default = final: prev: let
-
goModHash = "sha256-EilWxfqrcKDaSR5zA3ZuDSCq7V+/IfWpKPu8HWhpndA=";
-
buildCmdPackage = name:
-
final.buildGoModule {
-
pname = name;
-
version = "0.1.0";
-
src = gitignoreSource ./.;
-
subPackages = ["cmd/${name}"];
-
vendorHash = goModHash;
-
CGO_ENABLED = 0;
-
};
-
in {
-
indigo-lexgen = final.buildGoModule {
-
pname = "indigo-lexgen";
-
version = "0.1.0";
-
src = indigo;
-
subPackages = ["cmd/lexgen"];
-
vendorHash = "sha256-pGc29fgJFq8LP7n/pY1cv6ExZl88PAeFqIbFEhB3xXs=";
-
doCheck = false;
-
};
-
-
appview = with final;
-
final.pkgsStatic.buildGoModule {
-
pname = "appview";
-
version = "0.1.0";
-
src = gitignoreSource ./.;
-
postUnpack = ''
-
pushd source
-
mkdir -p appview/pages/static/{fonts,icons}
-
cp -f ${htmx-src} appview/pages/static/htmx.min.js
-
cp -rf ${lucide-src}/*.svg appview/pages/static/icons/
-
cp -f ${inter-fonts-src}/web/InterVariable*.woff2 appview/pages/static/fonts/
-
cp -f ${inter-fonts-src}/web/InterDisplay*.woff2 appview/pages/static/fonts/
-
cp -f ${ibm-plex-mono-src}/fonts/complete/woff2/IBMPlexMono-Regular.woff2 appview/pages/static/fonts/
-
${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o appview/pages/static/tw.css
-
popd
-
'';
-
doCheck = false;
-
subPackages = ["cmd/appview"];
-
vendorHash = goModHash;
-
CGO_ENABLED = 1;
-
stdenv = pkgsStatic.stdenv;
-
};
-
-
knotserver = with final;
-
final.pkgsStatic.buildGoModule {
-
pname = "knotserver";
-
version = "0.1.0";
-
src = gitignoreSource ./.;
-
nativeBuildInputs = [final.makeWrapper];
-
subPackages = ["cmd/knotserver"];
-
vendorHash = goModHash;
-
installPhase = ''
-
runHook preInstall
-
-
mkdir -p $out/bin
-
cp $GOPATH/bin/knotserver $out/bin/knotserver
-
-
wrapProgram $out/bin/knotserver \
-
--prefix PATH : ${pkgs.git}/bin
-
-
runHook postInstall
-
'';
-
CGO_ENABLED = 1;
-
};
-
knotserver-unwrapped = final.pkgsStatic.buildGoModule {
-
pname = "knotserver";
-
version = "0.1.0";
-
src = gitignoreSource ./.;
-
subPackages = ["cmd/knotserver"];
-
vendorHash = goModHash;
-
CGO_ENABLED = 1;
-
};
-
repoguard = buildCmdPackage "repoguard";
-
keyfetch = buildCmdPackage "keyfetch";
-
};
-
packages = forAllSystems (system: {
-
inherit
-
(nixpkgsFor."${system}")
-
indigo-lexgen
-
appview
-
knotserver
-
knotserver-unwrapped
-
repoguard
-
keyfetch
-
;
-
});
-
defaultPackage = forAllSystems (system: nixpkgsFor.${system}.appview);
-
formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra);
-
devShells = forAllSystems (system: let
-
pkgs = nixpkgsFor.${system};
-
staticShell = pkgs.mkShell.override {
-
stdenv = pkgs.pkgsStatic.stdenv;
-
};
-
in {
-
default = staticShell {
-
nativeBuildInputs = [
-
pkgs.go
-
pkgs.air
-
pkgs.gopls
-
pkgs.httpie
-
pkgs.indigo-lexgen
-
pkgs.litecli
-
pkgs.websocat
-
pkgs.tailwindcss
-
pkgs.nixos-shell
-
];
-
shellHook = ''
-
mkdir -p appview/pages/static/{fonts,icons}
-
cp -f ${htmx-src} appview/pages/static/htmx.min.js
-
cp -rf ${lucide-src}/*.svg appview/pages/static/icons/
-
cp -f ${inter-fonts-src}/web/InterVariable*.woff2 appview/pages/static/fonts/
-
cp -f ${inter-fonts-src}/web/InterDisplay*.woff2 appview/pages/static/fonts/
-
cp -f ${ibm-plex-mono-src}/fonts/complete/woff2/IBMPlexMono-Regular.woff2 appview/pages/static/fonts/
-
'';
-
};
-
});
-
apps = forAllSystems (system: let
-
pkgs = nixpkgsFor."${system}";
-
air-watcher = name:
-
pkgs.writeShellScriptBin "run"
-
''
-
${pkgs.air}/bin/air -c /dev/null \
-
-build.cmd "${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o ./appview/pages/static/tw.css && ${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" \
-
-build.bin "./out/${name}.out" \
-
-build.include_ext "go"
-
'';
-
tailwind-watcher =
-
pkgs.writeShellScriptBin "run"
-
''
-
${pkgs.tailwindcss}/bin/tailwindcss -w -i input.css -o ./appview/pages/static/tw.css
-
'';
-
in {
-
watch-appview = {
-
type = "app";
-
program = ''${air-watcher "appview"}/bin/run'';
-
};
-
watch-knotserver = {
-
type = "app";
-
program = ''${air-watcher "knotserver"}/bin/run'';
-
};
-
watch-tailwind = {
-
type = "app";
-
program = ''${tailwind-watcher}/bin/run'';
-
};
-
});
-
-
nixosModules.appview = {
-
config,
-
pkgs,
-
lib,
-
...
+
outputs =
+
{ self
+
, nixpkgs
+
, indigo
+
, htmx-src
+
, lucide-src
+
, gitignore
+
, inter-fonts-src
+
, ibm-plex-mono-src
+
,
}:
-
with lib; {
-
options = {
-
services.tangled-appview = {
-
enable = mkOption {
-
type = types.bool;
-
default = false;
-
description = "Enable tangled appview";
+
let
+
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
+
nixpkgsFor = forAllSystems (system:
+
import nixpkgs {
+
inherit system;
+
overlays = [ self.overlays.default ];
+
});
+
inherit (gitignore.lib) gitignoreSource;
+
in
+
{
+
overlays.default = final: prev:
+
let
+
goModHash = "sha256-EilWxfqrcKDaSR5zA3ZuDSCq7V+/IfWpKPu8HWhpndA=";
+
buildCmdPackage = name:
+
final.buildGoModule {
+
pname = name;
+
version = "0.1.0";
+
src = gitignoreSource ./.;
+
subPackages = [ "cmd/${name}" ];
+
vendorHash = goModHash;
+
CGO_ENABLED = 0;
};
-
port = mkOption {
-
type = types.int;
-
default = 3000;
-
description = "Port to run the appview on";
-
};
-
cookie_secret = mkOption {
-
type = types.str;
-
default = "00000000000000000000000000000000";
-
description = "Cookie secret";
+
in
+
{
+
indigo-lexgen = final.buildGoModule {
+
pname = "indigo-lexgen";
+
version = "0.1.0";
+
src = indigo;
+
subPackages = [ "cmd/lexgen" ];
+
vendorHash = "sha256-pGc29fgJFq8LP7n/pY1cv6ExZl88PAeFqIbFEhB3xXs=";
+
doCheck = false;
+
};
+
+
appview = with final;
+
final.pkgsStatic.buildGoModule {
+
pname = "appview";
+
version = "0.1.0";
+
src = gitignoreSource ./.;
+
postUnpack = ''
+
pushd source
+
mkdir -p appview/pages/static/{fonts,icons}
+
cp -f ${htmx-src} appview/pages/static/htmx.min.js
+
cp -rf ${lucide-src}/*.svg appview/pages/static/icons/
+
cp -f ${inter-fonts-src}/web/InterVariable*.woff2 appview/pages/static/fonts/
+
cp -f ${inter-fonts-src}/web/InterDisplay*.woff2 appview/pages/static/fonts/
+
cp -f ${ibm-plex-mono-src}/fonts/complete/woff2/IBMPlexMono-Regular.woff2 appview/pages/static/fonts/
+
${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o appview/pages/static/tw.css
+
popd
+
'';
+
doCheck = false;
+
subPackages = [ "cmd/appview" ];
+
vendorHash = goModHash;
+
CGO_ENABLED = 1;
+
stdenv = pkgsStatic.stdenv;
};
-
};
-
};
-
config = mkIf config.services.tangled-appview.enable {
-
systemd.services.tangled-appview = {
-
description = "tangled appview service";
-
wantedBy = ["multi-user.target"];
+
knotserver = with final;
+
final.pkgsStatic.buildGoModule {
+
pname = "knotserver";
+
version = "0.1.0";
+
src = gitignoreSource ./.;
+
nativeBuildInputs = [ final.makeWrapper ];
+
subPackages = [ "cmd/knotserver" ];
+
vendorHash = goModHash;
+
installPhase = ''
+
runHook preInstall
-
serviceConfig = {
-
ListenStream = "0.0.0.0:${toString config.services.tangled-appview.port}";
-
ExecStart = "${self.packages.${pkgs.system}.appview}/bin/appview";
-
Restart = "always";
-
};
+
mkdir -p $out/bin
+
cp $GOPATH/bin/knotserver $out/bin/knotserver
-
environment = {
-
TANGLED_DB_PATH = "appview.db";
-
TANGLED_COOKIE_SECRET = config.services.tangled-appview.cookie_secret;
+
wrapProgram $out/bin/knotserver \
+
--prefix PATH : ${pkgs.git}/bin
+
+
runHook postInstall
+
'';
+
CGO_ENABLED = 1;
};
+
knotserver-unwrapped = final.pkgsStatic.buildGoModule {
+
pname = "knotserver";
+
version = "0.1.0";
+
src = gitignoreSource ./.;
+
subPackages = [ "cmd/knotserver" ];
+
vendorHash = goModHash;
+
CGO_ENABLED = 1;
};
+
repoguard = buildCmdPackage "repoguard";
+
keyfetch = buildCmdPackage "keyfetch";
};
-
};
+
packages = forAllSystems (system: {
+
inherit
+
(nixpkgsFor."${system}")
+
indigo-lexgen
+
appview
+
knotserver
+
knotserver-unwrapped
+
repoguard
+
keyfetch
+
;
+
});
+
defaultPackage = forAllSystems (system: nixpkgsFor.${system}.appview);
+
formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra);
+
devShells = forAllSystems (system:
+
let
+
pkgs = nixpkgsFor.${system};
+
staticShell = pkgs.mkShell.override {
+
stdenv = pkgs.pkgsStatic.stdenv;
+
};
+
in
+
{
+
default = staticShell {
+
nativeBuildInputs = [
+
pkgs.go
+
pkgs.air
+
pkgs.gopls
+
pkgs.httpie
+
pkgs.indigo-lexgen
+
pkgs.litecli
+
pkgs.websocat
+
pkgs.tailwindcss
+
pkgs.nixos-shell
+
];
+
shellHook = ''
+
mkdir -p appview/pages/static/{fonts,icons}
+
cp -f ${htmx-src} appview/pages/static/htmx.min.js
+
cp -rf ${lucide-src}/*.svg appview/pages/static/icons/
+
cp -f ${inter-fonts-src}/web/InterVariable*.woff2 appview/pages/static/fonts/
+
cp -f ${inter-fonts-src}/web/InterDisplay*.woff2 appview/pages/static/fonts/
+
cp -f ${ibm-plex-mono-src}/fonts/complete/woff2/IBMPlexMono-Regular.woff2 appview/pages/static/fonts/
+
'';
+
};
+
});
+
apps = forAllSystems (system:
+
let
+
pkgs = nixpkgsFor."${system}";
+
air-watcher = name:
+
pkgs.writeShellScriptBin "run"
+
''
+
TANGLED_DEV=true ${pkgs.air}/bin/air -c /dev/null \
+
-build.cmd "${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o ./appview/pages/static/tw.css && ${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" \
+
-build.bin "./out/${name}.out" \
+
-build.include_ext "go"
+
'';
+
tailwind-watcher =
+
pkgs.writeShellScriptBin "run"
+
''
+
${pkgs.tailwindcss}/bin/tailwindcss -w -i input.css -o ./appview/pages/static/tw.css
+
'';
+
in
+
{
+
watch-appview = {
+
type = "app";
+
program = ''${air-watcher "appview"}/bin/run'';
+
};
+
watch-knotserver = {
+
type = "app";
+
program = ''${air-watcher "knotserver"}/bin/run'';
+
};
+
watch-tailwind = {
+
type = "app";
+
program = ''${tailwind-watcher}/bin/run'';
+
};
+
});
-
nixosModules.knotserver = {
-
config,
-
pkgs,
-
lib,
-
...
-
}: let
-
cfg = config.services.tangled-knotserver;
-
in
-
with lib; {
-
options = {
-
services.tangled-knotserver = {
-
enable = mkOption {
-
type = types.bool;
-
default = false;
-
description = "Enable a tangled knotserver";
+
nixosModules.appview =
+
{ config
+
, pkgs
+
, lib
+
, ...
+
}:
+
with lib; {
+
options = {
+
services.tangled-appview = {
+
enable = mkOption {
+
type = types.bool;
+
default = false;
+
description = "Enable tangled appview";
+
};
+
port = mkOption {
+
type = types.int;
+
default = 3000;
+
description = "Port to run the appview on";
+
};
+
cookie_secret = mkOption {
+
type = types.str;
+
default = "00000000000000000000000000000000";
+
description = "Cookie secret";
+
};
+
};
};
-
appviewEndpoint = mkOption {
-
type = types.str;
-
default = "https://tangled.sh";
-
description = "Appview endpoint";
-
};
+
config = mkIf config.services.tangled-appview.enable {
+
systemd.services.tangled-appview = {
+
description = "tangled appview service";
+
wantedBy = [ "multi-user.target" ];
-
gitUser = mkOption {
-
type = types.str;
-
default = "git";
-
description = "User that hosts git repos and performs git operations";
-
};
+
serviceConfig = {
+
ListenStream = "0.0.0.0:${toString config.services.tangled-appview.port}";
+
ExecStart = "${self.packages.${pkgs.system}.appview}/bin/appview";
+
Restart = "always";
+
};
-
openFirewall = mkOption {
-
type = types.bool;
-
default = true;
-
description = "Open port 22 in the firewall for ssh";
-
};
-
-
stateDir = mkOption {
-
type = types.path;
-
default = "/home/${cfg.gitUser}";
-
description = "Tangled knot data directory";
-
};
-
-
repo = {
-
scanPath = mkOption {
-
type = types.path;
-
default = cfg.stateDir;
-
description = "Path where repositories are scanned from";
+
environment = {
+
TANGLED_DB_PATH = "appview.db";
+
TANGLED_COOKIE_SECRET = config.services.tangled-appview.cookie_secret;
+
};
};
+
};
+
};
-
mainBranch = mkOption {
-
type = types.str;
-
default = "main";
-
description = "Default branch name for repositories";
+
nixosModules.knotserver =
+
{ config
+
, pkgs
+
, lib
+
, ...
+
}:
+
let
+
cfg = config.services.tangled-knotserver;
+
in
+
with lib; {
+
options = {
+
services.tangled-knotserver = {
+
enable = mkOption {
+
type = types.bool;
+
default = false;
+
description = "Enable a tangled knotserver";
};
-
};
-
server = {
-
listenAddr = mkOption {
+
appviewEndpoint = mkOption {
type = types.str;
-
default = "0.0.0.0:5555";
-
description = "Address to listen on";
+
default = "https://tangled.sh";
+
description = "Appview endpoint";
};
-
internalListenAddr = mkOption {
+
gitUser = mkOption {
type = types.str;
-
default = "127.0.0.1:5444";
-
description = "Internal address for inter-service communication";
+
default = "git";
+
description = "User that hosts git repos and performs git operations";
};
-
secretFile = mkOption {
-
type = lib.types.path;
-
example = "KNOT_SERVER_SECRET=<hash>";
-
description = "File containing secret key provided by appview (required)";
+
openFirewall = mkOption {
+
type = types.bool;
+
default = true;
+
description = "Open port 22 in the firewall for ssh";
};
-
dbPath = mkOption {
+
stateDir = mkOption {
type = types.path;
-
default = "${cfg.stateDir}/knotserver.db";
-
description = "Path to the database file";
+
default = "/home/${cfg.gitUser}";
+
description = "Tangled knot data directory";
};
-
hostname = mkOption {
-
type = types.str;
-
example = "knot.tangled.sh";
-
description = "Hostname for the server (required)";
+
repo = {
+
scanPath = mkOption {
+
type = types.path;
+
default = cfg.stateDir;
+
description = "Path where repositories are scanned from";
+
};
+
+
mainBranch = mkOption {
+
type = types.str;
+
default = "main";
+
description = "Default branch name for repositories";
+
};
};
-
dev = mkOption {
-
type = types.bool;
-
default = false;
-
description = "Enable development mode (disables signature verification)";
+
server = {
+
listenAddr = mkOption {
+
type = types.str;
+
default = "0.0.0.0:5555";
+
description = "Address to listen on";
+
};
+
+
internalListenAddr = mkOption {
+
type = types.str;
+
default = "127.0.0.1:5444";
+
description = "Internal address for inter-service communication";
+
};
+
+
secretFile = mkOption {
+
type = lib.types.path;
+
example = "KNOT_SERVER_SECRET=<hash>";
+
description = "File containing secret key provided by appview (required)";
+
};
+
+
dbPath = mkOption {
+
type = types.path;
+
default = "${cfg.stateDir}/knotserver.db";
+
description = "Path to the database file";
+
};
+
+
hostname = mkOption {
+
type = types.str;
+
example = "knot.tangled.sh";
+
description = "Hostname for the server (required)";
+
};
+
+
dev = mkOption {
+
type = types.bool;
+
default = false;
+
description = "Enable development mode (disables signature verification)";
+
};
};
};
};
-
};
-
config = mkIf cfg.enable {
-
environment.systemPackages = with pkgs; [git];
+
config = mkIf cfg.enable {
+
environment.systemPackages = with pkgs; [ git ];
-
system.activationScripts.gitConfig = ''
-
mkdir -p "${cfg.repo.scanPath}"
-
chown -R ${cfg.gitUser}:${cfg.gitUser} \
-
"${cfg.repo.scanPath}"
+
system.activationScripts.gitConfig = ''
+
mkdir -p "${cfg.repo.scanPath}"
+
chown -R ${cfg.gitUser}:${cfg.gitUser} \
+
"${cfg.repo.scanPath}"
-
mkdir -p "${cfg.stateDir}/.config/git"
-
cat > "${cfg.stateDir}/.config/git/config" << EOF
-
[user]
-
name = Git User
-
email = git@example.com
-
EOF
-
chown -R ${cfg.gitUser}:${cfg.gitUser} \
-
"${cfg.stateDir}"
-
'';
+
mkdir -p "${cfg.stateDir}/.config/git"
+
cat > "${cfg.stateDir}/.config/git/config" << EOF
+
[user]
+
name = Git User
+
email = git@example.com
+
EOF
+
chown -R ${cfg.gitUser}:${cfg.gitUser} \
+
"${cfg.stateDir}"
+
'';
-
users.users.${cfg.gitUser} = {
-
isSystemUser = true;
-
useDefaultShell = true;
-
home = cfg.stateDir;
-
createHome = true;
-
group = cfg.gitUser;
-
};
+
users.users.${cfg.gitUser} = {
+
isSystemUser = true;
+
useDefaultShell = true;
+
home = cfg.stateDir;
+
createHome = true;
+
group = cfg.gitUser;
+
};
-
users.groups.${cfg.gitUser} = {};
+
users.groups.${cfg.gitUser} = { };
-
services.openssh = {
-
enable = true;
-
extraConfig = ''
-
Match User ${cfg.gitUser}
-
AuthorizedKeysCommand /etc/ssh/keyfetch_wrapper
-
AuthorizedKeysCommandUser nobody
-
'';
-
};
+
services.openssh = {
+
enable = true;
+
extraConfig = ''
+
Match User ${cfg.gitUser}
+
AuthorizedKeysCommand /etc/ssh/keyfetch_wrapper
+
AuthorizedKeysCommandUser nobody
+
'';
+
};
-
environment.etc."ssh/keyfetch_wrapper" = {
-
mode = "0555";
-
text = ''
-
#!${pkgs.stdenv.shell}
-
${self.packages.${pkgs.system}.keyfetch}/bin/keyfetch \
-
-repoguard-path ${self.packages.${pkgs.system}.repoguard}/bin/repoguard \
-
-internal-api "http://${cfg.server.internalListenAddr}" \
-
-git-dir "${cfg.repo.scanPath}" \
-
-log-path /tmp/repoguard.log
-
'';
-
};
+
environment.etc."ssh/keyfetch_wrapper" = {
+
mode = "0555";
+
text = ''
+
#!${pkgs.stdenv.shell}
+
${self.packages.${pkgs.system}.keyfetch}/bin/keyfetch \
+
-repoguard-path ${self.packages.${pkgs.system}.repoguard}/bin/repoguard \
+
-internal-api "http://${cfg.server.internalListenAddr}" \
+
-git-dir "${cfg.repo.scanPath}" \
+
-log-path /tmp/repoguard.log
+
'';
+
};
-
systemd.services.knotserver = {
-
description = "knotserver service";
-
after = ["network.target" "sshd.service"];
-
wantedBy = ["multi-user.target"];
-
serviceConfig = {
-
User = cfg.gitUser;
-
WorkingDirectory = cfg.stateDir;
-
Environment = [
-
"KNOT_REPO_SCAN_PATH=${cfg.repo.scanPath}"
-
"KNOT_REPO_MAIN_BRANCH=${cfg.repo.mainBranch}"
-
"APPVIEW_ENDPOINT=${cfg.appviewEndpoint}"
-
"KNOT_SERVER_INTERNAL_LISTEN_ADDR=${cfg.server.internalListenAddr}"
-
"KNOT_SERVER_LISTEN_ADDR=${cfg.server.listenAddr}"
-
"KNOT_SERVER_DB_PATH=${cfg.server.dbPath}"
-
"KNOT_SERVER_HOSTNAME=${cfg.server.hostname}"
-
];
-
EnvironmentFile = cfg.server.secretFile;
-
ExecStart = "${self.packages.${pkgs.system}.knotserver}/bin/knotserver";
-
Restart = "always";
+
systemd.services.knotserver = {
+
description = "knotserver service";
+
after = [ "network.target" "sshd.service" ];
+
wantedBy = [ "multi-user.target" ];
+
serviceConfig = {
+
User = cfg.gitUser;
+
WorkingDirectory = cfg.stateDir;
+
Environment = [
+
"KNOT_REPO_SCAN_PATH=${cfg.repo.scanPath}"
+
"KNOT_REPO_MAIN_BRANCH=${cfg.repo.mainBranch}"
+
"APPVIEW_ENDPOINT=${cfg.appviewEndpoint}"
+
"KNOT_SERVER_INTERNAL_LISTEN_ADDR=${cfg.server.internalListenAddr}"
+
"KNOT_SERVER_LISTEN_ADDR=${cfg.server.listenAddr}"
+
"KNOT_SERVER_DB_PATH=${cfg.server.dbPath}"
+
"KNOT_SERVER_HOSTNAME=${cfg.server.hostname}"
+
];
+
EnvironmentFile = cfg.server.secretFile;
+
ExecStart = "${self.packages.${pkgs.system}.knotserver}/bin/knotserver";
+
Restart = "always";
+
};
};
-
};
-
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [22];
+
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 22 ];
+
};
};
-
};
-
nixosConfigurations.knotVM = nixpkgs.lib.nixosSystem {
-
system = "x86_64-linux";
-
modules = [
-
self.nixosModules.knotserver
-
({
-
config,
-
pkgs,
-
...
-
}: {
-
virtualisation.memorySize = 2048;
-
virtualisation.cores = 2;
-
services.getty.autologinUser = "root";
-
environment.systemPackages = with pkgs; [curl vim git];
-
systemd.tmpfiles.rules = let
-
u = config.services.tangled-knotserver.gitUser;
-
g = config.services.tangled-knotserver.gitUser;
-
in [
-
"d /var/lib/knotserver 0770 ${u} ${g} - -" # Create the directory first
-
"f+ /var/lib/knotserver/secret 0660 ${u} ${g} - KNOT_SERVER_SECRET=5b42390da4c6659f34c9a545adebd8af82c4a19960d735f651e3d582623ba9f2"
-
];
-
services.tangled-knotserver = {
-
enable = true;
-
server = {
-
secretFile = "/var/lib/knotserver/secret";
-
hostname = "localhost:6000";
-
listenAddr = "0.0.0.0:6000";
+
nixosConfigurations.knotVM = nixpkgs.lib.nixosSystem {
+
system = "x86_64-linux";
+
modules = [
+
self.nixosModules.knotserver
+
({ config
+
, pkgs
+
, ...
+
}: {
+
virtualisation.memorySize = 2048;
+
virtualisation.cores = 2;
+
services.getty.autologinUser = "root";
+
environment.systemPackages = with pkgs; [ curl vim git ];
+
systemd.tmpfiles.rules =
+
let
+
u = config.services.tangled-knotserver.gitUser;
+
g = config.services.tangled-knotserver.gitUser;
+
in
+
[
+
"d /var/lib/knotserver 0770 ${u} ${g} - -" # Create the directory first
+
"f+ /var/lib/knotserver/secret 0660 ${u} ${g} - KNOT_SERVER_SECRET=5b42390da4c6659f34c9a545adebd8af82c4a19960d735f651e3d582623ba9f2"
+
];
+
services.tangled-knotserver = {
+
enable = true;
+
server = {
+
secretFile = "/var/lib/knotserver/secret";
+
hostname = "localhost:6000";
+
listenAddr = "0.0.0.0:6000";
+
};
};
-
};
-
})
-
];
+
})
+
];
+
};
};
-
};
}