Learning-HTMX/18-expenses-chart/flake.nix

81 lines
2.5 KiB
Nix

rec {
description = "expenses chart exercise";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
templ.url = "github:a-h/templ";
};
outputs = { self, nixpkgs, flake-utils, templ }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
templPkg = templ.packages.${system}.templ;
pname = "expenses-chart";
version = "0.0.1";
in rec {
thePackage = pkgs.buildGoModule {
inherit pname version;
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
vendorHash = "sha256-sKuP3TsRD3MXBGtdSRnX62eXBQE1ASWFQu0kLlXSlFA=";
preBuild = ''
# Adding the Tailwind build step to preBuild
${pkgs.nodePackages.tailwindcss}/bin/tailwindcss -i ./input.css -o static/output.css
# Adding generation of go code from templ files
${templPkg}/bin/templ generate
'';
};
packages = rec {
"${pname}" = thePackage;
"${pname}-image" = pkgs.dockerTools.buildLayeredImage {
name = pname;
tag = "latest";
created = "now";
config = {
Cmd = [ "${thePackage}/bin/templ-exercise" ];
ExposedPorts = { "3000/tcp" = { }; };
};
};
image-hello = pkgs.dockerTools.buildLayeredImage { # so, wow, this works
name = pname;
tag = "latest";
config.Cmd = [ "${pkgs.hello}/bin/hello" ];
};
image = pkgs.dockerTools.buildImage {
name = pname;
tag = "latest";
created = "now";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [ thePackage pkgs.dockerTools.binSh pkgs.coreutils ];
pathsToLink = [ "/bin" "/dist" "/public" ];
};
config = {
Cmd = [ "/bin/templ-exercise" ];
ExposedPorts = { "8080/tcp" = { }; };
};
};
};
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.go
pkgs.wgo
pkgs.semgrep
pkgs.gopls
pkgs.gnumake
templPkg
pkgs.nodePackages.tailwindcss
];
shellHook = ''
export GOPATH=$PWD/.go
export PATH=$GOPATH/bin:$PATH
'';
};
});
# see https://serokell.io/blog/practical-nix-flakes
}