Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flake for NixOS servers support #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; };

outputs = { nixpkgs, ... }@inputs: {
nixosModules = { default = import ./nix; };
};
}
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ ... }: { imports = [ ./options.nix ./piped.nix ]; }
48 changes: 48 additions & 0 deletions nix/options.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ lib, ... }:

{
options = with lib; {
piped = {
enable = mkOption {
description = "Enable the piped service";
type = types.bool;
default = false;
};

# Config for configure-instance.sh
frontend = mkOption {
description = "Hostname for the Frontend (eg: piped.kavin.rocks)";
type = types.str;
};
backend = mkOption {
description = "Hostname for the Backend (eg: pipedapi.kavin.rocks)";
type = types.str;
};
proxy = mkOption {
description = "Hostname for the Proxy (eg: pipedproxy.kavin.rocks)";
type = types.str;
};
reverseproxy = mkOption {
description = "Reverse proxy you would like to use (either caddy or nginx)";
type = types.str;
};

# Additional Config
dataDir = mkOption {
description = "The path for data storage";
type = types.str;
default = "/var/lib/piped";
};
httpPort = mkOption {
description = "The port to listen for HTTP conenctions";
type = types.int;
default = 80;
};
httpsPort = mkOption {
description = "The port to listen for HTTPS conenctions";
type = types.int;
default = 443;
};
};
};
}
27 changes: 27 additions & 0 deletions nix/piped-package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ stdenvNoCC, bash, pipedConfig }:

stdenvNoCC.mkDerivation rec {
name = "piped";

src = ../template;
installer = ../configure-instance.sh;

preferLocalBuild = true;

installPhase = ''
mkdir -p "$out/template"
cp -r . "$out/template"
cd "$out"
${bash}/bin/bash ${installer} <<<$(
echo ${pipedConfig.frontend}
echo ${pipedConfig.backend}
echo ${pipedConfig.proxy}
echo ${pipedConfig.reverseproxy}
)
rm -rf $out/template

sed "s|80:|${builtins.toString pipedConfig.httpPort}:|g" -i docker-compose.yml
sed "s|443:|${builtins.toString pipedConfig.httpsPort}:|g" -i docker-compose.yml
sed "s|\./data|${pipedConfig.dataDir}|g" -i docker-compose.yml
'';
}
19 changes: 19 additions & 0 deletions nix/piped.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ config, lib, pkgs, ... }:

let
pipedPackage = pkgs.callPackage ./piped-package.nix { pipedConfig = config.piped; };
in lib.mkIf config.piped.enable {
virtualisation.docker.enable = true;
systemd.services.piped = {
enable = true;
serviceConfig = {
WorkingDirectory = pipedPackage;
preStart = "${pkgs.docker-compose}/bin/docker-compose pull";
ExecStart = "${pkgs.docker-compose}/bin/docker-compose up";
ExecStop = "${pkgs.docker-compose}/bin/docker-compose down";
};
environment.COMPOSE_PROJECT_NAME = "piped-flake";
after = [ "docker.service" "docker.socket" ];
wantedBy = [ "multi-user.target" ];
};
}