feat(15): nix installation & image
This commit is contained in:
parent
01ec722ea0
commit
080b47a9a6
|
@ -0,0 +1 @@
|
|||
use flake
|
|
@ -0,0 +1,101 @@
|
|||
{ pkgs, lib, sbt-derivation }:
|
||||
|
||||
let
|
||||
pname = "multi-step-form";
|
||||
package = sbt-derivation.lib.mkSbtDerivation {
|
||||
inherit pkgs pname;
|
||||
# ...and the rest of the arguments
|
||||
version = "0.0.1";
|
||||
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
|
||||
nativeBuildInputs = [ pkgs.nodePackages.tailwindcss ];
|
||||
buildPhase = ''
|
||||
tailwindcss -i ./src/input.css -o ./src/main/resources/public/output.css
|
||||
sbt assembly
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp target/scala-*/${pname}-assembly-*.jar $out/bin/${pname}.jar
|
||||
'';
|
||||
|
||||
depsSha256 = "sha256-Y5RktcE3fxUJci4o7LTuNlBEybTdVRqsG551AkVeRPw=";
|
||||
};
|
||||
|
||||
module = { config, pkgs, ... }:
|
||||
let cfg = config.services.${pname};
|
||||
in {
|
||||
options.services.${pname} = {
|
||||
enable = lib.mkEnableOption "My frontendmentor exercise ${pname}";
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 8080;
|
||||
description = "Port to listen on.";
|
||||
};
|
||||
|
||||
host = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "localhost";
|
||||
description = "Host to bind to.";
|
||||
};
|
||||
|
||||
useNginx = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Whether to use Nginx to proxy requests.";
|
||||
};
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
users.groups."${pname}-group" = { };
|
||||
users.users."${pname}-user" = {
|
||||
isSystemUser = true;
|
||||
group = "${pname}-group";
|
||||
};
|
||||
|
||||
systemd.services.${pname} =
|
||||
let serverHost = if cfg.useNginx then "localhost" else cfg.host;
|
||||
in {
|
||||
description = "Exercise app ${pname}";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
startLimitIntervalSec = 30;
|
||||
startLimitBurst = 10;
|
||||
serviceConfig = {
|
||||
ExecStart =
|
||||
"${pkgs.jdk}/bin/java -jar ${package}/bin/${pname}.jar -p ${
|
||||
toString cfg.port
|
||||
} --host ${serverHost}";
|
||||
WorkingDirectory = "${package}/bin";
|
||||
Restart = "on-failure";
|
||||
User = "${pname}-user";
|
||||
Group = "${pname}-group";
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx = lib.mkIf cfg.useNginx {
|
||||
virtualHosts.${cfg.host} = {
|
||||
locations."/".proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
image = pkgs.dockerTools.buildLayeredImage {
|
||||
name = pname;
|
||||
tag = "latest";
|
||||
created = "now";
|
||||
config = {
|
||||
Cmd = [ "${pkgs.jdk}/bin/java" "-jar" "${package}/bin/${pname}.jar" "--host" "0.0.0.0" ];
|
||||
ExposedPorts = {
|
||||
"8080/tcp" = {};
|
||||
};
|
||||
};
|
||||
};
|
||||
# image = pkgs.dockerTools.buildLayeredImage { # so, wow, this works
|
||||
# name = "hello2";
|
||||
# tag = "latest";
|
||||
# config.Cmd = [ "${pkgs.hello}/bin/hello" ];
|
||||
# };
|
||||
in {
|
||||
package = package;
|
||||
module = module;
|
||||
image = image;
|
||||
}
|
|
@ -28,6 +28,10 @@
|
|||
inherit pkgs sbt-derivation;
|
||||
lib = pkgs.lib;
|
||||
};
|
||||
multi-step-form = import ./15-multi-step-form/default.nix {
|
||||
inherit pkgs sbt-derivation;
|
||||
lib = pkgs.lib;
|
||||
};
|
||||
in {
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
|
@ -51,6 +55,9 @@
|
|||
packages.rock-paper-scissors = rock-paper-scissors.package;
|
||||
packages.rock-paper-scissors-image = rock-paper-scissors.image;
|
||||
nixosModules.rock-paper-scissors = rock-paper-scissors.module;
|
||||
packages.multi-step-form = multi-step-form.package;
|
||||
packages.multi-step-form-image = multi-step-form.image;
|
||||
nixosModules.multi-step-form = multi-step-form.module;
|
||||
});
|
||||
# see https://serokell.io/blog/practical-nix-flakes
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue