nix: expose overlay and NixOS module for infrastructure deployment
- Fix default.nix to build from workspace (imphnen-backend/Cargo.toml) - Add overlays.default adding pkgs.imphnen-backend - Add nixosModules.backend via nixos-module.nix - NixOS module defines systemd service on port 8081 with environmentFile Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e432a1a743
commit
30128a8fe2
+16
-15
@@ -1,15 +1,16 @@
|
|||||||
{pkgs ? import <nixpkgs> {}}: let
|
{ pkgs ? import <nixpkgs> { } }:
|
||||||
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
|
pkgs.rustPlatform.buildRustPackage {
|
||||||
rustDeps = pkgs.callPackage ./Cargo.nix {};
|
pname = "imphnen-backend";
|
||||||
packageEntry = rustDeps.workspaceMembers.${manifest.name};
|
version = (pkgs.lib.importTOML ./imphnen-backend/Cargo.toml).package.version;
|
||||||
deps = packageEntry.build.cargoDeps or null;
|
src = pkgs.lib.cleanSource ./.;
|
||||||
in
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
pkgs.rustPlatform.buildRustPackage {
|
cargoBuildFlags = [
|
||||||
pname = manifest.name;
|
"--package"
|
||||||
version = manifest.version;
|
"imphnen-backend"
|
||||||
cargoDeps = deps;
|
"--bin"
|
||||||
src = pkgs.lib.cleanSource ./.;
|
"api"
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
];
|
||||||
nativeBuildInputs = [pkgs.openssl pkgs.pkg-config];
|
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||||
buildInputs = [pkgs.openssl];
|
buildInputs = [ pkgs.openssl ];
|
||||||
}
|
doCheck = false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,9 +21,7 @@
|
|||||||
system:
|
system:
|
||||||
import nixpkgs {
|
import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
config = {
|
config.allowUnfree = true;
|
||||||
allowUnfree = true;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||||
in
|
in
|
||||||
@@ -31,9 +29,17 @@
|
|||||||
packages = forAllSystems (system: {
|
packages = forAllSystems (system: {
|
||||||
default = (pkgsFor system).callPackage ./default.nix { };
|
default = (pkgsFor system).callPackage ./default.nix { };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
overlays.default = final: _prev: {
|
||||||
|
imphnen-backend = final.callPackage ./default.nix { };
|
||||||
|
};
|
||||||
|
|
||||||
|
nixosModules.backend = ./nixos-module.nix;
|
||||||
|
|
||||||
devShells = forAllSystems (system: {
|
devShells = forAllSystems (system: {
|
||||||
default = (pkgsFor system).callPackage ./shell.nix { };
|
default = (pkgsFor system).callPackage ./shell.nix { };
|
||||||
});
|
});
|
||||||
|
|
||||||
dockerImages = forAllSystems (system: {
|
dockerImages = forAllSystems (system: {
|
||||||
tryOutApi = (pkgsFor system).callPackage ./docker.nix { };
|
tryOutApi = (pkgsFor system).callPackage ./docker.nix { };
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.imphnen-backend;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.services.imphnen-backend = {
|
||||||
|
enable = lib.mkEnableOption "IMPHNEN backend service";
|
||||||
|
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 8081;
|
||||||
|
description = "Port the backend HTTP server listens on.";
|
||||||
|
};
|
||||||
|
|
||||||
|
environmentFile = lib.mkOption {
|
||||||
|
type = lib.types.path;
|
||||||
|
description = "Path to environment file with secrets (DATABASE_URL, JWT keys, etc).";
|
||||||
|
};
|
||||||
|
|
||||||
|
openFirewall = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
systemd.services.imphnen-backend = {
|
||||||
|
description = "IMPHNEN Backend Service";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [
|
||||||
|
"network.target"
|
||||||
|
"postgresql.service"
|
||||||
|
];
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${pkgs.imphnen-backend}/bin/api";
|
||||||
|
EnvironmentFile = cfg.environmentFile;
|
||||||
|
Environment = [ "PORT=${toString cfg.port}" ];
|
||||||
|
DynamicUser = true;
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = "5s";
|
||||||
|
StandardOutput = "journal";
|
||||||
|
StandardError = "journal";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user