From d7aff545521c3ec78c932d491e880ccd42c3a149 Mon Sep 17 00:00:00 2001 From: skye Date: Mon, 24 Apr 2023 12:37:15 +0300 Subject: [PATCH] feat: flake.nix for api, improved dev-launch.sh --- api/dev-launch.sh | 40 +++++++++++++++++++--- api/flake.lock | 85 +++++++++++++++++++++++++++++++++++++++++++++++ api/flake.nix | 31 +++++++++++++++++ 3 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 api/flake.lock create mode 100644 api/flake.nix diff --git a/api/dev-launch.sh b/api/dev-launch.sh index 45e1cb6..8091e1c 100755 --- a/api/dev-launch.sh +++ b/api/dev-launch.sh @@ -17,9 +17,41 @@ function confirm() { return 1 } -confirm reset containers? && docker compose down -confirm reset database? && docker volume rm laurelinapi_apidb_data +function docker() { + confirm reset containers? && docker compose down + confirm reset database? && docker volume rm laurelinapi_apidb_data -confirm rebuild api? && docker compose build + confirm rebuild api? && docker compose build + + confirm launch? && docker compose up +} + +function nixenv() { + nix develop +} + +function nixsetup() { + export PGDATA=/tmp/laurelinpgdata + initdb + pg_ctl -o "-k /tmp" start + createdb -h /tmp laurelinapi + + export GIN_MODE=release # or "debug" for debug logs + export LAURELINAPI_JWT_SECRET=XpNYdG7vgvgPPuezrtZqt4CJIUuxNP7c + export GORM_DB_STRING="host=localhost dbname=laurelinapi port=5432 sslmode=disable" + + go run main.go +} + +if confirm nix? +then + if confirm "in devshell?" + then + nixsetup + else + nixenv + fi +else + docker +fi -confirm launch? && docker compose up diff --git a/api/flake.lock b/api/flake.lock new file mode 100644 index 0000000..749ca97 --- /dev/null +++ b/api/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": [ + "flake-utils" + ] + }, + "locked": { + "lastModified": 1677459247, + "narHash": "sha256-JbakfAiPYmCCV224yAMq/XO0udN5coWv/oazblMKdoY=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "3cbf3a51fe32e2f57af4c52744e7228bab22983d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1682173319, + "narHash": "sha256-tPhOpJJ+wrWIusvGgIB2+x6ILfDkEgQMX0BTtM5vd/4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ee7ec1c71adc47d2e3c2d5eb0d6b8fbbd42a8d1c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "gomod2nix": "gomod2nix", + "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", + "version": 7 +} diff --git a/api/flake.nix b/api/flake.nix new file mode 100644 index 0000000..d9b1a4e --- /dev/null +++ b/api/flake.nix @@ -0,0 +1,31 @@ +{ + description = "Laurelin API"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; + flake-utils.url = "github:numtide/flake-utils"; + gomod2nix = { + url = "github:nix-community/gomod2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.utils.follows = "flake-utils"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, gomod2nix }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ gomod2nix.overlays.default ]; + }; + in { + devShell = with pkgs; pkgs.mkShell { + buildInputs = [ + go + gopls + + postgresql + ]; + }; + }); +} -- 2.44.1