add nixos module and overlay

This commit is contained in:
Aaron Bieber 2023-01-10 18:30:48 -07:00
parent 0f70db9ead
commit ec6a0c2000
No known key found for this signature in database
3 changed files with 99 additions and 3 deletions

View File

@ -10,12 +10,16 @@
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in {
overlay = final: prev: {
pots = self.packages.${prev.system}.pots;
};
nixosModule = import ./module.nix;
packages = forAllSystems (system:
let pkgs = nixpkgsFor.${system};
in {
pots = pkgs.buildGoModule {
pname = "pots";
version = "v0.0.1";
version = "v0.0.2";
src = ./.;
vendorHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
};

View File

@ -132,7 +132,8 @@ func (apiHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
func main() {
listen := flag.String("listen", ":8888", "listen string")
port := flag.Int("port", 8888, "port to listen on")
ip := flag.String("ip", "127.0.0.1", "ip to listen on")
flag.Parse()
mux := http.NewServeMux()
@ -147,7 +148,7 @@ func main() {
})
s := &http.Server{
Addr: *listen,
Addr: fmt.Sprintf("%s:%d", *ip, *port),
Handler: mux,
}

91
module.nix Normal file
View File

@ -0,0 +1,91 @@
{ lib, config, pkgs, inputs, ... }:
let cfg = config.services.pots;
in {
options = with lib; {
services.pots = {
enable = lib.mkEnableOption "Enable pots";
port = mkOption {
type = types.int;
default = 8888;
description = ''
Port to listen on string.
'';
};
user = mkOption {
type = with types; oneOf [ str int ];
default = "pots";
description = ''
The user the service will use.
'';
};
group = mkOption {
type = with types; oneOf [ str int ];
default = "pots";
description = ''
The group the service will use.
'';
};
keyPath = mkOption {
type = types.path;
default = "";
description = ''
Path to the GitHub API key file
'';
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/pots";
description = "Path pots home directory";
};
package = mkOption {
type = types.package;
default = pkgs.pots;
defaultText = literalExpression "pkgs.pots";
description = "The package to use for pots";
};
envFile = mkOption {
type = types.path;
default = "/run/secrets/pots_env_file";
description = ''
Path to a file containing the pots token information
'';
};
};
};
config = lib.mkIf (cfg.enable) {
users.groups.${cfg.group} = { };
users.users.${cfg.user} = {
description = "pots service user";
isSystemUser = true;
home = "${cfg.dataDir}";
createHome = true;
group = "${cfg.group}";
};
systemd.services.pots = {
enable = true;
description = "pots server";
wantedBy = [ "network-online.target" ];
after = [ "network-online.target" ];
environment = { HOME = "${cfg.dataDir}"; };
serviceConfig = {
User = cfg.user;
Group = cfg.group;
ExecStart =
"${cfg.package}/bin/pots -port ${cfg.port}";
EnvironmentFile = cfg.envFile;
};
};
};
}