switch to flakes, add a module

This commit is contained in:
Aaron Bieber 2024-03-28 10:02:01 -06:00
parent 5a5b512557
commit d41b55e44c
No known key found for this signature in database
6 changed files with 149 additions and 13 deletions

2
.envrc
View File

@ -1 +1 @@
use_nix use flake

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ db/*
mcchunkie mcchunkie
deploy.sh deploy.sh
*.core *.core
.direnv

26
flake.lock generated Normal file
View File

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1711523803,
"narHash": "sha256-UKcYiHWHQynzj6CN/vTcix4yd1eCu1uFdsuarupdCQQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2726f127c15a4cc9810843b96cad73c7eb39e443",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

54
flake.nix Normal file
View File

@ -0,0 +1,54 @@
{
description = "mcchunkie: a chat bot";
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
outputs =
{ self
, nixpkgs
,
}:
let
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in
{
overlay = _: prev: { inherit (self.packages.${prev.system}) mcchunkie; };
nixosModule = import ./module.nix;
packages = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
in
{
mcchunkie = pkgs.buildGoModule rec {
pname = "mcchunkie";
version = "v1.0.15";
src = ./.;
vendorHash = "sha256-LMWaHqmvxG17Z0zh0vmTAYDsc9UkztSCM1+jl2iXSds=";
# makes outbound http requests
doCheck = false;
ldflags = [ "-X suah.dev/mcchunkie/plugins.version=${version}" ];
};
});
defaultPackage = forAllSystems (system: self.packages.${system}.mcchunkie);
devShells = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
in
{
default = pkgs.mkShell {
shellHook = ''
PS1='\u@\h:\@; '
nix run github:qbit/xin#flake-warn
echo "Go `${pkgs.go}/bin/go version`"
'';
nativeBuildInputs = with pkgs; [ git go gopls go-tools ];
};
});
};
}

67
module.nix Normal file
View File

@ -0,0 +1,67 @@
{ lib, config, pkgs, ... }:
let cfg = config.services.mcchunkie;
in {
options = with lib; {
services.mcchunkie = {
enable = lib.mkEnableOption "Enable mcchunkie";
user = mkOption {
type = with types; oneOf [ str int ];
default = "mcchunkie";
description = ''
The user the service will use.
'';
};
group = mkOption {
type = with types; oneOf [ str int ];
default = "mcchunkie";
description = ''
The group the service will use.
'';
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/mcchunkie";
description = "Path mcchunkie will use to store data";
};
package = mkOption {
type = types.package;
default = pkgs.mcchunkie;
defaultText = literalExpression "pkgs.mcchunkie";
description = "The package to use for mcchunkie";
};
};
};
config = lib.mkIf (cfg.enable) {
users.groups.${cfg.group} = { };
users.users.${cfg.user} = {
description = "mcchunkie service user";
isSystemUser = true;
home = "${cfg.dataDir}";
createHome = true;
group = "${cfg.group}";
};
systemd.services.mcchunkie = {
enable = true;
description = "mcchunkie server";
wantedBy = [ "network-online.target" ];
after = [ "network-online.target" ];
environment = { HOME = "${cfg.dataDir}"; };
serviceConfig = {
User = cfg.user;
Group = cfg.group;
ExecStart = ''
${cfg.package}/bin/mcchunkie
'';
};
};
};
}

View File

@ -1,12 +0,0 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
shellHook = ''
export NO_COLOR=true
export PS1="\u@\h:\w; "
'';
nativeBuildInputs = with pkgs.buildPackages; [
go
go-tools
];
}