-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
result |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ | ||
inputs = { | ||
naersk.url = "github:nix-community/naersk/master"; | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | ||
utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, utils, naersk }: | ||
utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = import nixpkgs { inherit system; }; | ||
naersk-lib = pkgs.callPackage naersk { }; | ||
in | ||
{ | ||
defaultPackage = naersk-lib.buildPackage ./.; | ||
devShell = with pkgs; mkShell { | ||
buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ]; | ||
RUST_SRC_PATH = rustPlatform.rustLibSrc; | ||
}; | ||
|
||
nixosModules.default = { config, lib, pkgs, ... }: | ||
with lib; | ||
let | ||
cfg = config.services.paste-bin; | ||
in | ||
{ | ||
options.services.paste-bin = { | ||
enable = mkEnableOption "paste-bin"; | ||
bindAddress = mkOption { | ||
default = "[::]:8000"; | ||
description = "Address and port to listen on"; | ||
type = types.str; | ||
}; | ||
maxPasteSize = mkOption { | ||
default = 32768; | ||
description = "Max allowed size of an individual paste"; | ||
type = types.int; | ||
}; | ||
bufferSize = mkOption { | ||
default = 1000; | ||
description = "Maximum amount of pastes to store at a time"; | ||
type = types.int; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
systemd.services.bin = { | ||
enable = true; | ||
wantedBy = [ "multi-user.target" ]; | ||
after = [ "network-online.target" ]; | ||
serviceConfig = { | ||
Type = "exec"; | ||
ExecStart = "${self.defaultPackage."${system}"}/bin/bin --buffer-size ${toString cfg.bufferSize} --max-paste-size ${toString cfg.maxPasteSize} ${cfg.bindAddress}"; | ||
Restart = "on-failure"; | ||
|
||
CapabilityBoundingSet = ""; | ||
NoNewPrivileges = true; | ||
PrivateDevices = true; | ||
PrivateTmp = true; | ||
PrivateUsers = true; | ||
PrivateMounts = true; | ||
ProtectHome = true; | ||
ProtectClock = true; | ||
ProtectProc = "noaccess"; | ||
ProcSubset = "pid"; | ||
ProtectKernelLogs = true; | ||
ProtectKernelModules = true; | ||
ProtectKernelTunables = true; | ||
ProtectControlGroups = true; | ||
ProtectHostname = true; | ||
RestrictSUIDSGID = true; | ||
RestrictRealtime = true; | ||
RestrictNamespaces = true; | ||
LockPersonality = true; | ||
RemoveIPC = true; | ||
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ]; | ||
SystemCallFilter = [ "@system-service" "~@privileged" ]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}); | ||
} |