add basic nixos module
Signed-off-by: Xe <me@christine.website>
This commit is contained in:
parent
1e692d6117
commit
042bc8b53c
57
flake.nix
57
flake.nix
|
@ -21,7 +21,8 @@
|
||||||
};
|
};
|
||||||
version = builtins.substring 0 8 self.lastModifiedDate;
|
version = builtins.substring 0 8 self.lastModifiedDate;
|
||||||
in {
|
in {
|
||||||
defaultPackage = pkgs.buildGoModule {
|
packages = {
|
||||||
|
default = pkgs.buildGoModule {
|
||||||
pname = "web-server";
|
pname = "web-server";
|
||||||
inherit version;
|
inherit version;
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
@ -38,9 +39,7 @@
|
||||||
vendorSha256 = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
|
vendorSha256 = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
|
||||||
};
|
};
|
||||||
|
|
||||||
packages = {
|
docker = let web = self.packages.${system}.default;
|
||||||
docker = let
|
|
||||||
web = self.defaultPackage.${system};
|
|
||||||
in pkgs.dockerTools.buildLayeredImage {
|
in pkgs.dockerTools.buildLayeredImage {
|
||||||
name = web.pname;
|
name = web.pname;
|
||||||
tag = web.version;
|
tag = web.version;
|
||||||
|
@ -55,10 +54,9 @@
|
||||||
web-service = pkgs.substituteAll {
|
web-service = pkgs.substituteAll {
|
||||||
name = "web-server.service";
|
name = "web-server.service";
|
||||||
src = ./systemd/web-server.service.in;
|
src = ./systemd/web-server.service.in;
|
||||||
web = self.defaultPackage.${system};
|
web = self.packages.${system}.default;
|
||||||
};
|
};
|
||||||
portable = let
|
portable = let web = self.packages.${system}.default;
|
||||||
web = self.defaultPackage.${system};
|
|
||||||
in pkgs.portableService {
|
in pkgs.portableService {
|
||||||
inherit (web) version;
|
inherit (web) version;
|
||||||
name = web.pname;
|
name = web.pname;
|
||||||
|
@ -67,11 +65,50 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
defaultApp = utils.lib.mkApp {
|
nixosModule = { config, lib, pkgs, ... }:
|
||||||
drv = self.defaultPackage.${system};
|
with lib;
|
||||||
|
let cfg = config.xeserv.services.gohello-http;
|
||||||
|
in {
|
||||||
|
options.xeserv.services.gohello-http = {
|
||||||
|
enable = mkEnableOption "Enables the gohello HTTP service";
|
||||||
|
|
||||||
|
domain = mkOption rec {
|
||||||
|
type = types.str;
|
||||||
|
default = "gohello.local.cetacean.club";
|
||||||
|
example = default;
|
||||||
|
description = "The domain name for gohello";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
devShell = pkgs.mkShell {
|
config = mkIf cfg.enable {
|
||||||
|
systemd.services."xeserv.gohello" = {
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
|
serviceConfig = let pkg = self.packages.${system}.default;
|
||||||
|
in {
|
||||||
|
Restart = "on-failure";
|
||||||
|
ExecStart = "${pkg}/bin/web-server";
|
||||||
|
DynamicUser = "yes";
|
||||||
|
RuntimeDirectory = "xeserv.gohello";
|
||||||
|
RuntimeDirectoryMode = "0755";
|
||||||
|
StateDirectory = "xeserv.gohello";
|
||||||
|
StateDirectoryMode = "0700";
|
||||||
|
CacheDirectory = "xeserv.gohello";
|
||||||
|
CacheDirectoryMode = "0750";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.nginx.virtualHosts.${cfg.domain} = {
|
||||||
|
locations."/" = {
|
||||||
|
proxyPass = "http://127.0.0.1:3031";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultApp = utils.lib.mkApp { drv = self.defaultPackage.${system}; };
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
buildInputs = with pkgs; [ go gopls goimports go-tools ];
|
buildInputs = with pkgs; [ go gopls goimports go-tools ];
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue