Build with nix

This also switches from the hacky vendor.sh script to managing the
dependencies with nix.
This commit is contained in:
Simon Bruder 2021-11-30 19:17:20 +01:00
parent 418d55ee17
commit 21ffb24003
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
5 changed files with 87 additions and 53 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@
/static/episodes/* /static/episodes/*
/static/vendor/ /static/vendor/
/vendor/ /vendor/
/result*

View file

@ -46,7 +46,7 @@ def get_episode_info(name, format):
return json.loads( return json.loads(
run( run(
[ [
"./vendor/ffprobe", "ffprobe",
"-loglevel", "-loglevel",
"error", "error",
"-show_format", "-show_format",

View file

@ -66,7 +66,7 @@ def encode_episode(podcast, episode, format):
) )
ffmpeg_chapters += f"title={escaped_title}\n\n".encode("utf-8") ffmpeg_chapters += f"title={escaped_title}\n\n".encode("utf-8")
command = ["./vendor/ffmpeg", "-y", "-loglevel", "error"] command = ["ffmpeg", "-y", "-loglevel", "error"]
command.extend(["-i", infile]) command.extend(["-i", infile])
if not format in ["oga", "opus"]: if not format in ["oga", "opus"]:
command.extend(["-i", episode["poster"]]) command.extend(["-i", episode["poster"]])

104
flake.nix
View file

@ -4,25 +4,89 @@
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem
let (system:
pkgs = import nixpkgs { inherit system; }; let
in pkgs = import nixpkgs { inherit system; config.allowUnfree = true; };
rec { in
devShell = pkgs.mkShell { rec {
buildInputs = with pkgs; [ packages = {
nixops bulma = pkgs.fetchzip {
python38 url = "https://github.com/jgthms/bulma/releases/download/0.9.0/bulma-0.9.0.zip";
python38Packages.mutagen sha256 = "sha256-FKWdkq6pRukCzR2IQ88OHlPkIJbeeEz7NdIWv44k8TM=";
zola };
unzip
wget
];
shellHook = '' podlove-subscribe-button = pkgs.fetchzip {
export NIXOPS_DEPLOYMENT=schulischer-schabernack-hcloud url = "https://github.com/podlove/podlove-subscribe-button/releases/download/v17/podlove-subscribe-button-v17.zip";
export NIX_PATH=nixpkgs=${nixpkgs} sha256 = "sha256-N+lxzDpw2mNOg0i+pOFuvwNMi5Q7rZK4H9WEzf5/1us=";
''; stripRoot = false;
}; };
});
podlove-web-player = pkgs.fetchzip {
url = "https://registry.npmjs.org/@podlove/web-player/-/web-player-4.5.13.tgz";
sha256 = "sha256-U7REkg0FwBaMO25M4lHRRWcNNhgZPPjx/AR48usPqCU=";
};
schulischer-schabernack = pkgs.callPackage
({ stdenv
, ffmpeg-full
, python3
, zola
}:
let
linkVendor = ''
mkdir -p vendor static/vendor
ln -sfT ${packages.bulma} vendor/bulma
# !!! XXX hack
# copying is required at least with interactive shell, because zola does not copy symlinks to output directory
# to keep it up to date, it is removed before that
rm -rf static/vendor/{podlove-subscribe-button,podlove-web-player}
cp --reflink=auto --no-preserve=mode,ownership -rf ${packages.podlove-subscribe-button} static/vendor/podlove-subscribe-button
cp --reflink=auto --no-preserve=mode,ownership -rf ${packages.podlove-web-player} static/vendor/podlove-web-player
'';
in
stdenv.mkDerivation {
name = "schulischer-schabernack";
src = self;
nativeBuildInputs = [
(ffmpeg-full.override { nonfreeLicensing = true; fdkaacExtlib = true; })
(python3.withPackages (ps: with ps; [ mutagen ]))
zola
];
postPatch = ''
patchShebangs .
'';
configurePhase = ''
runHook preConfigure
${linkVendor}
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
./build.sh
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -r public $out
runHook postInstall
'';
shellHook = ''
${linkVendor}
export NIXOPS_DEPLOYMENT=schulischer-schabernack-hcloud
export NIX_PATH=nixpkgs=${nixpkgs}
'';
})
{ };
};
defaultPackage = packages.schulischer-schabernack;
});
} }

View file

@ -1,31 +0,0 @@
#!/bin/sh
set -e
mkdir -p vendor
cd vendor
rm -rf bulma
wget -nv -O bulma.zip "https://github.com/jgthms/bulma/releases/download/0.9.0/bulma-0.9.0.zip"
unzip -q bulma.zip
rm bulma.zip
mv bulma-* bulma
wget -Nnv \
"https://sbruder-cdn.s3.eu-central-1.wasabisys.com/ffmpeg-fdk/ffmpeg" \
"https://sbruder-cdn.s3.eu-central-1.wasabisys.com/ffmpeg-fdk/ffprobe"
sha512sum -c << EOF
29cc5a88d508781fc34ccafa8292c8505395c8a3a2231f71a49f5553176994f2118217f248ba03593464ee6e63c72e8bb1c630779fdac4a3e97925a4aca27836 ffmpeg
bbe17d8b9489c0b5155c57fdc4fe4d7635d57ae98da9767229070210ab41099c4f2af50b42ad5a3283a75605ac9972c93bf8b6cdb00cf2333cc2adfd943ce5f0 ffprobe
EOF
chmod +x ffmpeg ffprobe
mkdir -p ../static/vendor/
cd ../static/vendor/
rm -rf podlove-web-player
mkdir podlove-web-player
wget -nv -O- "https://registry.npmjs.org/@podlove/web-player/-/web-player-4.5.13.tgz" | tar xzf - --strip-components=1 -C podlove-web-player
rm -rf podlove-subscribe-button
wget -nv -O podlove-subscribe-button.zip "https://github.com/podlove/podlove-subscribe-button/releases/download/v17/podlove-subscribe-button-v17.zip"
unzip -q -d podlove-subscribe-button podlove-subscribe-button.zip
rm podlove-subscribe-button.zip