use treefmt-nix to format everything
13 files changed, 237 insertions(+), 160 deletions(-)
changed files
- README.md
- domain/calendar/calendar.go
- domain/content/builder/template/template.go
- domain/content/fetcher/fetcher.go
- domain/content/publisher/mux.go
- domain/web/templates/files.go
- flake.lock
- flake.nix
- shared/cache/cache.go
- shared/events/redis.go
- shared/storage/sqlite/db/query.sql.go
- shared/storage/sqlite/query.sql
- shared/storage/sqlite/schema.sql
M domain/calendar/calendar.go → domain/calendar/calendar.go
@@ -20,8 +20,10 @@ "alin.ovh/homestead/shared/cache" "alin.ovh/homestead/shared/config" ) -const Filename = "calendar.ics" -const Refresh = 30 * time.Minute +const ( + Filename = "calendar.ics" + Refresh = 30 * time.Minute +) type Options struct { URL config.URL
M domain/content/builder/template/template.go → domain/content/builder/template/template.go
@@ -18,13 +18,11 @@ "github.com/antchfx/xmlquery" "github.com/antchfx/xpath" ) -var ( - nsMap = map[string]string{ - "xsl": "http://www.w3.org/1999/XSL/Transform", - "atom": "http://www.w3.org/2005/Atom", - "xhtml": "http://www.w3.org/1999/xhtml", - } -) +var nsMap = map[string]string{ + "xsl": "http://www.w3.org/1999/XSL/Transform", + "atom": "http://www.w3.org/2005/Atom", + "xhtml": "http://www.w3.org/1999/xhtml", +} func RenderRobotsTXT(baseURL config.URL, w io.Writer) error { tpl, err := template.ParseFS(templates.Files, "robots.tmpl")
M domain/content/fetcher/fetcher.go → domain/content/fetcher/fetcher.go
@@ -23,9 +23,11 @@ "github.com/Southclaws/fault/fmsg" "github.com/google/renameio/v2" ) -var files = []string{"config.toml", "site.db"} -var numericFilename = regexp.MustCompile("[0-9]{3,}") -var timeout = 10 * time.Second +var ( + files = []string{"config.toml", "site.db"} + numericFilename = regexp.MustCompile("[0-9]{3,}") + timeout = 10 * time.Second +) type Fetcher struct { options *Options
M domain/content/publisher/mux.go → domain/content/publisher/mux.go
@@ -12,7 +12,6 @@ func (app *App) Index(w http.ResponseWriter, _ *http.Request) ihttp.Error { err := pubtpl.IndexPage(app.siteSettings, templates.PageSettings{ Title: "Home", }).Render(w) - if err != nil { return ihttp.InternalServerError("Failed to render index page", err) }
M domain/web/templates/files.go → domain/web/templates/files.go
@@ -7,9 +7,7 @@ "alin.ovh/homestead/shared/env" ) -var ( - Files fs.FS -) +var Files fs.FS func init() { Files = os.DirFS(env.GetEnvFallback("KO_DATA_PATH", "kodata"))
M flake.lock → flake.lock
@@ -76,6 +76,22 @@ "repo": "nixpkgs", "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1747958103, + "narHash": "sha256-qmmFCrfBwSHoWw7cVK4Aj+fns+c54EBP8cGqp/yK410=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "fe51d34885f7b5e3e7b59572796e1bcb427eccb1", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": "flake-compat",@@ -103,6 +119,7 @@ "inputs": { "gomod2nix": "gomod2nix", "nixpkgs": "nixpkgs", "pre-commit-hooks": "pre-commit-hooks", + "treefmt-nix": "treefmt-nix", "utils": "utils" } },@@ -118,6 +135,24 @@ }, "original": { "owner": "nix-systems", "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1750931469, + "narHash": "sha256-0IEdQB1nS+uViQw4k3VGUXntjkDp7aAlqcxdewb/hAc=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "ac8e6f32e11e9c7f153823abc3ab007f2a65d3e1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", "type": "github" } },
M flake.nix → flake.nix
@@ -7,94 +7,127 @@ inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs"; inputs.gomod2nix.inputs.flake-utils.follows = "utils"; inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; + inputs.treefmt-nix.url = "github:numtide/treefmt-nix"; - outputs = { self, nixpkgs, utils, pre-commit-hooks, gomod2nix, ... }: - utils.lib.eachDefaultSystem - (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - gomod2nix.overlays.default - ]; - }; - commonShellPackages = with pkgs; [ - go - hyperlink - just - ko - flyctl - redis - sqlc + outputs = + { + self, + nixpkgs, + utils, + pre-commit-hooks, + gomod2nix, + treefmt-nix, + ... + }: + utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + gomod2nix.overlays.default ]; - devPackages = with pkgs; [ - wgo - gopls - gotools - gomod2nix.legacyPackages.${system}.gomod2nix + }; + commonShellPackages = with pkgs; [ + go + hyperlink + just + ko + flyctl + redis + sqlc + ]; + devPackages = with pkgs; [ + wgo + gofumpt + gopls + gotools + gomod2nix.legacyPackages.${system}.gomod2nix + sqlfluff - systemfd - modd - ]; - in - { - devShells = { - ci = pkgs.mkShell { - packages = commonShellPackages; - }; - default = pkgs.mkShell { - inherit (self.checks.${system}.pre-commit-check) shellHook; - packages = devPackages ++ commonShellPackages; - }; + systemfd + modd + ]; + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + taplo.enable = true; + mdformat.enable = true; + gofumpt.enable = true; + golines.enable = true; + prettier.enable = true; + sqlfluff.enable = true; + sqlfluff.dialect = "sqlite"; + }; + settings = { + taplo.excludes = [ "gomod2nix.toml" ]; + }; + }; + in + { + devShells = { + ci = pkgs.mkShell { + packages = commonShellPackages; + }; + default = pkgs.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + packages = devPackages ++ commonShellPackages; }; - checks = { - pre-commit-check = pre-commit-hooks.lib.${system}.run { - src = ./.; - hooks = { - go-mod-tidy = { - enable = true; - name = "go-mod-tidy"; - description = "Run `go mod tidy`"; - types_or = [ "go" "go-mod" ]; - entry = "${pkgs.go}/bin/go mod tidy"; - pass_filenames = false; - }; - golines.enable = true; - golangci-lint.enable = true; - gotest.enable = true; - govet.enable = true; - gomod2nix = { - enable = true; - name = "gomod2nix"; - description = "Import go.mod updates to nix"; - types_or = [ "go-sum" ]; - entry = "${pkgs.gomod2nix}/bin/gomod2nix"; - pass_filenames = false; - }; - sqlc = { - enable = true; - name = "sqlc"; - description = "Generate go code from SQL"; - types_or = [ "sql" ]; - entry = "${pkgs.sqlc}/bin/sqlc generate"; - pass_filenames = false; - }; + }; + formatter = treefmtEval.config.build.wrapper; + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + go-mod-tidy = { + enable = true; + name = "go-mod-tidy"; + description = "Run `go mod tidy`"; + types_or = [ + "go" + "go-mod" + ]; + entry = "${pkgs.go}/bin/go mod tidy"; + pass_filenames = false; + }; + golines.enable = true; + golangci-lint.enable = true; + gotest.enable = true; + govet.enable = true; + gomod2nix = { + enable = true; + name = "gomod2nix"; + description = "Import go.mod updates to nix"; + types_or = [ "go-sum" ]; + entry = "${pkgs.gomod2nix}/bin/gomod2nix"; + pass_filenames = false; + }; + sqlc = { + enable = true; + name = "sqlc"; + description = "Generate go code from SQL"; + types_or = [ "sql" ]; + entry = "${pkgs.sqlc}/bin/sqlc generate"; + pass_filenames = false; }; }; }; - packages = { - build = pkgs.buildGoApplication { - pname = "build"; - version = self.shortRev or self.dirtyShortRev; - src = ./.; - modules = ./gomod2nix.toml; - subPackages = [ "domain/content/builder/build" ]; - nativeBuildInputs = with pkgs; [ makeWrapper ]; + }; + packages = { + build = pkgs.buildGoApplication { + pname = "build"; + version = self.shortRev or self.dirtyShortRev; + src = ./.; + modules = ./gomod2nix.toml; + subPackages = [ "domain/content/builder/build" ]; + nativeBuildInputs = with pkgs; [ makeWrapper ]; - postInstall = '' - wrapProgram $out/bin/build --set KO_DATA_PATH ${./kodata} - ''; - }; + postInstall = '' + wrapProgram $out/bin/build --set KO_DATA_PATH ${./kodata} + ''; }; - }); + }; + } + ); }