DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

d7aff545521c3ec78c932d491e880ccd42c3a149 — skye 1 year, 8 months ago 7b4ac4a
feat: flake.nix for api, improved dev-launch.sh
3 files changed, 152 insertions(+), 4 deletions(-)

M api/dev-launch.sh
A api/flake.lock
A api/flake.nix
M api/dev-launch.sh => api/dev-launch.sh +36 -4
@@ 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

A api/flake.lock => api/flake.lock +85 -0
@@ 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
}

A api/flake.nix => api/flake.nix +31 -0
@@ 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
      ];
    };
  });
}