149 lines
4.0 KiB
Nix
149 lines
4.0 KiB
Nix
{
|
|
description = "A very basic flake";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
|
};
|
|
|
|
inputs.utils.url = "github:numtide/flake-utils";
|
|
|
|
outputs = { self, nixpkgs, utils, ... }:
|
|
|
|
nixpkgs.lib.attrsets.recursiveUpdate
|
|
(utils.lib.eachSystem (utils.lib.defaultSystems) ( system:
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
in rec
|
|
{
|
|
devShells.default = pkgs.mkShell {
|
|
packages = with pkgs; [
|
|
go
|
|
gotools
|
|
tailwindcss_4
|
|
];
|
|
};
|
|
|
|
packages.portal = nixpkgs.legacyPackages.x86_64-linux.buildGoModule {
|
|
pname = "portal";
|
|
version = "1.0";
|
|
vendorHash = "sha256-CNOsrFvkg+6LvWmrIoNwLj7+7JJi4q2J+8Rf6EqNr0Y=";
|
|
src = ./.;
|
|
|
|
postInstall = ''
|
|
cp -r views $out/
|
|
cp -r static $out/
|
|
'';
|
|
};
|
|
|
|
packages.default = packages.portal;
|
|
|
|
checks = let
|
|
checkArgs = {
|
|
pkgs = pkgs;
|
|
inherit self;
|
|
};
|
|
in {
|
|
portal = import ./test/test.nix checkArgs;
|
|
};
|
|
|
|
})) {
|
|
|
|
nixosModules.portal = { config, lib, pkgs, ... }:
|
|
let
|
|
cfg = config.services.portal;
|
|
portal-pkg = self.packages.x86_64-linux.portal;
|
|
in
|
|
{
|
|
options = {
|
|
services.portal = {
|
|
enable = lib.mkOption {
|
|
default = false;
|
|
type = lib.types.bool;
|
|
description = lib.mdDoc ''
|
|
Enables portal
|
|
'';
|
|
};
|
|
gatekeeperHost = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = lib.mDoc ''
|
|
gatekeeper host addr
|
|
'';
|
|
};
|
|
|
|
gatekeeperScheme = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = lib.mDoc ''
|
|
http or https
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
environment.systemPackages = [
|
|
portal-pkg
|
|
];
|
|
|
|
systemd.tmpfiles.rules = [
|
|
"d '/var/lib/portal' 0750 portal portal - -"
|
|
"d '/var/lib/portal/views' 0750 portal portal - -"
|
|
"d '/var/lib/portal/static' 0750 portal portal - -"
|
|
"d '/var/lib/portal/static/uploads' 0750 portal portal - -"
|
|
"z '/var/lib/portal' 0750 portal portal - -"
|
|
"z '/var/lib/portal/views' 0750 portal portal - -"
|
|
"z '/var/lib/portal/static' 0750 portal portal - -"
|
|
"z '/var/lib/portal/static/uploads' 0750 portal portal - -"
|
|
];
|
|
|
|
users = {
|
|
groups.portal = {};
|
|
users.portal = {
|
|
description = "portal user";
|
|
group = "portal";
|
|
isNormalUser = true;
|
|
};
|
|
};
|
|
|
|
systemd.services.portal = {
|
|
description = "portal daemon";
|
|
serviceConfig = {
|
|
Type = "simple";
|
|
WorkingDirectory = "/var/lib/portal";
|
|
ExecStart = pkgs.writeScript "start-portal" ''
|
|
#! ${pkgs.bash}/bin/bash
|
|
PATH="$PATH:${lib.makeBinPath [ pkgs.poppler-utils pkgs.cups pkgs.imagemagick ]}"
|
|
${portal-pkg}/bin/portal
|
|
'';
|
|
Restart = "on-failure";
|
|
};
|
|
|
|
environment = {
|
|
SQLITE_DB = "/var/lib/portal/portal.db";
|
|
PORT = "8080";
|
|
STATIC = "/var/lib/portal/static";
|
|
VIEWS = "/var/lib/portal/views";
|
|
GATEKEEPER_HOST = "${cfg.gatekeeperHost}";
|
|
GATEKEEPER_SCHEME = "${cfg.gatekeeperScheme}";
|
|
};
|
|
|
|
preStart = ''
|
|
mkdir -m 0770 -p "/var/lib/portal"
|
|
cp -r ${portal-pkg}/views /var/lib/portal/
|
|
cp -r ${portal-pkg}/static /var/lib/portal/
|
|
chown portal:portal "/var/lib/portal"
|
|
'';
|
|
|
|
wantedBy = [ "default.target" ];
|
|
|
|
environment = {
|
|
USER = "portal";
|
|
HOME = "/var/lib/portal";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
};
|
|
}
|
|
|