Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] :: Use Nix to generate Docker Image and Dev Environment #1485

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IMAGE_NAME=Change_me
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0="

use devenv
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ e2e/playwright-report/
e2e/playwright/.cache/
/backend/build_info/version.txt
/backend/dist
# Devenv
.devenv*
devenv.local.nix

# direnv
.direnv

# pre-commit
.pre-commit-config.yaml
.env
210 changes: 210 additions & 0 deletions devenv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1717698746,
"owner": "cachix",
"repo": "devenv",
"rev": "866ecadab5d92cdbb296723f67fa464d01401d9a",
"treeHash": "9d43a86d5c69469287da4740c8627624e9b7076c",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"treeHash": "2addb7b71a20a25ea74feeaf5c2f6a6b30898ecb",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"treeHash": "bd263f021e345cb4a39d80c126ab650bebc3c10c",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"treeHash": "ca14199cabdfe1a06a7b1654c76ed49100a689f9",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"go_1_20_revision": {
"locked": {
"lastModified": 1708814358,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3",
"treeHash": "277a62f1f87f693e5e82230315ea9d814ae55561",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3",
"type": "github"
}
},
"mk-shell-bin": {
"locked": {
"lastModified": 1677004959,
"owner": "rrbutani",
"repo": "nix-mk-shell-bin",
"rev": "ff5d8bd4d68a347be5042e2f16caee391cd75887",
"treeHash": "496327dabdc787353a29987f492dd4939151baad",
"type": "github"
},
"original": {
"owner": "rrbutani",
"repo": "nix-mk-shell-bin",
"type": "github"
}
},
"nix2container": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1712990762,
"owner": "nlewo",
"repo": "nix2container",
"rev": "20aad300c925639d5d6cbe30013c8357ce9f2a2e",
"treeHash": "f9359d4b4e79c4e798a3018ae0ce3cb4317d4612",
"type": "github"
},
"original": {
"owner": "nlewo",
"repo": "nix2container",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1716977621,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
"treeHash": "6d9f1f7ca0faf1bc2eeb397c78a49623260d3412",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1717530100,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a2e1d0414259a144ebdc048408a807e69e0565af",
"treeHash": "d1a59f4c20789566e0ef4b5471521a4fc58963a1",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1717664902,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "cc4d466cb1254af050ff7bdf47f6d404a7c646d1",
"treeHash": "def977583217aad11744d144c1f7fc216ce450bf",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"go_1_20_revision": "go_1_20_revision",
"mk-shell-bin": "mk-shell-bin",
"nix2container": "nix2container",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"treeHash": "cce81f2a0f0743b2eb61bc2eb6c7adbe2f2c6beb",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
31 changes: 31 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ pkgs, lib, config, inputs, ... }:
let
goPkgs = pkgs.callPackage inputs.go_1_20_revision { };
in
{
dotenv.enable = true;
dotenv.filename = ".env";

name = "hanko";

packages = [
goPkgs.go_1_20
pkgs.git
pkgs.nixpacks
];

enterShell = ''
if [[ ! -f .env ]]; then
cp .env.template .env
echo "Created a new .env file from .env.example"
fi
'';

scripts = {
build_image.exec = ''
nixpacks build ./backend \
--name ${config.env.IMAGE_NAME}
'';
build_push_image.exec = "build_image && docker push ${config.env.IMAGE_NAME}";
};
}
12 changes: 12 additions & 0 deletions devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
inputs:
nix2container:
url: github:nlewo/nix2container
inputs:
nixpkgs:
follows: nixpkgs
mk-shell-bin:
url: github:rrbutani/nix-mk-shell-bin
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
go_1_20_revision:
url: github:NixOS/nixpkgs?rev=336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3
6 changes: 6 additions & 0 deletions nixpacks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[phases.setup]
nixpkgsArchive = '336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3'
nixPkgs = [ "go_1_20" ]

[phases.build]
cmd = "go generate ./... && CGO_ENABLED=0 GOOS=linux GOARCH='$TARGETARCH' go build -a -o hanko main.go"