feat: nix build enabled

nix build
will put binary into nix store, and symlink to ./result
running with
./result/bin/auth-pocketbase-attempt serve --dir=./pb_data

if i understood migrations correctly, when using as a framework
migrations will be generated as go files, and will be packaged into the binary
This commit is contained in:
efim 2023-10-08 07:20:48 +00:00
parent 769fe603c7
commit 4a64f2186f
4 changed files with 136 additions and 19 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ tmp/
.direnv
pb_data
pages/static/public/out.css
result

View File

@ -90,9 +90,66 @@ and i guess i could also search online for tailwindcss Makefile examples and tip
** DONE package static into single binary
i guess already done?
** TODO write nix build
** DONE write nix build
and it should be even easier with a Makefile?
https://ryantm.github.io/nixpkgs/stdenv/stdenv/
simple stdenv.mkDerivation calls generic builder which uses Makefile
now i have a problem with using go build in a homeless-shelter
> failed to initialize build cache at /homeless-shelter/.cache/go-build: mkdir /homeless-shelter: permission denied
*** well, especially with go.mod dependencies i'd need to use buildGoModule
but
[efim@chunky:~/Documents/personal/go-learning/auth-pocketbase-attempt]$ ./result/bin/auth-pocketbase-attempt serve
2023/10/07 04:05:56 mkdir result/bin/pb_data: read-only file system
so, i need to pass some place in tmp? this is probably pocketbase settings, hopefully as command line argument
https://nixos.org/manual/nixpkgs/stable/#sec-language-go
https://nixos.wiki/wiki/Go
so, if i call executable from somewhere, it looks for pb_data in current directory
but then for some reason
[efim@chunky:~/Documents/personal/go-learning/auth-pocketbase-attempt]$ ./result/bin/auth-pocketbase-attempt serve
2023/10/08 06:37:19 mkdir result/bin/pb_data: read-only file system
here it tries to init pb_data near the binary
this works:
[efim@chunky:~/Documents/personal/go-learning/auth-pocketbase-attempt]$ ./result/bin/auth-pocketbase-attempt serve --dir=./pb_data
*** oh, i don't need to specify location of migrations.
because they are static. and should be just present in the nix store
and --dir is already built in. nice
well, i don't see any pb_migrations in my project directory even though,
i'm creating and updating the table
maybe it's all in pb_data now?
if now - i'll need to add something like
#+begin_src nix
postBuild = ''
cp pb_migration $out/bin/pb_migration
'';
#+end_src
*** so, if using as framework migrations are not automatically enabled?
https://github.com/pocketbase/pocketbase/discussions/2218
https://pocketbase.io/docs/go-migrations/#enable-go-migrations
The prebuilt executable enables the migrate command by default, but when you are extending PocketBase with Go you have to enable it manually
*** now `nix build` produces the binary capable to run the site
and
#+begin_src bash
./result/bin/auth-pocketbase-attempt serve --dir=./pb_data
#+end_src
is what i need for it to pick up pb_data from work directory, cool
** TODO write nixos module
need to pass data and migration location as params
** TODO add docker image from nix
*** TODO add cli for port and host
** TODO add readme and comments
@ -102,3 +159,9 @@ can it be configured on render.com?
** TODO get icons for the auth providers. surely they are accessible from the pocketbase itself?
http://localhost:8090/_/images/oauth2/apple.svg
yes.
** TODO figure out and enbale migrations
https://pocketbase.io/docs/go-migrations/#enable-go-migrations
if i understood correctly, when i enable migration generation
i would be able to modify locally run instance via admin interface,
go files with migration would be generated, i'll have to import them somewhere in my main module, and then after building/packaging when i run `serve` on production the migrations would run on the production data

View File

@ -1,5 +1,23 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1695806987,
@ -16,8 +34,24 @@
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -1,9 +1,15 @@
{
description = "going to look at the pocketbase apis";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs }: {
devShell.x86_64-linux = let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in pkgs.mkShell {
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pname = "auth-pocketbase-attempt";
version = "0.0.1";
in rec {
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.go
pkgs.wgo # for restart of project
@ -19,5 +25,18 @@
export PATH=$GOPATH/bin:$PATH
'';
};
packages = rec {
auth-pocketbase-attempt = pkgs.buildGoModule {
inherit pname version;
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
vendorHash = "sha256-7B5EkrLpL+P5wipQG5a12hrvXQn/UpYAjrz/DuHmSUQ="; # set to "" when get dependencies in go.mod
# Adding the Tailwind build step to preBuild
preBuild = ''
${pkgs.nodePackages.tailwindcss}/bin/tailwindcss -i pages/input.css -o pages/static/public/out.css
'';
};
default = auth-pocketbase-attempt;
};
});
}