Skip to content

Commit dd493ff

Browse files
committed
feat: Add nix support
Build `audible-cli` via nix _including_ all plugins! Added necessary code to create an AppImage for Linux + docker images via nix. Also add GitHub action logic to check whether the package continues to build via nix, including the AppImage and docker image. Currently limiting support to Linux x86, as this is the only local machine.
1 parent b3adb9a commit dd493ff

7 files changed

Lines changed: 453 additions & 0 deletions

File tree

.github/workflows/nix.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Nix-Test
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
id-token: write
13+
steps:
14+
- uses: DeterminateSystems/nix-installer-action@main
15+
- uses: DeterminateSystems/magic-nix-cache-action@main
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Run `nix fmt`
19+
run: nix fmt -- --check *
20+
- name: Run `flake checks`
21+
run: nix flake check -L
22+
- name: Create AppImage
23+
run: nix build .#audible-cli-AppImage
24+
- name: Test appimage
25+
run: ./result decrypt --help
26+
- name: Rename AppImage
27+
if: startsWith(github.ref, 'refs/tags/')
28+
run: cp ./result audible-cli.AppImage
29+
- name: Release-AppImage
30+
uses: softprops/action-gh-release@v2
31+
if: startsWith(github.ref, 'refs/tags/')
32+
with:
33+
files: audible-cli.AppImage
34+
# FUTURE: Push the docker container to an image registry
35+
# see: https://github.com/containers/skopeo
36+
# and usage in: https://github.com/seanrmurphy/nix-container-build-gha/blob/main/scripts/build_and_push_image.sh

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
/src/audible_cli/*.bak
44
library.csv
55

6+
result
7+
*.AppImage
8+
69
# Byte-compiled / optimized / DLL files
710
__pycache__/
811
*.py[cod]

flake.lock

Lines changed: 175 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
description = "Nix related tooling for a command line interface for audible. With the CLI you can download your Audible books, cover, chapter files & conver them.";
3+
inputs = {
4+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
5+
systems.url = "github:nix-systems/x86_64-linux";
6+
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
7+
nix-filter.url = "github:numtide/nix-filter";
8+
nix-appimage = {
9+
url = "github:ralismark/nix-appimage";
10+
};
11+
};
12+
outputs = {
13+
self,
14+
nixpkgs,
15+
systems,
16+
nix-appimage,
17+
flake-compat,
18+
nix-filter,
19+
} @ inputs: let
20+
eachSystem = nixpkgs.lib.genAttrs (import systems);
21+
pkgsFor = eachSystem (system: (nixpkgs.legacyPackages.${system}.extend self.overlays.default));
22+
in {
23+
formatter = eachSystem (system: pkgsFor.${system}.alejandra);
24+
checks = eachSystem (system: self.packages.${system});
25+
overlays = import ./nix/overlays.nix {
26+
inherit inputs;
27+
lib = nixpkgs.lib; # TODO: Understand this construct
28+
};
29+
30+
packages = eachSystem (system: let
31+
pkgs = pkgsFor.${system};
32+
in rec {
33+
audible-cli = pkgs.audible-cli;
34+
audible-cli-full = pkgs.audible-cli-full;
35+
isbntools = pkgs.python3Packages.isbntools;
36+
audible-cli-AppImage = inputs.nix-appimage.mkappimage.${system} {
37+
drv = audible-cli-full;
38+
name = audible-cli-full.name;
39+
entrypoint = pkgs.lib.getExe audible-cli-full;
40+
};
41+
audible-cli-docker = pkgs.dockerTools.buildLayeredImage {
42+
name = audible-cli-full.pname; # `.name` has illegal docker tag format
43+
tag = "latest";
44+
contents = audible-cli-full;
45+
};
46+
default = audible-cli-full;
47+
});
48+
};
49+
}

nix/default.nix

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
lib,
3+
nix-filter,
4+
python3Packages,
5+
ffmpeg_7-headless,
6+
enable-plugin-decrypt ? true,
7+
enable-plugin-goodreads-transform ? true,
8+
enable-plugin-annotations ? true,
9+
enable-plugin-image-urls ? true,
10+
enable-plugin-listening-stats ? true,
11+
version ? "git",
12+
}:
13+
# The core of the code was taken from nixpkgs and with special thanks to the
14+
# upstream maintainer `jvanbruegge`
15+
# https://github.com/NixOS/nixpkgs/blob/63c3a29ca82437c87573e4c6919b09a24ea61b0f/pkgs/by-name/au/audible-cli/package.nix
16+
python3Packages.buildPythonApplication {
17+
pname = "audible-cli";
18+
inherit version;
19+
pyproject = true;
20+
21+
src = nix-filter {
22+
root = ./..;
23+
include =
24+
[
25+
# Include the "src" path relative to the root
26+
"src"
27+
"LICENSE"
28+
"setup.cfg"
29+
"README.md" # Required by `setup.cfg`
30+
"setup.py"
31+
"nix"
32+
]
33+
++ lib.optionals enable-plugin-annotations [
34+
"plugin_cmds/cmd_get-annotations.py"
35+
]
36+
++ lib.optionals enable-plugin-goodreads-transform [
37+
"plugin_cmds/cmd_goodreads-transform.py"
38+
]
39+
++ lib.optionals enable-plugin-image-urls [
40+
"plugin_cmds/cmd_image-urls.py"
41+
]
42+
++ lib.optionals enable-plugin-listening-stats [
43+
"plugin_cmds/cmd_listening-stats.py"
44+
]
45+
++ lib.optionals enable-plugin-decrypt [
46+
"plugin_cmds/cmd_decrypt.py"
47+
];
48+
};
49+
50+
# there is no real benefit of trying to make ffmpeg smaller, as headless
51+
# only takes about 25MB, whereas Python takes >120MB.
52+
dependencies = lib.optionals enable-plugin-decrypt [ffmpeg_7-headless];
53+
makeWrapperArgs =
54+
lib.optionals
55+
(enable-plugin-annotations || enable-plugin-goodreads-transform || enable-plugin-image-urls || enable-plugin-listening-stats || enable-plugin-decrypt)
56+
["--set AUDIBLE_PLUGIN_DIR $src/plugin_cmds"];
57+
58+
nativeBuildInputs = with python3Packages; [
59+
pythonRelaxDepsHook
60+
setuptools
61+
];
62+
# FUTURE: Renable once shell completion is fixed!
63+
# ++ [
64+
# installShellFiles
65+
# ];
66+
67+
propagatedBuildInputs =
68+
(with python3Packages; [
69+
aiofiles
70+
audible
71+
click
72+
httpx
73+
packaging
74+
pillow
75+
questionary
76+
setuptools
77+
tabulate
78+
toml
79+
tqdm
80+
])
81+
++ lib.optionals enable-plugin-goodreads-transform [
82+
python3Packages.isbntools
83+
];
84+
85+
pythonRelaxDeps = [
86+
"httpx"
87+
];
88+
89+
# FUTURE: Fix fish code_completions & re-enable them
90+
# postInstall = ''
91+
# export PATH=$out/bin:$PATH
92+
# installShellCompletion --cmd audible \
93+
# --bash <(source utils/code_completion/audible-complete-bash.sh) \
94+
# --fish <(source utils/code_completion/audible-complete-zsh-fish.sh) \
95+
# --zsh <(source utils/code_completion/audible-complete-zsh-fish.sh)
96+
# '';
97+
98+
# upstream has no tests
99+
doCheck = false;
100+
# FUTURE: Add import tests for the different plugins!
101+
102+
pythonImportsCheck = [
103+
"audible_cli"
104+
];
105+
106+
# passthru.updateScript = pkgs.nix-update-script {};
107+
108+
meta = {
109+
description = "A command line interface for audible package. With the cli you can download your Audible books, cover, chapter files";
110+
license = lib.licenses.agpl3Only;
111+
homepage = "https://github.com/mkb79/audible-cli";
112+
maintainers = with lib.maintainers; [kai-tub];
113+
mainProgram = "audible";
114+
};
115+
}

0 commit comments

Comments
 (0)