1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +02:00

Merge pull request #545 from JakeStanger/build/nix/refactor

Nix refactor
This commit is contained in:
Jake Stanger 2024-04-17 22:10:17 +01:00 committed by GitHub
commit f4e1e81da6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 254 additions and 240 deletions

381
flake.nix
View file

@ -1,215 +1,222 @@
{ {
description = "Nix Flake for ironbar"; description = "Nix Flake for ironbar";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay = { rust-overlay = {
url = "github:oxalica/rust-overlay"; url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
crane = { crane = {
url = "github:ipetkov/crane"; url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
naersk.url = "github:nix-community/naersk"; naersk.url = "github:nix-community/naersk";
}; };
outputs = {
self,
nixpkgs,
rust-overlay,
crane,
naersk,
...
}: let
inherit (nixpkgs) lib;
genSystems = lib.genAttrs [
"aarch64-linux"
"x86_64-linux"
];
pkgsFor = system:
import nixpkgs {
inherit system;
overlays = [ outputs = { self, nixpkgs, rust-overlay, crane, naersk, ... }:
self.overlays.default let
rust-overlay.overlays.default inherit (nixpkgs) lib;
];
}; genSystems = lib.genAttrs [ "aarch64-linux" "x86_64-linux" ];
mkRustToolchain = pkgs:
pkgs.rust-bin.stable.latest.default.override { pkgsFor = system:
extensions = ["rust-src"]; import nixpkgs {
}; inherit system;
in {
overlays.default = final: prev: let overlays = [ self.overlays.default rust-overlay.overlays.default ];
rust = mkRustToolchain final; };
craneLib = (crane.mkLib final).overrideToolchain rust;
naersk' = prev.callPackage naersk { mkRustToolchain = pkgs:
cargo = rust; pkgs.rust-bin.stable.latest.default.override {
rustc = rust; extensions = [ "rust-src" ];
}; };
rustPlatform = prev.makeRustPlatform {
cargo = rust;
rustc = rust;
};
props = builtins.fromTOML (builtins.readFile ./Cargo.toml);
mkDate = longDate: (lib.concatStringsSep "-" [
(builtins.substring 0 4 longDate)
(builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate)
]);
builder = "naersk";
in { in {
ironbar = let overlays.default = final: prev:
version = props.package.version + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty"); let
in rust = mkRustToolchain final;
if builder == "crane"
then craneLib = (crane.mkLib final).overrideToolchain rust;
prev.callPackage ./nix/default.nix {
inherit version; naersk' = prev.callPackage naersk {
inherit rustPlatform; cargo = rust;
builderName = builder; rustc = rust;
builder = craneLib;
}
else if builder == "naersk"
then
prev.callPackage ./nix/default.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
builder = naersk';
}
else
prev.callPackage ./nix/default.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
}; };
};
packages = genSystems ( rustPlatform = prev.makeRustPlatform {
system: let cargo = rust;
pkgs = pkgsFor system; rustc = rust;
in };
(self.overlays.default pkgs pkgs)
// { props = builtins.fromTOML (builtins.readFile ./Cargo.toml);
mkDate = longDate:
(lib.concatStringsSep "-" [
(builtins.substring 0 4 longDate)
(builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate)
]);
builder = "naersk";
in {
ironbar = let
version = props.package.version + "+date="
+ (mkDate (self.lastModifiedDate or "19700101")) + "_"
+ (self.shortRev or "dirty");
in if builder == "crane" then
prev.callPackage ./nix/default.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
builder = craneLib;
}
else if builder == "naersk" then
prev.callPackage ./nix/default.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
builder = naersk';
}
else
prev.callPackage ./nix/default.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
};
};
packages = genSystems (system:
let pkgs = pkgsFor system;
in (self.overlays.default pkgs pkgs) // {
default = self.packages.${system}.ironbar; default = self.packages.${system}.ironbar;
} });
);
apps = genSystems (system: let
pkgs = pkgsFor system;
in {
default = {
type = "app";
program = "${pkgs.ironbar}/bin/ironbar";
};
ironbar = {
type = "app";
program = "${pkgs.ironbar}/bin/ironbar";
};
});
devShells = genSystems (system: let apps = genSystems (system:
pkgs = pkgsFor system; let pkgs = pkgsFor system;
rust = mkRustToolchain pkgs; in rec {
ironbar = {
in { type = "app";
default = pkgs.mkShell { program = "${pkgs.ironbar}/bin/ironbar";
packages = with pkgs; [
rust
rust-analyzer-unwrapped
gcc
gtk3
gtk-layer-shell
pkg-config
openssl
gdk-pixbuf
glib
glib-networking
shared-mime-info
gnome.adwaita-icon-theme
hicolor-icon-theme
gsettings-desktop-schemas
libxkbcommon
libpulseaudio
luajit
luajitPackages.lgi
];
RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
};
});
homeManagerModules.default = {
config,
lib,
pkgs,
...
}: let
cfg = config.programs.ironbar;
defaultIronbarPackage = self.packages.${pkgs.hostPlatform.system}.default;
jsonFormat = pkgs.formats.json {};
in {
options.programs.ironbar = {
enable = lib.mkEnableOption "ironbar status bar";
package = lib.mkOption {
type = with lib.types; package;
default = defaultIronbarPackage;
description = "The package for ironbar to use.";
};
systemd = lib.mkOption {
type = lib.types.bool;
default = pkgs.stdenv.isLinux;
description = "Whether to enable to systemd service for ironbar.";
};
style = lib.mkOption {
type = lib.types.lines;
default = "";
description = "The stylesheet to apply to ironbar.";
};
config = lib.mkOption {
type = jsonFormat.type;
default = {};
description = "The config to pass to ironbar.";
};
features = lib.mkOption {
type = lib.types.listOf lib.types.nonEmptyStr;
default = [];
description = "The features to be used.";
};
};
config = let
pkg = cfg.package.override {features = cfg.features;};
in
lib.mkIf cfg.enable {
home.packages = [pkg];
xdg.configFile = {
"ironbar/config.json" = lib.mkIf (cfg.config != "") {
source = jsonFormat.generate "ironbar-config" cfg.config;
};
"ironbar/style.css" = lib.mkIf (cfg.style != "") {
text = cfg.style;
};
}; };
systemd.user.services.ironbar = lib.mkIf cfg.systemd {
Unit = { default = ironbar;
Description = "Systemd service for Ironbar"; });
Requires = ["graphical-session.target"];
}; devShells = genSystems (system:
Service = { let
Type = "simple"; pkgs = pkgsFor system;
ExecStart = "${pkg}/bin/ironbar"; rust = mkRustToolchain pkgs;
};
Install.WantedBy = [ in {
(lib.mkIf config.wayland.windowManager.hyprland.systemd.enable "hyprland-session.target") default = pkgs.mkShell {
(lib.mkIf config.wayland.windowManager.sway.systemd.enable "sway-session.target") packages = with pkgs; [
(lib.mkIf config.wayland.windowManager.river.systemd.enable "river-session.target") rust
rust-analyzer-unwrapped
gcc
gtk3
gtk-layer-shell
pkg-config
openssl
gdk-pixbuf
glib
glib-networking
shared-mime-info
gnome.adwaita-icon-theme
hicolor-icon-theme
gsettings-desktop-schemas
libxkbcommon
libpulseaudio
luajit
luajitPackages.lgi
]; ];
RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
};
});
homeManagerModules.default = { config, lib, pkgs, ... }:
let
cfg = config.programs.ironbar;
defaultIronbarPackage =
self.packages.${pkgs.hostPlatform.system}.default;
jsonFormat = pkgs.formats.json { };
in {
options.programs.ironbar = {
enable = lib.mkEnableOption "ironbar status bar";
package = lib.mkOption {
type = with lib.types; package;
default = defaultIronbarPackage;
description = "The package for ironbar to use.";
};
systemd = lib.mkOption {
type = lib.types.bool;
default = pkgs.stdenv.isLinux;
description = "Whether to enable to systemd service for ironbar.";
};
style = lib.mkOption {
type = lib.types.lines;
default = "";
description = "The stylesheet to apply to ironbar.";
};
config = lib.mkOption {
type = jsonFormat.type;
default = { };
description = "The config to pass to ironbar.";
};
features = lib.mkOption {
type = lib.types.listOf lib.types.nonEmptyStr;
default = [ ];
description = "The features to be used.";
};
};
config = let pkg = cfg.package.override { features = cfg.features; };
in lib.mkIf cfg.enable {
home.packages = [ pkg ];
xdg.configFile = {
"ironbar/config.json" = lib.mkIf (cfg.config != "") {
source = jsonFormat.generate "ironbar-config" cfg.config;
};
"ironbar/style.css" =
lib.mkIf (cfg.style != "") { text = cfg.style; };
};
systemd.user.services.ironbar = lib.mkIf cfg.systemd {
Unit = {
Description = "Systemd service for Ironbar";
Requires = [ "graphical-session.target" ];
};
Service = {
Type = "simple";
ExecStart = "${pkg}/bin/ironbar";
};
Install.WantedBy = with config.wayland.windowManager; [
(lib.mkIf hyprland.systemd.enable "hyprland-session.target")
(lib.mkIf sway.systemd.enable "sway-session.target")
(lib.mkIf river.systemd.enable "river-session.target")
];
};
}; };
}; };
}; };
};
nixConfig = { nixConfig = {
extra-substituters = ["https://jakestanger.cachix.org"]; extra-substituters = [ "https://cache.garnix.io" ];
extra-trusted-public-keys = ["jakestanger.cachix.org-1:VWJE7AWNe5/KOEvCQRxoE8UsI2Xs2nHULJ7TEjYm7mM="]; extra-trusted-public-keys =
[ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
}; };
} }

View file

@ -25,14 +25,23 @@
builderName ? "nix", builderName ? "nix",
builder ? {}, builder ? {},
}: let }: let
hasFeature = f: features == [ ] || builtins.elem f features;
basePkg = rec { basePkg = rec {
inherit version; inherit version;
pname = "ironbar"; pname = "ironbar";
src = builtins.path { src = builtins.path {
name = "ironbar"; name = "ironbar";
path = lib.cleanSource ../.; path = lib.cleanSource ../.;
}; };
nativeBuildInputs = [ pkg-config wrapGAppsHook gobject-introspection ];
nativeBuildInputs = [
pkg-config
wrapGAppsHook
gobject-introspection
];
buildInputs = [ buildInputs = [
gtk3 gtk3
@ -44,79 +53,77 @@
gnome.adwaita-icon-theme gnome.adwaita-icon-theme
hicolor-icon-theme hicolor-icon-theme
gsettings-desktop-schemas gsettings-desktop-schemas
libxkbcommon libxkbcommon ]
libpulseaudio ++ (if hasFeature "http" then [ openssl ] else [])
openssl ++ (if hasFeature "volume" then [ libpulseaudio ] else [])
luajit ++ (if hasFeature "cairo" then [ luajit ] else []);
];
propagatedBuildInputs = [ gtk3 ]; propagatedBuildInputs = [ gtk3 ];
lgi = luajitPackages.lgi; lgi = luajitPackages.lgi;
preFixup = '' gappsWrapperArgs = ''
gappsWrapperArgs+=(
# Thumbnailers # Thumbnailers
--prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share" --prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share"
--prefix XDG_DATA_DIRS : "${librsvg}/share" --prefix XDG_DATA_DIRS : "${librsvg}/share"
--prefix XDG_DATA_DIRS : "${webp-pixbuf-loader}/share" --prefix XDG_DATA_DIRS : "${webp-pixbuf-loader}/share"
--prefix XDG_DATA_DIRS : "${shared-mime-info}/share" --prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
# gtk-launch # gtk-launch
--suffix PATH : "${lib.makeBinPath [ gtk3 ]}" --suffix PATH : "${lib.makeBinPath [ gtk3 ]}"
''
# cairo + (if hasFeature "cairo" then ''
--prefix LUA_PATH : "./?.lua;${lgi}/share/lua/5.1/?.lua;${lgi}/share/lua/5.1/?/init.lua;${luajit}/share/lua/5.1/\?.lua;${luajit}/share/lua/5.1/?/init.lua" --prefix LUA_PATH : "./?.lua;${lgi}/share/lua/5.1/?.lua;${lgi}/share/lua/5.1/?/init.lua;${luajit}/share/lua/5.1/\?.lua;${luajit}/share/lua/5.1/?/init.lua"
--prefix LUA_CPATH : "./?.so;${lgi}/lib/lua/5.1/?.so;${luajit}/lib/lua/5.1/?.so;${luajit}/lib/lua/5.1/loadall.so" --prefix LUA_CPATH : "./?.so;${lgi}/lib/lua/5.1/?.so;${luajit}/lib/lua/5.1/?.so;${luajit}/lib/lua/5.1/loadall.so"
'' else "");
preFixup = ''
gappsWrapperArgs+=(
${gappsWrapperArgs}
) )
''; '';
passthru = { passthru = {
updateScript = gnome.updateScript { updateScript = gnome.updateScript {
packageName = pname; packageName = pname;
attrPath = "gnome.${pname}"; attrPath = "gnome.${pname}";
}; };
}; };
meta = with lib; { meta = with lib; {
homepage = "https://github.com/JakeStanger/ironbar"; homepage = "https://github.com/JakeStanger/ironbar";
description = "Customisable gtk-layer-shell wlroots/sway bar written in rust."; description =
"Customisable gtk-layer-shell wlroots/sway bar written in rust.";
license = licenses.mit; license = licenses.mit;
platforms = platforms.linux; platforms = platforms.linux;
mainProgram = "ironbar"; mainProgram = "ironbar";
}; };
}; };
flags = let flags = let
noDefault = noDefault = if features == [ ] then "" else "--no-default-features";
if features == []
then "" featuresStr = if features == [ ] then
else "--no-default-features"; ""
featuresStr = else
if features == [] ''-F "${builtins.concatStringsSep "," features}"'';
then ""
else ''-F "${builtins.concatStringsSep "," features}"''; in [ noDefault featuresStr ];
in [noDefault featuresStr]; in if builderName == "naersk" then
in builder.buildPackage (basePkg // { cargoBuildOptions = old: old ++ flags; })
if builderName == "naersk" else if builderName == "crane" then
then builder.buildPackage (basePkg // {
builder.buildPackage (basePkg cargoExtraArgs = builtins.concatStringsSep " " flags;
// { doCheck = false;
cargoBuildOptions = old: old ++ flags; })
}) else
else if builderName == "crane" rustPlatform.buildRustPackage (basePkg // {
then buildNoDefaultFeatures = features != [ ];
builder.buildPackage (basePkg
// { buildFeatures = features;
cargoExtraArgs = builtins.concatStringsSep " " flags; cargoDeps = rustPlatform.importCargoLock { lockFile = ../Cargo.lock; };
doCheck = false; cargoLock.lockFile = ../Cargo.lock;
}) cargoLock.outputHashes."stray-0.1.3" =
else "sha256-7mvsWZFmPWti9AiX67h6ZlWiVVRZRWIxq3pVaviOUtc=";
rustPlatform.buildRustPackage (basePkg })
// {
buildNoDefaultFeatures =
if features == []
then false
else true;
buildFeatures = features;
cargoDeps = rustPlatform.importCargoLock {lockFile = ../Cargo.lock;};
cargoLock.lockFile = ../Cargo.lock;
cargoLock.outputHashes."stray-0.1.3" = "sha256-7mvsWZFmPWti9AiX67h6ZlWiVVRZRWIxq3pVaviOUtc=";
})