154
flake.nix
154
flake.nix
@@ -2,85 +2,97 @@
|
|||||||
description = "A simple pastebin service";
|
description = "A simple pastebin service";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { nixpkgs, flake-utils, ... }@inputs:
|
outputs =
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
{ nixpkgs, flake-utils, ... }@inputs:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages = rec {
|
packages = rec {
|
||||||
slenpaste = pkgs.buildGoModule {
|
slenpaste = pkgs.buildGoModule {
|
||||||
pname = "slenpaste";
|
pname = "slenpaste";
|
||||||
version = "0.1.3";
|
version = "0.1.4";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
goPackagePath = "github.com/slendidev/slenpaste";
|
goPackagePath = "github.com/slendidev/slenpaste";
|
||||||
vendorHash = "sha256-MUvodL6K71SCfxu51T/Ka2/w32Kz+IXem1bYqXQLSaU=";
|
vendorHash = "sha256-MUvodL6K71SCfxu51T/Ka2/w32Kz+IXem1bYqXQLSaU=";
|
||||||
};
|
};
|
||||||
default = slenpaste;
|
default = slenpaste;
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
buildInputs = [ pkgs.go pkgs.gopls ];
|
buildInputs = [
|
||||||
};
|
pkgs.go
|
||||||
|
pkgs.gopls
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
nixosModules.slenpaste = { lib, pkgs, config, ... }: {
|
nixosModules.slenpaste =
|
||||||
# module function
|
{
|
||||||
options.services.slenpaste.enable = lib.mkEnableOption "Enable slenpaste service";
|
lib,
|
||||||
options.services.slenpaste.domain = lib.mkOption {
|
pkgs,
|
||||||
type = lib.types.str;
|
config,
|
||||||
default = "localhost";
|
...
|
||||||
description = "Domain to serve pastes from";
|
}:
|
||||||
};
|
{
|
||||||
options.services.slenpaste.listen = lib.mkOption {
|
# module function
|
||||||
type = lib.types.str;
|
options.services.slenpaste.enable = lib.mkEnableOption "Enable slenpaste service";
|
||||||
default = "0.0.0.0:8080";
|
options.services.slenpaste.domain = lib.mkOption {
|
||||||
description = "Listen address (host:port)";
|
type = lib.types.str;
|
||||||
};
|
default = "localhost";
|
||||||
options.services.slenpaste.staticDir = lib.mkOption {
|
description = "Domain to serve pastes from";
|
||||||
type = lib.types.str;
|
};
|
||||||
default = "/var/lib/slenpaste";
|
options.services.slenpaste.listen = lib.mkOption {
|
||||||
description = "Directory which contains the actual paste data";
|
type = lib.types.str;
|
||||||
};
|
default = "0.0.0.0:8080";
|
||||||
options.services.slenpaste.expireDur = lib.mkOption {
|
description = "Listen address (host:port)";
|
||||||
type = lib.types.str;
|
};
|
||||||
default = "0";
|
options.services.slenpaste.staticDir = lib.mkOption {
|
||||||
description = "Expiry duration (Go syntax, e.g. \"5m\", \"1h\" or \"0\" for none)";
|
type = lib.types.str;
|
||||||
};
|
default = "/var/lib/slenpaste";
|
||||||
options.services.slenpaste.expireOnView = lib.mkOption {
|
description = "Directory which contains the actual paste data";
|
||||||
type = lib.types.bool;
|
};
|
||||||
default = false;
|
options.services.slenpaste.expireDur = lib.mkOption {
|
||||||
description = "Whether to expire on first view";
|
type = lib.types.str;
|
||||||
};
|
default = "0";
|
||||||
options.services.slenpaste.https = lib.mkOption {
|
description = "Expiry duration (Go syntax, e.g. \"5m\", \"1h\" or \"0\" for none)";
|
||||||
type = lib.types.bool;
|
};
|
||||||
default = false;
|
options.services.slenpaste.expireOnView = lib.mkOption {
|
||||||
description = "Whether to use https:// in generated URLs";
|
type = lib.types.bool;
|
||||||
};
|
default = false;
|
||||||
|
description = "Whether to expire on first view";
|
||||||
|
};
|
||||||
|
options.services.slenpaste.https = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Whether to use https:// in generated URLs";
|
||||||
|
};
|
||||||
|
|
||||||
config = lib.mkIf config.services.slenpaste.enable {
|
config = lib.mkIf config.services.slenpaste.enable {
|
||||||
systemd.services.slenpaste = {
|
systemd.services.slenpaste = {
|
||||||
description = "slenpaste HTTP paste service";
|
description = "slenpaste HTTP paste service";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
wants = [ "network.target" ];
|
wants = [ "network.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = ''
|
ExecStart = ''
|
||||||
${inputs.self.packages.${system}.slenpaste}/bin/slenpaste \
|
${inputs.self.packages.${system}.slenpaste}/bin/slenpaste \
|
||||||
-domain "${config.services.slenpaste.domain}" \
|
-domain "${config.services.slenpaste.domain}" \
|
||||||
-listen "${config.services.slenpaste.listen}" \
|
-listen "${config.services.slenpaste.listen}" \
|
||||||
-expire "${config.services.slenpaste.expireDur}" \
|
-expire "${config.services.slenpaste.expireDur}" \
|
||||||
${lib.optionalString config.services.slenpaste.expireOnView "-expire-on-view=false"}
|
${lib.optionalString config.services.slenpaste.expireOnView "-expire-on-view=false"}
|
||||||
${lib.optionalString config.services.slenpaste.https "-https"}
|
${lib.optionalString config.services.slenpaste.https "-https"}
|
||||||
'';
|
'';
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
};
|
};
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
13
main.go
13
main.go
@@ -69,16 +69,21 @@ func randomID(n int) string {
|
|||||||
|
|
||||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Content-Type", "text/html")
|
w.Header().Add("Content-Type", "text/html")
|
||||||
|
scheme := "http"
|
||||||
|
if useHTTPS {
|
||||||
|
scheme = "https"
|
||||||
|
}
|
||||||
|
d := fmt.Sprintf("%s://%s", scheme, domain)
|
||||||
fmt.Fprintf(w, `<html><body><pre>Welcome to slenpaste!
|
fmt.Fprintf(w, `<html><body><pre>Welcome to slenpaste!
|
||||||
|
|
||||||
Upload a file:
|
Upload a file:
|
||||||
curl -F 'file=@yourfile.txt' -F 'expiry=1h' http://%s/
|
curl -F 'file=@yourfile.txt' -F 'expiry=1h' %s/
|
||||||
|
|
||||||
Upload from stdin (no file param, expire after 5m):
|
Upload from stdin (no file param, expire after 5m):
|
||||||
curl --data-binary @- http://%s/?expiry=5m < yourfile.txt
|
curl --data-binary @- %s/?expiry=5m < yourfile.txt
|
||||||
|
|
||||||
Upload from stdin and expire on first view:
|
Upload from stdin and expire on first view:
|
||||||
cat yourfile.txt | curl --data-binary @- "http://%s/?expiry=view"
|
cat yourfile.txt | curl --data-binary @- "%s/?expiry=view"
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
<form enctype="multipart/form-data" method="post">
|
<form enctype="multipart/form-data" method="post">
|
||||||
@@ -95,7 +100,7 @@ Upload from stdin and expire on first view:
|
|||||||
|
|
||||||
<input type="submit" value="Upload">
|
<input type="submit" value="Upload">
|
||||||
</form>
|
</form>
|
||||||
</body></html>`, domain, domain, domain)
|
</body></html>`, d, d, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user