Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix support and use #1168

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CMakeUserPresets.json
/*build*/
**/target/
/*install*/
/Nixpile-build

*.swp

Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@ If you're having trouble with something, want to suggest a feature or report a b

You can directly [report issues here on GitHub](/drawpile/Drawpile/issues). If you got Discord, you can [join the Drawpile server](https://drawpile.net/discord/) on there. You can also [use the chatroom on libera.chat](https://drawpile.net/irc/), it can be done directly through the browser and doesn't need any account.

## Drawpile on nix

> Linux users hate him for descovering how to reproduce an ENTIRE ENVIROMENT with just ONE COMMAND <br>
> \- Qubic 2023

Having a reproducible work enviroment is nice.
Especialy if you can do it only with one command.

### Dev enviroment

To get a dev shell with nix you just do `nix shell .#(cmake profile without linux prefix)`
(I did not include linux prefix becuse I'm quite sure it will probably work with nix + macOs)

### Dev shell functions

In dev shells you have 2 very simple functions

`firstBuild` for setuping cmake and building drawpile for first time <br>
`incrementalBuild` for building drawpile successive times

### Package names

We name packages same way we name shell-s

<!---
Sorry for spelling mistakes I wrote this at 3AM tired
TODO rewrite this entierly
-->

## Contributing

Pull requests are welcome, be it for code or anything else! If you want to contribute documentation, you can do so [over in this repository](/drawpile/drawpile.github.io).
Expand Down
6 changes: 6 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url =
lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) { src = ./.; }).defaultNix
92 changes: 92 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

240 changes: 240 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
# TODO: Consider using mold (linker)
#TODO: Add declarative drawpile server support
#TODO: Consider my terrible life choices that led me to derive os-es from config files
{
description = "Collaborative drawing program that lets multiple people draw.";

inputs = {
#main packages
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

#utilities in writing flakes
flake-utils.url = "github:numtide/flake-utils";

#compatibility with non flaked nix
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";

# source filtering
nix-filter.url = "github:numtide/nix-filter";
};

outputs = { self, nixpkgs, flake-utils, nix-filter, ... }:
#Support x86_64/arm linux
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};

#Compile time libs

mkNativeInputs = { qt5 }:
let
qtStuff = if qt5 then
[ pkgs.libsForQt5.qt5.wrapQtAppsHook ]
else
[ pkgs.qt6.wrapQtAppsHook ];

buildSystems = with pkgs; [ cmake ninja gcc ];

in qtStuff ++ buildSystems;

mkDepends = { qt5, shell }:
let
#decide what QT to use
qtDependences = if qt5 then
with pkgs.libsForQt5.qt5;
[ qtbase qtsvg qttools qtmultimedia ]
++ [ pkgs.libsForQt5.karchive ]
else
with pkgs; [ qt6.qtbase qt6.qtsvg qt6.qttools qt6.qtmultimedia ];

#Other dependencies required for building
otherDeps = with pkgs; [

git
libxkbcommon
libzip
libsodium
libmicrohttpd
libpulseaudio
];

shellDpeneds = if shell then
with pkgs; [ cargo rustc rustfmt clippy ]
else
with pkgs; [ ];

in qtDependences ++ shellDpeneds ++ otherDeps;

mkDpShell = { useQt5, preset, debug ? false }:
pkgs.mkShell {

nativeBuildInputs = mkNativeInputs { qt5 = useQt5; };

buildInputs = mkDepends {
qt5 = useQt5;
shell = true;
};

shellHook = ''
export ROOT="$PWD/Nixpile-build/${preset}"
mkdir -p "$ROOT"
export LD_LIBRARY_PATH="$CMAKE_LIBRARY_PATH"

configure() {
cmake -S "$ROOT/../../" -B "$ROOT" \
--preset ${preset} \
"-DCMAKE_INSTALL_PREFIX=$out"
}

build() {
if ! [ -e "$ROOT" ]; then
configure || return 1
fi
if [ -e "$ROOT/bin/.drawpile-wrapped" ]; then
mv "$ROOT/bin/.drawpile-wrapped" "$ROOT/bin/drawpile"
fi
cmake --build "$ROOT" || return 1
wrapQtApp "$ROOT/bin/drawpile"
}

run() {
build || return 1
"$ROOT/bin/drawpile"
}
'';
};

mkDrawpile = { useQt5, preset, debug ? false }:
pkgs.rustPlatform.buildRustPackage {
name = "drawpile";

src = nix-filter {
root = ./.;
# Filter source
include = [
# Include /src
"src"
# Include rust stuff
./Cargo.toml
./Cargo.lock
# Include CMAKE stuff
"cmake"
./CMakePresets.json
./CMakeLists.txt

#Other misalanius stuff
./LICENSE.txt
./ChangeLog
./README.md
"doc"
];
};

nativeBuildInputs = mkNativeInputs { qt5 = useQt5; };

buildInputs = mkDepends {
qt5 = useQt5;
shell = false;
};

cargoLock = { lockFile = ./Cargo.lock; };

configurePhase = ''
cmake -S ./ -B Drawpile-build \
--preset ${preset} \
-DCMAKE_INSTALL_PREFIX=$out
'';

enableParallelBuilding = true;

buildPhase = ''
cmake --build ./Drawpile-build
'';

installPhase = ''
mkdir -p $out
cmake --install ./Drawpile-build
'';
};

in rec {

packages = {
debug-qt6-all-ninja = mkDrawpile {
preset = "linux-debug-qt6-all-ninja";
useQt5 = false;
};

release-qt6-all-ninja = mkDrawpile {
preset = "linux-release-qt6-all-ninja";
useQt5 = false;
};

release-qt6-server-ninja = mkDrawpile {
preset = "linux-release-qt6-server-ninja";
useQt5 = false;
};

debug-qt5-all-ninja = mkDrawpile {
preset = "linux-debug-qt5-all-ninja";
useQt5 = true;
};

release-qt5-all-ninja = mkDrawpile {
preset = "linux-release-qt5-all-ninja";
useQt5 = true;
};

release-qt5-server-ninja = mkDrawpile {
preset = "linux-release-qt5-server-ninja";
useQt5 = true;
};

default = self.outputs.packages.${system}.release-qt6-all-ninja;
};

#Dev shells

devShells = rec {
debug-qt6-all-ninja = mkDpShell {
preset = "linux-debug-qt6-all-ninja";
useQt5 = false;
debug = true;
};

release-qt6-all-ninja = mkDpShell {
preset = "linux-release-qt6-all-ninja";
useQt5 = false;
debug = true;
};

release-qt6-server-ninja = mkDpShell {
preset = "linux-release-qt6-server-ninja";
useQt5 = false;
debug = true;
};

debug-qt5-all-ninja = mkDpShell {
preset = "linux-debug-qt5-all-ninja";
useQt5 = true;
debug = true;
};

release-qt5-all-ninja = mkDpShell {
preset = "linux-release-qt5-all-ninja";
useQt5 = true;
debug = true;
};

release-qt5-server-ninja = mkDpShell {
preset = "linux-release-qt5-server-ninja";
useQt5 = true;
debug = true;
};

default = self.outputs.devShells.${system}.debug-qt6-all-ninja;
};

formatter = pkgs.nixfmt;
});
}
6 changes: 6 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url =
lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) { src = ./.; }).shellNix