From 21ffb2400315fe3f2f5f41b8f43acded796ae0b3 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Tue, 30 Nov 2021 19:17:20 +0100 Subject: [PATCH] Build with nix This also switches from the hacky vendor.sh script to managing the dependencies with nix. --- .gitignore | 1 + common.py | 2 +- encode.py | 2 +- flake.nix | 104 ++++++++++++++++++++++++++++++++++++++++++----------- vendor.sh | 31 ---------------- 5 files changed, 87 insertions(+), 53 deletions(-) delete mode 100755 vendor.sh diff --git a/.gitignore b/.gitignore index b3c0b4f..af5aa22 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /static/episodes/* /static/vendor/ /vendor/ +/result* diff --git a/common.py b/common.py index 47a8be0..dce768c 100644 --- a/common.py +++ b/common.py @@ -46,7 +46,7 @@ def get_episode_info(name, format): return json.loads( run( [ - "./vendor/ffprobe", + "ffprobe", "-loglevel", "error", "-show_format", diff --git a/encode.py b/encode.py index 065a807..bf9ae86 100755 --- a/encode.py +++ b/encode.py @@ -66,7 +66,7 @@ def encode_episode(podcast, episode, format): ) 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]) if not format in ["oga", "opus"]: command.extend(["-i", episode["poster"]]) diff --git a/flake.nix b/flake.nix index 63b2673..24e3f58 100644 --- a/flake.nix +++ b/flake.nix @@ -4,25 +4,89 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; }; - in - rec { - devShell = pkgs.mkShell { - buildInputs = with pkgs; [ - nixops - python38 - python38Packages.mutagen - zola - unzip - wget - ]; + outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }; + in + rec { + packages = { + bulma = pkgs.fetchzip { + url = "https://github.com/jgthms/bulma/releases/download/0.9.0/bulma-0.9.0.zip"; + sha256 = "sha256-FKWdkq6pRukCzR2IQ88OHlPkIJbeeEz7NdIWv44k8TM="; + }; - shellHook = '' - export NIXOPS_DEPLOYMENT=schulischer-schabernack-hcloud - export NIX_PATH=nixpkgs=${nixpkgs} - ''; - }; - }); + podlove-subscribe-button = pkgs.fetchzip { + url = "https://github.com/podlove/podlove-subscribe-button/releases/download/v17/podlove-subscribe-button-v17.zip"; + 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; + }); } diff --git a/vendor.sh b/vendor.sh deleted file mode 100755 index 7ff5100..0000000 --- a/vendor.sh +++ /dev/null @@ -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