Skip to content

Commit de3625d

Browse files
authored
Add NixOS package (#257)
Closes #106
1 parent 64712c1 commit de3625d

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

default.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following Nix expression provides the result of building the tiddlydesktop.nix package.
2+
# The version of Nixpkgs comes from the Nix Flake lock file, flake.lock.
3+
# To build, simply change to the repo's directory and run: nix-build
4+
5+
let
6+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
7+
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/${lock.nodes.nixpkgs.locked.rev}.tar.gz") { };
8+
in pkgs.callPackage ./tiddlydesktop.nix { }

flake.lock

Lines changed: 24 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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This is a Nix Flake which provides the tiddlydesktop package.
2+
# To execute TiddlyDesktop, simply run: nix run github:TiddlyWiki/TiddlyDesktop
3+
4+
{
5+
description = "A Nix Flake for TiddlyDesktop.";
6+
7+
outputs = { self, nixpkgs }: {
8+
9+
packages.x86_64-linux.tiddlydesktop = let
10+
pkgs = import "${nixpkgs}" {
11+
system = "x86_64-linux";
12+
};
13+
in pkgs.callPackage ./tiddlydesktop.nix { };
14+
15+
packages.x86_64-linux.default = self.packages.x86_64-linux.tiddlydesktop;
16+
17+
apps.x86_64-linux.tiddlydesktop = {
18+
type = "app";
19+
program = "${self.packages.x86_64-linux.tiddlydesktop}/bin/tiddlydesktop";
20+
};
21+
22+
apps.x86_64-linux.default = self.apps.x86_64-linux.tiddlydesktop;
23+
24+
};
25+
}

readme.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@ Unzip into a folder and run `TiddlyWiki.app` or `nw.exe` and for linux `nw`
2020

2121
Note that TiddlyDesktop will not work correctly from a Windows UNC network share (eg ``\\MY-SERVER\SHARE\MyFolder``). You should map the network share to a local drive, and run it from there.
2222

23+
## NixOS
24+
25+
To install TiddlyDesktop on NixOS, you first need to add this repo to your `configuration.nix`; Using a `let` expression at the top of the file is a good approach:
26+
27+
```
28+
let
29+
twdesktop = let
30+
rev = "Set this to the TiddlyDesktop Git revision that you want to install.";
31+
in import (fetchTarball "https://github.com/TiddlyWiki/TiddlyDesktop/archive/${rev}.tar.gz") { };
32+
in
33+
...
34+
```
35+
36+
Then add the attribute name (which is twdesktop in the example above) to your `systemPackages`:
37+
38+
```
39+
...
40+
environment.systemPackages = with pkgs; [
41+
...
42+
twdesktop
43+
];
44+
...
45+
```
46+
47+
In addition to the method described above, the tiddlydesktop package is available as a Nix Flake; See https://nixos.wiki/wiki/Flakes to read more about Flakes. Simply use the Flake input `github:TiddlyWiki/TiddlyDesktop`. For example, you can run TiddlyDesktop with the command `nix run github:TiddlyWiki/TiddlyDesktop`.
48+
2349
# Usage
2450

2551
## Multiple Configurations

tiddlydesktop.nix

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{ stdenv
2+
, lib
3+
, nodePackages
4+
, nwjs
5+
, jq
6+
, writeScript
7+
, bash
8+
, makeDesktopItem
9+
, copyDesktopItems
10+
, gsettings-desktop-schemas
11+
, wrapGAppsHook
12+
, gtk3
13+
}:
14+
let
15+
launcher = writeScript "tiddlydesktop" ''
16+
#! ${bash}/bin/bash
17+
18+
${nwjs}/bin/nw @out@/lib/tiddlydesktop $@
19+
'';
20+
21+
packageJson = builtins.fromJSON (builtins.readFile ./package.json);
22+
in stdenv.mkDerivation rec {
23+
pname = "tiddlydesktop";
24+
version = "${packageJson.version}";
25+
26+
src = ./.;
27+
28+
nativeBuildInputs = [ copyDesktopItems wrapGAppsHook gtk3 ];
29+
buildInputs = [ nodePackages.tiddlywiki jq ];
30+
31+
# These instructions are based on those from the bld.sh upstream script.
32+
buildPhase = ''
33+
cp -RH ${nodePackages.tiddlywiki}/lib/node_modules/tiddlywiki source/tiddlywiki
34+
chmod -R u+w source
35+
cp -RH plugins/tiddlydesktop source/tiddlywiki/plugins/tiddlywiki
36+
37+
version=$(jq < package.json '.version')
38+
plugin_info=$(mktemp)
39+
cat source/tiddlywiki/plugins/tiddlywiki/tiddlydesktop/plugin.info > $plugin_info
40+
jq < $plugin_info --arg version $version '. + {version: $version}' > source/tiddlywiki/plugins/tiddlywiki/tiddlydesktop/plugin.info
41+
echo $version > source/tiddlywiki/plugins/tiddlywiki/tiddlydesktop/system/version.txt
42+
'';
43+
44+
installPhase = ''
45+
runHook preInstall
46+
mkdir -p $out/bin
47+
mkdir -p $out/lib/tiddlydesktop
48+
mkdir -p $out/share/icons/hicolor
49+
50+
cp -R source/* $out/lib/tiddlydesktop/
51+
cp ${launcher} $out/bin/tiddlydesktop
52+
substituteAllInPlace $out/bin/tiddlydesktop
53+
54+
for n in 16 32 48 64 128 256 1024; do
55+
size=$n"x"$n
56+
mkdir -p $out/share/icons/hicolor/$size/apps
57+
cp icons/app-icon$n.png $out/share/icons/hicolor/$size/apps/${pname}.png
58+
done
59+
60+
runHook postInstall
61+
'';
62+
63+
desktopItems = [
64+
(makeDesktopItem {
65+
name = pname;
66+
exec = pname;
67+
icon = pname;
68+
desktopName = "Tiddly Desktop";
69+
categories = ["Utility" "TextEditor"];
70+
})
71+
];
72+
73+
meta = with lib; {
74+
homepage = "https://github.com/TiddlyWiki/TiddlyDesktop";
75+
description = "A custom desktop browser for TiddlyWiki 5 and TiddlyWiki Classic, based on nw.js";
76+
license = licenses.bsd0;
77+
maintainers = with maintainers; [ emmanuelrosa ];
78+
platforms = [ "x86_64-linux" ];
79+
};
80+
}

0 commit comments

Comments
 (0)