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;
|
||||
in {
|
||||
defaultPackage = pkgs.buildGoModule {
|
||||
packages = {
|
||||
default = pkgs.buildGoModule {
|
||||
pname = "web-server";
|
||||
inherit version;
|
||||
src = ./.;
|
||||
|
@ -38,9 +39,7 @@
|
|||
vendorSha256 = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
|
||||
};
|
||||
|
||||
packages = {
|
||||
docker = let
|
||||
web = self.defaultPackage.${system};
|
||||
docker = let web = self.packages.${system}.default;
|
||||
in pkgs.dockerTools.buildLayeredImage {
|
||||
name = web.pname;
|
||||
tag = web.version;
|
||||
|
@ -55,10 +54,9 @@
|
|||
web-service = pkgs.substituteAll {
|
||||
name = "web-server.service";
|
||||
src = ./systemd/web-server.service.in;
|
||||
web = self.defaultPackage.${system};
|
||||
web = self.packages.${system}.default;
|
||||
};
|
||||
portable = let
|
||||
web = self.defaultPackage.${system};
|
||||
portable = let web = self.packages.${system}.default;
|
||||
in pkgs.portableService {
|
||||
inherit (web) version;
|
||||
name = web.pname;
|
||||
|
@ -67,11 +65,50 @@
|
|||
};
|
||||
};
|
||||
|
||||
defaultApp = utils.lib.mkApp {
|
||||
drv = self.defaultPackage.${system};
|
||||
nixosModule = { config, lib, pkgs, ... }:
|
||||
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 ];
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue