From 2eafe4b950d73ec4d1dedbeeff58c030a28cf0b3 Mon Sep 17 00:00:00 2001 From: LordGrimmauld Date: Sat, 9 Mar 2024 15:38:58 +0100 Subject: [PATCH] attempt nix packaging --- .gitignore | 2 +- CMakeLists.txt | 7 ++---- LICENSE | 11 +++++++++ flake.lock | 26 ++++++++++++++++++++++ flake.nix | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 20 ----------------- nix/default.nix | 46 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 145 insertions(+), 26 deletions(-) create mode 100644 LICENSE create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/default.nix diff --git a/.gitignore b/.gitignore index 1ece43c..81f817d 100644 --- a/.gitignore +++ b/.gitignore @@ -76,4 +76,4 @@ cmake-build-debug *.dll *.exe build - +result diff --git a/CMakeLists.txt b/CMakeLists.txt index c5c0ca2..4a9f3cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,8 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(TS_FILES swaymux_en_US.ts) @@ -52,7 +52,6 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation - qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) else() if(ANDROID) add_library(swaymux SHARED @@ -65,8 +64,6 @@ else() ${PROJECT_SOURCES} ) endif() - - qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) endif() target_link_libraries(swaymux PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0ede32b --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +Copyright 2024 Grimmauld + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8fc4939 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1709905912, + "narHash": "sha256-TofHtnlrOBCxtSZ9nnlsTybDnQXUmQrlIleXF1RQAwQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a343533bccc62400e8a9560423486a3b6c11a23b", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixpkgs-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..52c621f --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ + +{ + description = "Swaymux: sway workspace/output/container navigation"; + + inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable"; + + outputs = { + nixpkgs, + self, + ... + }: let + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); +# forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: forSystem system fn); + in { + checks = forAllSystems ({ + pkgs, + lib, + ... + }: { + alejandra = pkgs.runCommand "check-alejandra" {} '' + ${lib.getExe pkgs.alejandra} --check ${./.} + touch $out + ''; + }); + + devShells = forAllSystems (pkgs: { + default = pkgs.mkShell { + packages = with pkgs; [ + # base toolchain + gcc + qt6.full + qtcreator + cmake + nlohmann_json + qtwayland + + # nix utils + self.formatter.${pkgs.system} + nil + ]; + }; + }); + + formatter = forAllSystems (pkgs: pkgs.alejandra); + + packages = forAllSystems (system: let + pkgs = nixpkgs.legacyPackages.${system}; + swaymux-pkg = (pkgs.qt6Packages.callPackage ./nix/default.nix {}); + in { + swaymux = swaymux-pkg; + default = swaymux-pkg; + }); + }; +} diff --git a/main.cpp b/main.cpp index 6d0fcea..7fa2b35 100644 --- a/main.cpp +++ b/main.cpp @@ -1,17 +1,6 @@ #include "mainwindow.h" -#include "sway_bindings/Sway.h" -#include "tree/swaytree.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include using namespace Qt::StringLiterals; @@ -31,15 +20,6 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationName("Grimmauld"); QCoreApplication::setApplicationName("SwayMux"); - QTranslator translator; - const QStringList uiLanguages = QLocale::system().uiLanguages(); - for (const QString &locale : uiLanguages) { - const QString baseName = "swaymux_" + QLocale(locale).name(); - if (translator.load(":/i18n/" + baseName)) { - a.installTranslator(&translator); - break; - } - } MainWindow w; w.showMaximized(); return a.exec(); diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..a4816b4 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,46 @@ +{ + lib, + nlohmann_json, + cmake, + stdenv, + qt6, + qtbase, + wrapQtAppsHook, + qtwayland +}: +stdenv.mkDerivation { + pname = "swaymux"; + version = "0.1"; + + src = lib.cleanSource ../.; + + configurePhase = '' + cmake . + ''; + + buildPhase = '' + make + ''; + + installPhase = '' + mkdir -p $out/bin + mv swaymux $out/bin + ''; + + buildInputs = [ qtbase qtwayland cmake nlohmann_json ]; + nativeBuildInputs = [ wrapQtAppsHook ]; + + doCheck = true; + + meta = with lib; { + description = "A program to quickly navigate sway"; + longDescription = '' + Swaymux allows the user to quickly navigate and administrate outputs, workspaces and containers in a tmux-style approach. + ''; + homepage = "https://git.grimmauld.de/Grimmauld/swaymux"; + changelog = "https://git.grimmauld.de/Grimmauld/swaymux/commits/branch/main"; + license = lib.licenses.bsd3; + maintainers = [ maintainers.grimmauld ]; + platforms = platforms.linux; + }; +}