nix: added module & package for tinyupload
This commit is contained in:
parent
c423174110
commit
9b10fde29d
3 changed files with 102 additions and 26 deletions
|
|
@ -16,13 +16,13 @@
|
||||||
in {
|
in {
|
||||||
# Define a package for your project
|
# Define a package for your project
|
||||||
packages = forEachSystem (system: pkgs: rec {
|
packages = forEachSystem (system: pkgs: rec {
|
||||||
tinyupload = pkgs.callPackage ./nix/package.nix {
|
tinyupload = pkgs.callPackage ./nix/package.nix {};
|
||||||
inherit pkgs;
|
|
||||||
};
|
|
||||||
|
|
||||||
default = tinyupload;
|
default = tinyupload;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
nixosModules.default = import ./nix/module.nix self;
|
||||||
|
|
||||||
devShells = forEachSystem (system: pkgs: {
|
devShells = forEachSystem (system: pkgs: {
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
DATABASE_URL = "sqlite:tinyupload.db";
|
DATABASE_URL = "sqlite:tinyupload.db";
|
||||||
|
|
|
||||||
95
nix/module.nix
Normal file
95
nix/module.nix
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
# Untested, but should be the majority of what is needed.
|
||||||
|
self: {
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (lib.options) mkEnableOption mkOption;
|
||||||
|
inherit (lib.types) str path port int;
|
||||||
|
inherit (lib.modules) mkIf;
|
||||||
|
|
||||||
|
cfg = config.services.tinyupload;
|
||||||
|
in {
|
||||||
|
options.services.tinyupload = {
|
||||||
|
enable = mkEnableOption "Enable tinyupload.";
|
||||||
|
|
||||||
|
address = mkOption {
|
||||||
|
type = str;
|
||||||
|
default = "127.0.0.1";
|
||||||
|
description = "Address on which tinyupload will listen on";
|
||||||
|
};
|
||||||
|
|
||||||
|
port = mkOption {
|
||||||
|
type = port;
|
||||||
|
default = 8080;
|
||||||
|
description = "Port on which the tinyupload service will listen";
|
||||||
|
};
|
||||||
|
|
||||||
|
uploadLimit = mkOption {
|
||||||
|
type = int;
|
||||||
|
default = 100;
|
||||||
|
description = "Upload limit for tinyupload in MB";
|
||||||
|
};
|
||||||
|
|
||||||
|
title = mkOption {
|
||||||
|
type = str;
|
||||||
|
default = "tinyupload";
|
||||||
|
description = "Title for the frontend of tinyupload";
|
||||||
|
};
|
||||||
|
|
||||||
|
dataDir = mkOption {
|
||||||
|
type = path;
|
||||||
|
default = "/var/lib/tinyupload";
|
||||||
|
description = "Directory to store uploaded files and database";
|
||||||
|
};
|
||||||
|
|
||||||
|
user = mkOption {
|
||||||
|
type = str;
|
||||||
|
default = "tinyupload";
|
||||||
|
description = "User account under which the service will run";
|
||||||
|
};
|
||||||
|
|
||||||
|
group = mkOption {
|
||||||
|
type = str;
|
||||||
|
default = "tinyupload";
|
||||||
|
description = "Group under which the service will run";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
users.users.${cfg.user} = {
|
||||||
|
isSystemUser = true;
|
||||||
|
group = cfg.group;
|
||||||
|
home = cfg.dataDir;
|
||||||
|
createHome = true;
|
||||||
|
description = "tinyupload service user";
|
||||||
|
};
|
||||||
|
|
||||||
|
users.groups.${cfg.group} = {};
|
||||||
|
|
||||||
|
systemd.services.tinyupload = {
|
||||||
|
description = "tinyupload service";
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
after = ["network.target"];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
RestartSec = 5;
|
||||||
|
User = cfg.user;
|
||||||
|
Group = cfg.group;
|
||||||
|
WorkingDirectory = cfg.dataDir;
|
||||||
|
Restart = "on-failure";
|
||||||
|
ExecStart = "${(pkgs.writeShellApplication {
|
||||||
|
name = "start-tinyupload";
|
||||||
|
text = ''
|
||||||
|
${self.packages.${pkgs.system}.tinyupload}/bin/tinyupload \
|
||||||
|
-u ${toString cfg.uploadLimit} \
|
||||||
|
-a "${cfg.address}:${toString cfg.port}" \
|
||||||
|
-t "${cfg.title}" \
|
||||||
|
serve
|
||||||
|
'';
|
||||||
|
})}/bin/start-tinyupload";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -1,26 +1,7 @@
|
||||||
{
|
{rustPlatform, ...}:
|
||||||
stdenv,
|
rustPlatform.buildRustPackage {
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
stdenv.mkDerivation {
|
|
||||||
pname = "tinyupload";
|
pname = "tinyupload";
|
||||||
version = "1.0.0";
|
version = "0.2.0";
|
||||||
|
|
||||||
src = ../.;
|
src = ../.;
|
||||||
|
cargoHash = "sha256-nfrci/E/ZSVfPLEUIKBRgCGkxH2p7WgnwDBHwOsUnCw=";
|
||||||
buildInputs = [pkgs.cargo];
|
|
||||||
|
|
||||||
# Specify the build commands
|
|
||||||
buildPhase = ''
|
|
||||||
cargo build --release
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Optionally, specify installPhase if needed
|
|
||||||
installPhase = ''
|
|
||||||
# If you have specific install steps, add them here
|
|
||||||
# For example, copying files to $out
|
|
||||||
mkdir -p $out/bin
|
|
||||||
cp target/release/tinyupload $out/bin
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue