dev: Added Nix Flake support

- Enables Nix users to get the git version of waybar
- Enables Nix users to develop waybar easily
- Adds a fully reproducible development environment
  - The user only has to install Nix, no other depencencies
  - Automatic dev env on directory entry through .envrc
This commit is contained in:
Narice 2022-12-06 18:44:26 +01:00
parent c5babb4c44
commit d5a86526bc
5 changed files with 300 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

1
.gitignore vendored
View File

@ -41,3 +41,4 @@ packagecache
*.exe
*.out
*.app
/.direnv/

94
flake.lock Normal file
View File

@ -0,0 +1,94 @@
{
"nodes": {
"devshell": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1667210711,
"narHash": "sha256-IoErjXZAkzYWHEpQqwu/DeRNJGFdR7X2OGbkhMqMrpw=",
"owner": "numtide",
"repo": "devshell",
"rev": "96a9dd12b8a447840cc246e17a47b81a4268bba7",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1642700792,
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1643381941,
"narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1670152712,
"narHash": "sha256-LJttwIvJqsZIj8u1LxVRv82vwUtkzVqQVi7Wb8gxPS4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "14ddeaebcbe9a25748221d1d7ecdf98e20e2325e",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"devshell": "devshell",
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
}
}
},
"root": "root",
"version": 7
}

65
flake.nix Normal file
View File

@ -0,0 +1,65 @@
{
description = "Highly customizable Wayland bar for Sway and Wlroots based compositors.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
devshell.url = "github:numtide/devshell";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, flake-utils, devshell, nixpkgs }:
let
inherit (nixpkgs) lib;
genSystems = lib.genAttrs [
"x86_64-linux"
];
pkgsFor = genSystems (system:
import nixpkgs {
inherit system;
});
mkDate = longDate: (lib.concatStringsSep "-" [
(builtins.substring 0 4 longDate)
(builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate)
]);
in
{
overlays.default = _: prev: rec {
waybar = prev.callPackage ./nix/default.nix {
version = "0.9.16" + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
};
};
packages = genSystems
(system:
(self.overlays.default null pkgsFor.${system})
// {
default = self.packages.${system}.waybar;
});
} //
flake-utils.lib.eachDefaultSystem (system: {
devShell =
let pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlay ];
};
in
pkgs.devshell.mkShell {
imports = [ "${pkgs.devshell.extraModulesDir}/language/c.nix" ];
commands = [
{
package = pkgs.devshell.cli;
help = "Per project developer environments";
}
];
devshell.packages = with pkgs; [
clang-tools
gdb
];
language.c.libraries = with pkgs; [
];
};
});
}

139
nix/default.nix Normal file
View File

@ -0,0 +1,139 @@
{ lib
, stdenv
, fetchFromGitHub
, meson
, pkg-config
, ninja
, wrapGAppsHook
, wayland
, wlroots
, gtkmm3
, libsigcxx
, jsoncpp
, scdoc
, spdlog
, gtk-layer-shell
, howard-hinnant-date
, libinotify-kqueue
, libxkbcommon
, evdevSupport ? true
, libevdev
, inputSupport ? true
, libinput
, jackSupport ? true
, libjack2
, mpdSupport ? true
, libmpdclient
, nlSupport ? true
, libnl
, pulseSupport ? true
, libpulseaudio
, rfkillSupport ? true
, runTests ? true
, catch2_3
, sndioSupport ? true
, sndio
, swaySupport ? true
, sway
, traySupport ? true
, libdbusmenu-gtk3
, udevSupport ? true
, udev
, upowerSupport ? true
, upower
, wireplumberSupport ? true
, wireplumber
, withMediaPlayer ? false
, glib
, gobject-introspection
, python3
, playerctl
, version
}:
stdenv.mkDerivation rec {
pname = "waybar";
inherit version;
# version = "0.9.16";
src = lib.cleanSourceWith {
filter = name: type:
let
baseName = baseNameOf (toString name);
in
! (
lib.hasSuffix ".nix" baseName
);
src = lib.cleanSource ../.;
};
nativeBuildInputs = [
meson
ninja
pkg-config
scdoc
wrapGAppsHook
] ++ lib.optional withMediaPlayer gobject-introspection;
propagatedBuildInputs = lib.optionals withMediaPlayer [
glib
playerctl
python3.pkgs.pygobject3
];
strictDeps = false;
buildInputs = with lib;
[ wayland wlroots gtkmm3 libsigcxx jsoncpp spdlog gtk-layer-shell howard-hinnant-date libxkbcommon ]
++ optional (!stdenv.isLinux) libinotify-kqueue
++ optional evdevSupport libevdev
++ optional inputSupport libinput
++ optional jackSupport libjack2
++ optional mpdSupport libmpdclient
++ optional nlSupport libnl
++ optional pulseSupport libpulseaudio
++ optional sndioSupport sndio
++ optional swaySupport sway
++ optional traySupport libdbusmenu-gtk3
++ optional udevSupport udev
++ optional upowerSupport upower
++ optional wireplumberSupport wireplumber;
checkInputs = [ catch2_3 ];
doCheck = runTests;
mesonFlags = (lib.mapAttrsToList
(option: enable: "-D${option}=${if enable then "enabled" else "disabled"}")
{
dbusmenu-gtk = traySupport;
jack = jackSupport;
libinput = inputSupport;
libnl = nlSupport;
libudev = udevSupport;
mpd = mpdSupport;
pulseaudio = pulseSupport;
rfkill = rfkillSupport;
sndio = sndioSupport;
tests = runTests;
upower_glib = upowerSupport;
wireplumber = wireplumberSupport;
}
) ++ [
"-Dsystemd=disabled"
"-Dgtk-layer-shell=enabled"
"-Dman-pages=enabled"
];
preFixup = lib.optionalString withMediaPlayer ''
cp $src/resources/custom_modules/mediaplayer.py $out/bin/waybar-mediaplayer.py
wrapProgram $out/bin/waybar-mediaplayer.py \
--prefix PYTHONPATH : "$PYTHONPATH:$out/${python3.sitePackages}"
'';
meta = with lib; {
description = "Highly customizable Wayland bar for Sway and Wlroots based compositors";
license = licenses.mit;
maintainers = with maintainers; [ FlorianFranzen minijackson synthetica lovesegfault ];
platforms = platforms.unix;
homepage = "https://github.com/alexays/waybar";
};
}