From 1f765c5b534fa2f3f8fdbb76ccec62d63a70c912 Mon Sep 17 00:00:00 2001 From: jaredmontoya <49511278+jaredmontoya@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:21:02 +0100 Subject: [PATCH] flake: fix/update --- .envrc | 2 +- .github/workflows/ci.yml | 6 ++++++ .../update-version-and-create-tag.yml | 15 ++++++--------- cli/cli_test.go | 3 ++- cli/output.go | 3 ++- common/attachment.go | 3 ++- common/domain_test.go | 3 ++- common/groups_items.go | 1 + core/plugin_registry.go | 3 ++- flake.lock | 18 +++++++++--------- flake.nix | 6 +++--- main.go | 3 ++- {pkgs => nix/pkgs}/fabric/default.nix | 8 +++++--- .../pkgs/fabric/gomod2nix.toml | 0 {pkgs => nix/pkgs}/fabric/version.nix | 0 shell.nix => nix/shell.nix | 0 treefmt.nix => nix/treefmt.nix | 1 + plugins/ai/azure/azure.go | 3 ++- plugins/ai/dryrun/dryrun_test.go | 5 +++-- plugins/ai/exolab/exolab.go | 3 ++- plugins/ai/gemini/gemini.go | 3 ++- plugins/ai/gemini/gemini_test.go | 3 ++- plugins/ai/openai/openai.go | 3 ++- plugins/ai/vendor.go | 1 + plugins/ai/vendors.go | 3 ++- plugins/db/fsdb/db.go | 3 ++- plugins/db/fsdb/sessions.go | 1 + plugins/db/fsdb/sessions_test.go | 3 ++- plugins/tools/converter/html_readability.go | 1 + restapi/ollama.go | 5 +++-- restapi/storage.go | 5 +++-- 31 files changed, 72 insertions(+), 45 deletions(-) rename {pkgs => nix/pkgs}/fabric/default.nix (85%) rename gomod2nix.toml => nix/pkgs/fabric/gomod2nix.toml (100%) rename {pkgs => nix/pkgs}/fabric/version.nix (100%) rename shell.nix => nix/shell.nix (100%) rename treefmt.nix => nix/treefmt.nix (84%) diff --git a/.envrc b/.envrc index 29da48d4..082c01fe 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,2 @@ -watch_file shell.nix +watch_file nix/shell.nix use flake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a2385a8..d19e85b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,9 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - name: Set up Go uses: actions/setup-go@v4 with: @@ -29,3 +32,6 @@ jobs: - name: Run tests run: go test -v ./... + + - name: Check Formatting + run: nix flake check diff --git a/.github/workflows/update-version-and-create-tag.yml b/.github/workflows/update-version-and-create-tag.yml index 9035cf6e..04c24215 100644 --- a/.github/workflows/update-version-and-create-tag.yml +++ b/.github/workflows/update-version-and-create-tag.yml @@ -25,9 +25,6 @@ jobs: - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - - name: Setup Nix Cache - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Set up Git run: | git config user.name "github-actions[bot]" @@ -63,21 +60,21 @@ jobs: - name: Update version.nix file run: | - echo "\"${{ env.new_version }}\"" > pkgs/fabric/version.nix + echo "\"${{ env.new_version }}\"" > nix/pkgs/fabric/version.nix - - name: Format source codes + - name: Format source code run: | - go fmt ./... + nix fmt - name: Update gomod2nix.toml file run: | - nix run .#gomod2nix + nix run .#gomod2nix -- --outdir nix/pkgs/fabric - name: Commit changes run: | git add version.go - git add pkgs/fabric/version.nix - git add gomod2nix.toml + git add nix/pkgs/fabric/version.nix + git add nix/pkgs/fabric/gomod2nix.toml git add . if ! git diff --staged --quiet; then git commit -m "Update version to ${{ env.new_tag }} and commit $commit_hash" diff --git a/cli/cli_test.go b/cli/cli_test.go index f0124d23..b8ff2c4c 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -1,10 +1,11 @@ package cli import ( - "github.com/danielmiessler/fabric/core" "os" "testing" + "github.com/danielmiessler/fabric/core" + "github.com/stretchr/testify/assert" ) diff --git a/cli/output.go b/cli/output.go index 9fa91e51..00793d92 100644 --- a/cli/output.go +++ b/cli/output.go @@ -2,8 +2,9 @@ package cli import ( "fmt" - "github.com/atotto/clipboard" "os" + + "github.com/atotto/clipboard" ) func CopyToClipboard(message string) (err error) { diff --git a/common/attachment.go b/common/attachment.go index b358772e..f493f700 100644 --- a/common/attachment.go +++ b/common/attachment.go @@ -6,11 +6,12 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/gabriel-vasile/mimetype" "io/ioutil" "net/http" "os" "path/filepath" + + "github.com/gabriel-vasile/mimetype" ) type Attachment struct { diff --git a/common/domain_test.go b/common/domain_test.go index 494082e6..a8f39c95 100644 --- a/common/domain_test.go +++ b/common/domain_test.go @@ -1,9 +1,10 @@ package common import ( + "testing" + goopenai "github.com/sashabaranov/go-openai" "github.com/stretchr/testify/assert" - "testing" ) func TestNormalizeMessages(t *testing.T) { diff --git a/common/groups_items.go b/common/groups_items.go index b8d77c77..9b2a6e8e 100644 --- a/common/groups_items.go +++ b/common/groups_items.go @@ -2,6 +2,7 @@ package common import ( "fmt" + "github.com/samber/lo" ) diff --git a/core/plugin_registry.go b/core/plugin_registry.go index 91b6400e..0bf92041 100644 --- a/core/plugin_registry.go +++ b/core/plugin_registry.go @@ -3,11 +3,12 @@ package core import ( "bytes" "fmt" - "github.com/danielmiessler/fabric/plugins/ai/exolab" "os" "path/filepath" "strconv" + "github.com/danielmiessler/fabric/plugins/ai/exolab" + "github.com/samber/lo" "github.com/danielmiessler/fabric/common" diff --git a/flake.lock b/flake.lock index c84b9db8..b88bfcb7 100644 --- a/flake.lock +++ b/flake.lock @@ -26,11 +26,11 @@ ] }, "locked": { - "lastModified": 1729448365, - "narHash": "sha256-oquZeWTYWTr5IxfwEzgsxjtD8SSFZYLdO9DaQb70vNU=", + "lastModified": 1733668782, + "narHash": "sha256-tPsqU00FhgdFr0JiQUiBMgPVbl1jbPCY5gbFiJycL3I=", "owner": "nix-community", "repo": "gomod2nix", - "rev": "5d387097aa716f35dd99d848dc26d8d5b62a104c", + "rev": "514283ec89c39ad0079ff2f3b1437404e4cba608", "type": "github" }, "original": { @@ -41,11 +41,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1729665710, - "narHash": "sha256-AlcmCXJZPIlO5dmFzV3V2XF6x/OpNWUV8Y/FMPGd8Z4=", + "lastModified": 1736344531, + "narHash": "sha256-8YVQ9ZbSfuUk2bUf2KRj60NRraLPKPS0Q4QFTbc+c2c=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2768c7d042a37de65bb1b5b3268fc987e534c49d", + "rev": "bffc22eb12172e6db3c5dde9e3e5628f8e3e7912", "type": "github" }, "original": { @@ -100,11 +100,11 @@ ] }, "locked": { - "lastModified": 1729613947, - "narHash": "sha256-XGOvuIPW1XRfPgHtGYXd5MAmJzZtOuwlfKDgxX5KT3s=", + "lastModified": 1736154270, + "narHash": "sha256-p2r8xhQZ3TYIEKBoiEhllKWQqWNJNoT9v64Vmg4q8Zw=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "aac86347fb5063960eccb19493e0cadcdb4205ca", + "rev": "13c913f5deb3a5c08bb810efd89dc8cb24dd968b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index d983dcfd..a274a39f 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,7 @@ let pkgs = nixpkgs.legacyPackages.${system}; in - treefmt-nix.lib.evalModule pkgs ./treefmt.nix + treefmt-nix.lib.evalModule pkgs ./nix/treefmt.nix ); in { @@ -49,7 +49,7 @@ pkgs = nixpkgs.legacyPackages.${system}; goEnv = gomod2nix.legacyPackages.${system}.mkGoEnv { pwd = ./.; }; in - import ./shell.nix { + import ./nix/shell.nix { inherit pkgs goEnv; inherit (gomod2nix.legacyPackages.${system}) gomod2nix; } @@ -62,7 +62,7 @@ in { default = self.packages.${system}.fabric; - fabric = pkgs.callPackage ./pkgs/fabric { + fabric = pkgs.callPackage ./nix/pkgs/fabric { inherit (gomod2nix.legacyPackages.${system}) buildGoApplication; }; inherit (gomod2nix.legacyPackages.${system}) gomod2nix; diff --git a/main.go b/main.go index 24a99e04..c9886404 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,10 @@ package main import ( "fmt" - "github.com/jessevdk/go-flags" "os" + "github.com/jessevdk/go-flags" + "github.com/danielmiessler/fabric/cli" ) diff --git a/pkgs/fabric/default.nix b/nix/pkgs/fabric/default.nix similarity index 85% rename from pkgs/fabric/default.nix rename to nix/pkgs/fabric/default.nix index c099316d..fca0fc03 100644 --- a/pkgs/fabric/default.nix +++ b/nix/pkgs/fabric/default.nix @@ -6,9 +6,11 @@ buildGoApplication { pname = "fabric-ai"; version = import ./version.nix; - src = ../../.; - pwd = ../../.; - modules = ../../gomod2nix.toml; + src = ../../../.; + pwd = ../../../.; + modules = ./gomod2nix.toml; + + doCheck = false; ldflags = [ "-s" diff --git a/gomod2nix.toml b/nix/pkgs/fabric/gomod2nix.toml similarity index 100% rename from gomod2nix.toml rename to nix/pkgs/fabric/gomod2nix.toml diff --git a/pkgs/fabric/version.nix b/nix/pkgs/fabric/version.nix similarity index 100% rename from pkgs/fabric/version.nix rename to nix/pkgs/fabric/version.nix diff --git a/shell.nix b/nix/shell.nix similarity index 100% rename from shell.nix rename to nix/shell.nix diff --git a/treefmt.nix b/nix/treefmt.nix similarity index 84% rename from treefmt.nix rename to nix/treefmt.nix index 8b05302f..14d2cb02 100644 --- a/treefmt.nix +++ b/nix/treefmt.nix @@ -6,6 +6,7 @@ statix.enable = true; nixfmt.enable = true; + goimports.enable = true; gofmt.enable = true; }; } diff --git a/plugins/ai/azure/azure.go b/plugins/ai/azure/azure.go index 885edb48..5753427f 100644 --- a/plugins/ai/azure/azure.go +++ b/plugins/ai/azure/azure.go @@ -1,10 +1,11 @@ package azure import ( + "strings" + "github.com/danielmiessler/fabric/plugins" "github.com/danielmiessler/fabric/plugins/ai/openai" goopenai "github.com/sashabaranov/go-openai" - "strings" ) func NewClient() (ret *Client) { diff --git a/plugins/ai/dryrun/dryrun_test.go b/plugins/ai/dryrun/dryrun_test.go index 045641d3..ba20a420 100644 --- a/plugins/ai/dryrun/dryrun_test.go +++ b/plugins/ai/dryrun/dryrun_test.go @@ -1,10 +1,11 @@ package dryrun import ( - "github.com/danielmiessler/fabric/common" - "github.com/sashabaranov/go-openai" "reflect" "testing" + + "github.com/danielmiessler/fabric/common" + "github.com/sashabaranov/go-openai" ) // Test generated using Keploy diff --git a/plugins/ai/exolab/exolab.go b/plugins/ai/exolab/exolab.go index 0174036b..3adfec7e 100644 --- a/plugins/ai/exolab/exolab.go +++ b/plugins/ai/exolab/exolab.go @@ -1,9 +1,10 @@ package exolab import ( + "strings" + "github.com/danielmiessler/fabric/plugins" "github.com/danielmiessler/fabric/plugins/ai/openai" - "strings" goopenai "github.com/sashabaranov/go-openai" ) diff --git a/plugins/ai/gemini/gemini.go b/plugins/ai/gemini/gemini.go index 1936dfd5..f3990d3e 100644 --- a/plugins/ai/gemini/gemini.go +++ b/plugins/ai/gemini/gemini.go @@ -4,9 +4,10 @@ import ( "context" "errors" "fmt" + "strings" + "github.com/danielmiessler/fabric/plugins" goopenai "github.com/sashabaranov/go-openai" - "strings" "github.com/danielmiessler/fabric/common" "github.com/google/generative-ai-go/genai" diff --git a/plugins/ai/gemini/gemini_test.go b/plugins/ai/gemini/gemini_test.go index c14cfe24..e3d58572 100644 --- a/plugins/ai/gemini/gemini_test.go +++ b/plugins/ai/gemini/gemini_test.go @@ -1,8 +1,9 @@ package gemini import ( - "github.com/google/generative-ai-go/genai" "testing" + + "github.com/google/generative-ai-go/genai" ) // Test generated using Keploy diff --git a/plugins/ai/openai/openai.go b/plugins/ai/openai/openai.go index c68ee083..9d26112c 100644 --- a/plugins/ai/openai/openai.go +++ b/plugins/ai/openai/openai.go @@ -4,10 +4,11 @@ import ( "context" "errors" "fmt" - "github.com/danielmiessler/fabric/plugins" "io" "log/slog" + "github.com/danielmiessler/fabric/plugins" + "github.com/danielmiessler/fabric/common" "github.com/samber/lo" "github.com/sashabaranov/go-openai" diff --git a/plugins/ai/vendor.go b/plugins/ai/vendor.go index c1ba9b0a..2c0245c0 100644 --- a/plugins/ai/vendor.go +++ b/plugins/ai/vendor.go @@ -2,6 +2,7 @@ package ai import ( "context" + "github.com/danielmiessler/fabric/plugins" goopenai "github.com/sashabaranov/go-openai" diff --git a/plugins/ai/vendors.go b/plugins/ai/vendors.go index ad2fca97..ab18146a 100644 --- a/plugins/ai/vendors.go +++ b/plugins/ai/vendors.go @@ -4,8 +4,9 @@ import ( "bytes" "context" "fmt" - "github.com/danielmiessler/fabric/plugins" "sync" + + "github.com/danielmiessler/fabric/plugins" ) func NewVendorsManager() *VendorsManager { diff --git a/plugins/db/fsdb/db.go b/plugins/db/fsdb/db.go index 4e458ded..6ee8534f 100644 --- a/plugins/db/fsdb/db.go +++ b/plugins/db/fsdb/db.go @@ -2,10 +2,11 @@ package fsdb import ( "fmt" - "github.com/joho/godotenv" "os" "path/filepath" "time" + + "github.com/joho/godotenv" ) func NewDb(dir string) (db *Db) { diff --git a/plugins/db/fsdb/sessions.go b/plugins/db/fsdb/sessions.go index 2f278744..54d5b961 100644 --- a/plugins/db/fsdb/sessions.go +++ b/plugins/db/fsdb/sessions.go @@ -2,6 +2,7 @@ package fsdb import ( "fmt" + "github.com/danielmiessler/fabric/common" goopenai "github.com/sashabaranov/go-openai" ) diff --git a/plugins/db/fsdb/sessions_test.go b/plugins/db/fsdb/sessions_test.go index 82c99fe0..9477ce14 100644 --- a/plugins/db/fsdb/sessions_test.go +++ b/plugins/db/fsdb/sessions_test.go @@ -1,8 +1,9 @@ package fsdb import ( - goopenai "github.com/sashabaranov/go-openai" "testing" + + goopenai "github.com/sashabaranov/go-openai" ) func TestSessions_GetOrCreateSession(t *testing.T) { diff --git a/plugins/tools/converter/html_readability.go b/plugins/tools/converter/html_readability.go index debbe1a6..001e274e 100644 --- a/plugins/tools/converter/html_readability.go +++ b/plugins/tools/converter/html_readability.go @@ -2,6 +2,7 @@ package converter import ( "bytes" + "github.com/go-shiori/go-readability" ) diff --git a/restapi/ollama.go b/restapi/ollama.go index 0d806729..fbc6d02a 100644 --- a/restapi/ollama.go +++ b/restapi/ollama.go @@ -5,13 +5,14 @@ import ( "context" "encoding/json" "fmt" - "github.com/danielmiessler/fabric/core" - "github.com/gin-gonic/gin" "io" "log" "net/http" "strings" "time" + + "github.com/danielmiessler/fabric/core" + "github.com/gin-gonic/gin" ) type OllamaModel struct { diff --git a/restapi/storage.go b/restapi/storage.go index 3b1d321e..47cde760 100644 --- a/restapi/storage.go +++ b/restapi/storage.go @@ -2,10 +2,11 @@ package restapi import ( "fmt" - "github.com/danielmiessler/fabric/plugins/db" - "github.com/gin-gonic/gin" "io" "net/http" + + "github.com/danielmiessler/fabric/plugins/db" + "github.com/gin-gonic/gin" ) // StorageHandler defines the handler for storage-related operations