flake: add nixosModule

This commit is contained in:
xeals 2022-11-02 10:48:50 +11:00
parent c3831e9efe
commit 74051f3afc
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C
2 changed files with 81 additions and 0 deletions

View File

@ -15,6 +15,11 @@
};
})
];
nixosModules = rec {
default = frontpage;
frontpage = import ./nixos;
};
} // (flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; }; in
{

76
nixos/default.nix Normal file
View File

@ -0,0 +1,76 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.frontpage;
toml = pkgs.formats.toml { };
fullSettings = recursiveUpdate cfg.settings {
core.port = cfg.port;
oidc.client_secret = "@SECRET@";
};
settingsFile = toml.generate "config.toml" fullSettings;
in
{
options.services.frontpage = {
enable = mkEnableOption "frontpage";
package = mkPackageOption pkgs "frontpage" { };
user = mkOption {
type = types.str;
default = "frontpage";
};
group = mkOption {
type = types.str;
default = "frontpage";
};
port = mkOption {
type = types.port;
default = 32195;
};
oidcSecretFile = mkOption {
type = types.path;
description = ''
Path to a file containing the OIDC secret for the application.
'';
};
settings = mkOption {
type = with types; attrsOf anything;
default = { };
description = ''
Settings attribute set as described by the documentation.
'';
};
};
config = mkIf cfg.enable {
systemd.services.frontpage = {
description = "Web front page";
wantedBy = [ "multi-user.target" ];
preStart = ''
sed \
"s=@SECRET@=$(<${cfg.oidcSecretFile})=" \
${settingsFile} \
> /run/frontpage/config.toml
'';
serviceConfig = {
Restart = "on-failure";
RestartSec = "2s";
ExecStart = "${cfg.package}/bin/frontpage -c /run/frontpage/config.toml";
RuntimeDirectory = [ "frontpage" ];
User = cfg.user;
};
};
users.users."${cfg.user}" = {
isSystemUser = true;
group = cfg.group;
};
users.groups."${cfg.group}" = { };
};
}