Skip to content

Commit

Permalink
NixOS module: static files
Browse files Browse the repository at this point in the history
Provided as NixOS config option and custom systemd unit directive.

Add a default param for git_version to make it work when the .git dir is
missing, for example when using the Github tarball.

static_files.nix uses the version from pyproject.toml as default.
  • Loading branch information
dpausp committed Mar 16, 2021
1 parent be8257c commit 03ad0b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
25 changes: 16 additions & 9 deletions nix/git_version.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{ pkgs }:
{ pkgs, default ? "unknown" }:

with builtins;
with pkgs;

lib.replaceStrings
["\n"]
[""]
(lib.readFile
(runCommand
"git-version"
{ src = ../.; buildInputs = [ gitMinimal ]; }
"cd $src; git describe --long --tags --dirty --always > $out"))
let
gitVersion =
lib.replaceStrings
["\n"]
[""]
(lib.readFile
(runCommand
"git-version"
{ src = ../.; buildInputs = [ gitMinimal ]; }
"cd $src; git describe --long --tags --dirty --always > $out"));
in
if pathExists ../.git
then gitVersion
else default
8 changes: 8 additions & 0 deletions nix/modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ in {
default = null;
};

staticFiles = mkOption {
internal = true;
type = with types; nullOr path;
default = null;
};

browserSessionSecretKeyFile = mkOption {
type = types.str;
description = "Path to file containing the secret key for browser session signing";
Expand Down Expand Up @@ -101,6 +107,7 @@ in {
config = lib.mkIf cfg.enable {

services.ekklesia.portal.configFile = configInput;
services.ekklesia.portal.staticFiles = staticFiles;

environment.systemPackages = [ ekklesiaPortalConfig ekklesiaPortalShowConfig ];

Expand Down Expand Up @@ -146,6 +153,7 @@ in {
Restart = "always";
X-ConfigFile = configInput;
X-ServeApp = serveApp;
X-StaticFiles = staticFiles;

DeviceAllow = [
"/dev/stderr"
Expand Down
6 changes: 4 additions & 2 deletions nix/static_files.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
with builtins;

{ sources ? null }:
let
deps = import ./deps.nix { inherit sources; };
inherit (deps) lib pkgs sassc javascriptDeps webfontsPath sassPath deform python;
version = import ./git_version.nix { inherit pkgs; };
inherit (deps) lib pkgs sassc javascriptDeps webfontsPath sassPath deform python pyProject;
version = import ./git_version.nix { inherit pkgs; default = pyProject.tool.poetry.version; };

in
pkgs.runCommand "ekklesia-portal-static-${version}" {
Expand Down

0 comments on commit 03ad0b5

Please sign in to comment.