From 73c6651baff2a727aa13ba19fdb194db340b4fae Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 26 Nov 2024 13:57:40 +0200 Subject: [PATCH] Nix: init --- flake.lock | 67 ++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 57 ++++++++++++++++++++++++++++++++++++++++ nix/default.nix | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/default.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..26957e2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,67 @@ +{ + "nodes": { + "hyprutils": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1732288281, + "narHash": "sha256-XTU9B53IjGeJiJ7LstOhuxcRjCOFkQFl01H78sT9Lg4=", + "owner": "hyprwm", + "repo": "hyprutils", + "rev": "b26f33cc1c8a7fd5076e19e2cce3f062dca6351c", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprutils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1732014248, + "narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "23e89b7da85c3640bbc2173fe04f4bd114342367", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "hyprutils": "hyprutils", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default-linux", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6892d47 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "Small C++ library with graphics / resource related utilities used across the hypr* ecosystem"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default-linux"; + + hyprutils = { + url = "github:hyprwm/hyprutils"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.systems.follows = "systems"; + }; + }; + + outputs = { + self, + nixpkgs, + systems, + ... + } @ inputs: let + inherit (nixpkgs) lib; + eachSystem = lib.genAttrs (import systems); + pkgsFor = eachSystem (system: + import nixpkgs { + localSystem.system = system; + overlays = with self.overlays; [hyprgraphics]; + }); + mkDate = longDate: (lib.concatStringsSep "-" [ + (builtins.substring 0 4 longDate) + (builtins.substring 4 2 longDate) + (builtins.substring 6 2 longDate) + ]); + + version = lib.removeSuffix "\n" (builtins.readFile ./VERSION); + in { + overlays = { + default = self.overlays.hyprgraphics; + hyprgraphics = lib.composeManyExtensions [ + inputs.hyprutils.overlays.default + (final: prev: { + hyprgraphics = final.callPackage ./nix/default.nix { + stdenv = final.gcc14Stdenv; + version = version + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty"); + }; + hyprgraphics-with-tests = final.hyprgraphics.override {doCheck = true;}; + }) + ]; + }; + + packages = eachSystem (system: { + default = self.packages.${system}.hyprgraphics; + inherit (pkgsFor.${system}) hyprgraphics hyprgraphics-with-tests; + }); + + formatter = eachSystem (system: pkgsFor.${system}.alejandra); + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..3495368 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,70 @@ +{ + lib, + stdenv, + stdenvAdapters, + cmake, + pkg-config, + cairo, + file, + hyprutils, + libjpeg, + libjxl, + libwebp, + pixman, + version ? "git", + doCheck ? false, + debug ? false, +}: let + inherit (builtins) foldl'; + inherit (lib.lists) flatten; + inherit (lib.sources) cleanSource cleanSourceWith; + inherit (lib.strings) hasSuffix; + + adapters = flatten [ + stdenvAdapters.useMoldLinker + (lib.optional debug stdenvAdapters.keepDebugInfo) + ]; + + customStdenv = foldl' (acc: adapter: adapter acc) stdenv adapters; +in + customStdenv.mkDerivation { + pname = "hyprgraphics"; + inherit version doCheck; + + src = cleanSourceWith { + filter = name: _type: let + baseName = baseNameOf (toString name); + in + ! (hasSuffix ".nix" baseName); + src = cleanSource ../.; + }; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + buildInputs = [ + cairo + file + hyprutils + libjpeg + libjxl + libwebp + pixman + ]; + + outputs = ["out" "dev"]; + + cmakeBuildType = + if debug + then "Debug" + else "RelWithDebInfo"; + + meta = with lib; { + homepage = "https://github.com/hyprwm/hyprgraphics"; + description = "Small C++ library with graphics / resource related utilities used across the hypr* ecosystem"; + license = licenses.bsd3; + platforms = platforms.linux; + }; + }