.
This commit is contained in:
parent
38a5c47dab
commit
af358f9326
5 changed files with 116 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -21,6 +21,8 @@
|
||||||
# Whitelist nix
|
# Whitelist nix
|
||||||
!flake.nix
|
!flake.nix
|
||||||
!flake.lock
|
!flake.lock
|
||||||
|
!default.nix
|
||||||
|
!module.nix
|
||||||
|
|
||||||
# Whitelist database
|
# Whitelist database
|
||||||
!*.sqlite
|
!*.sqlite
|
||||||
|
|
|
||||||
18
default.nix
Normal file
18
default.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
{ lib, buildGoModule }:
|
||||||
|
|
||||||
|
buildGoModule {
|
||||||
|
pname = "henna";
|
||||||
|
version = "0.1.0";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
vendorHash = null;
|
||||||
|
|
||||||
|
CGO_ENABLED = 1;
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "Henna gallery server";
|
||||||
|
license = licenses.mit;
|
||||||
|
maintainers = [ ];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,9 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils }:
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
{
|
||||||
|
nixosModules.default = import ./module.nix;
|
||||||
|
} // flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in
|
in
|
||||||
|
|
|
||||||
9
main.go
9
main.go
|
|
@ -34,6 +34,8 @@ var (
|
||||||
imaginaryURL string
|
imaginaryURL string
|
||||||
galleryPath string
|
galleryPath string
|
||||||
databasePath string
|
databasePath string
|
||||||
|
listenAddr string
|
||||||
|
listenPort int
|
||||||
randomCovers []CoverData
|
randomCovers []CoverData
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -41,6 +43,8 @@ func main() {
|
||||||
flag.StringVar(&imaginaryURL, "imaginary", "http://192.168.88.54:10001", "imaginary root URL")
|
flag.StringVar(&imaginaryURL, "imaginary", "http://192.168.88.54:10001", "imaginary root URL")
|
||||||
flag.StringVar(&galleryPath, "gallery", "/home/user/mnt/panda/galleries/", "gallery path")
|
flag.StringVar(&galleryPath, "gallery", "/home/user/mnt/panda/galleries/", "gallery path")
|
||||||
flag.StringVar(&databasePath, "database", "./db.sqlite", "database path")
|
flag.StringVar(&databasePath, "database", "./db.sqlite", "database path")
|
||||||
|
flag.StringVar(&listenAddr, "address", "localhost", "listen address")
|
||||||
|
flag.IntVar(&listenPort, "port", 10000, "listen port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -68,8 +72,9 @@ func main() {
|
||||||
http.Handle("/assets/", http.FileServer(http.FS(assetsFS)))
|
http.Handle("/assets/", http.FileServer(http.FS(assetsFS)))
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(galleryPath))))
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(galleryPath))))
|
||||||
|
|
||||||
log.Println("Server listening on :8080")
|
addr := fmt.Sprintf("%s:%d", listenAddr, listenPort)
|
||||||
log.Fatal(http.ListenAndServe(":10000", nil))
|
log.Printf("Server listening on %s", addr)
|
||||||
|
log.Fatal(http.ListenAndServe(addr, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRandom(w http.ResponseWriter, r *http.Request) {
|
func handleRandom(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
86
module.nix
Normal file
86
module.nix
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.henna;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.services.henna = {
|
||||||
|
enable = lib.mkEnableOption "Henna gallery server";
|
||||||
|
|
||||||
|
package = lib.mkOption {
|
||||||
|
type = lib.types.package;
|
||||||
|
default = pkgs.callPackage ./default.nix { };
|
||||||
|
description = "The henna package to use.";
|
||||||
|
};
|
||||||
|
|
||||||
|
imaginaryUrl = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = "Imaginary server root URL.";
|
||||||
|
};
|
||||||
|
|
||||||
|
galleryPath = lib.mkOption {
|
||||||
|
type = lib.types.path;
|
||||||
|
description = "Path to the gallery directory.";
|
||||||
|
};
|
||||||
|
|
||||||
|
databasePath = lib.mkOption {
|
||||||
|
type = lib.types.path;
|
||||||
|
default = ./db.sqlite;
|
||||||
|
description = "Path to the SQLite database file.";
|
||||||
|
};
|
||||||
|
|
||||||
|
address = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "localhost";
|
||||||
|
description = "Address to listen on.";
|
||||||
|
};
|
||||||
|
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 10000;
|
||||||
|
description = "Port to listen on.";
|
||||||
|
};
|
||||||
|
|
||||||
|
user = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "henna";
|
||||||
|
description = "User to run henna as.";
|
||||||
|
};
|
||||||
|
|
||||||
|
group = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "henna";
|
||||||
|
description = "Group to run henna as.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
users.users.${cfg.user} = {
|
||||||
|
isSystemUser = true;
|
||||||
|
group = cfg.group;
|
||||||
|
};
|
||||||
|
|
||||||
|
users.groups.${cfg.group} = { };
|
||||||
|
|
||||||
|
systemd.services.henna = {
|
||||||
|
description = "Henna gallery server";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "network.target" ];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = ''
|
||||||
|
${cfg.package}/bin/henna \
|
||||||
|
-imaginary "${cfg.imaginaryUrl}" \
|
||||||
|
-gallery "${cfg.galleryPath}" \
|
||||||
|
-database "${cfg.databasePath}" \
|
||||||
|
-address "${cfg.address}" \
|
||||||
|
-port ${toString cfg.port}
|
||||||
|
'';
|
||||||
|
User = cfg.user;
|
||||||
|
Group = cfg.group;
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = 5;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue