1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-16 22:31:03 +02:00

chore(nix): simplify packaging and outputs

This commit is contained in:
atagen 2025-05-29 23:35:29 +10:00
parent 098df1ee26
commit 3b80b43582
7 changed files with 187 additions and 311 deletions

12
default.nix Normal file
View file

@ -0,0 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
) {src = ./.;}).defaultNix

89
flake.lock generated
View file

@ -1,20 +1,5 @@
{ {
"nodes": { "nodes": {
"crane": {
"locked": {
"lastModified": 1748047550,
"narHash": "sha256-t0qLLqb4C1rdtiY8IFRH5KIapTY/n3Lqt57AmxEv9mk=",
"owner": "ipetkov",
"repo": "crane",
"rev": "b718a78696060df6280196a6f992d04c87a16aef",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-compat": { "flake-compat": {
"locked": { "locked": {
"lastModified": 1747046372, "lastModified": 1747046372,
@ -30,24 +15,6 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1743550720,
"narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "c621e8422220273271f52058f618c94e405bb0f5",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"naersk": { "naersk": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
@ -66,6 +33,21 @@
"type": "github" "type": "github"
} }
}, },
"nix-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"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1748662220, "lastModified": 1748662220,
@ -82,21 +64,6 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib": {
"locked": {
"lastModified": 1743296961,
"narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1748460289, "lastModified": 1748460289,
@ -115,32 +82,10 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"crane": "crane",
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"naersk": "naersk", "naersk": "naersk",
"nixpkgs": "nixpkgs_2", "nix-systems": "nix-systems",
"rust-overlay": "rust-overlay" "nixpkgs": "nixpkgs_2"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1748658947,
"narHash": "sha256-F+nGITu6D7RswJlm8qCuU1PCuOSgDeAqaDKWW1n1jmQ=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "fc82ce758cc5df6a6d5d24e75710321cdbdc787a",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
} }
} }
}, },

153
flake.nix
View file

@ -3,134 +3,85 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-compat.url = "github:edolstra/flake-compat"; flake-compat.url = "github:edolstra/flake-compat";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
naersk.url = "github:nix-community/naersk"; naersk.url = "github:nix-community/naersk";
nix-systems.url = "github:nix-systems/default-linux";
}; };
outputs = inputs @ { outputs = {
self, self,
nixpkgs, nixpkgs,
rust-overlay,
crane,
naersk, naersk,
flake-parts, nix-systems,
... ...
}: }: let
flake-parts.lib.mkFlake {inherit inputs;} (let forAllSystems = function:
mkRustToolchain = pkgs: nixpkgs.lib.genAttrs (import nix-systems) (system: function nixpkgs.legacyPackages.${system});
pkgs.rust-bin.stable.latest.default.override { mkDate = longDate: (nixpkgs.lib.concatStringsSep "-" [
extensions = ["rust-src"];
};
in {
systems = [
"aarch64-linux"
"x86_64-linux"
];
imports = [
./nix/devshell.nix
];
perSystem = {
system,
config,
pkgs,
lib,
...
}: {
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
rust-overlay.overlays.default
];
};
# Packages
packages = {
ironbar = pkgs.ironbar;
default = pkgs.ironbar;
};
# Apps
apps = {
ironbar = {
type = "app";
program = lib.getExe pkgs.ironbar;
};
default = config.apps.ironbar;
};
};
flake = {
overlays.default = final: prev: let
inherit (nixpkgs) lib;
rust = mkRustToolchain final;
craneLib = (crane.mkLib final).overrideToolchain rust;
naersk' = prev.callPackage naersk {
cargo = rust;
rustc = rust;
};
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 0 4 longDate)
(builtins.substring 4 2 longDate) (builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate) (builtins.substring 6 2 longDate)
]); ]);
builder = "naersk";
in { in {
# Devshell
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = builtins.attrValues {
inherit
(pkgs)
cargo
clippy
rustfmt
gtk3
gtk-layer-shell
gcc
openssl
libdbusmenu-gtk3
libpulseaudio
libinput
libevdev
luajit
;
inherit (pkgs.luajitPackages) lgi;
};
nativeBuildInputs = [
pkgs.pkg-config
];
};
});
# Packages
packages = forAllSystems (pkgs: {
ironbar = let ironbar = let
props = builtins.fromTOML (builtins.readFile ./Cargo.toml);
version = version =
props.package.version props.package.version
+ "+date=" + "+date="
+ (mkDate (self.lastModifiedDate or "19700101")) + (mkDate (self.lastModifiedDate or "19700101"))
+ "_" + "_"
+ (self.shortRev or "dirty"); + (self.shortRev or "dirty");
naersk' = pkgs.callPackage naersk {};
in in
if builder == "crane" pkgs.callPackage ./nix/package.nix {
then
prev.callPackage ./nix/package.nix {
inherit version; inherit version;
inherit rustPlatform; naersk = naersk';
builderName = builder;
builder = craneLib;
}
else if builder == "naersk"
then
prev.callPackage ./nix/package.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
builder = naersk';
}
else
prev.callPackage ./nix/package.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
}; };
default = self.packages.${pkgs.hostPlatform.system}.ironbar;
});
# Apps
apps = forAllSystems (pkgs: {
ironbar = {
type = "app";
program = pkgs.lib.getExe self.packages.${pkgs.hostPlatform.system}.ironbar;
}; };
default = self.apps.ironbar;
});
homeManagerModules.default = import ./nix/module.nix self; homeManagerModules.default = import ./nix/module.nix self;
}; };
});
nixConfig = { nixConfig = {
extra-substituters = ["https://cache.garnix.io"]; extra-substituters = ["https://cache.garnix.io"];

View file

@ -1,25 +0,0 @@
{
perSystem = { pkgs, ... }: {
devShells.default = pkgs.mkShell {
packages = with pkgs; [
cargo
clippy
rustfmt
gtk3
gtk-layer-shell
gcc
openssl
libdbusmenu-gtk3
libpulseaudio
libinput
libevdev
luajit
luajitPackages.lgi
];
nativeBuildInputs = with pkgs; [
pkg-config
];
};
};
}

View file

@ -7,57 +7,65 @@ self: {
cfg = config.programs.ironbar; cfg = config.programs.ironbar;
defaultIronbarPackage = self.packages.${pkgs.hostPlatform.system}.default; defaultIronbarPackage = self.packages.${pkgs.hostPlatform.system}.default;
jsonFormat = pkgs.formats.json {}; jsonFormat = pkgs.formats.json {};
inherit
(lib)
types
mkOption
mkEnableOption
mkIf
getExe
;
in { in {
options.programs.ironbar = { options.programs.ironbar = {
enable = lib.mkEnableOption "ironbar status bar"; enable = mkEnableOption "ironbar status bar";
package = lib.mkOption { package = mkOption {
type = with lib.types; package; type = types.package;
default = defaultIronbarPackage; default = defaultIronbarPackage;
apply = pkg: pkg.override {features = cfg.features;}; apply = pkg: pkg.override {features = cfg.features;};
description = "The package for ironbar to use."; description = "The package for ironbar to use.";
}; };
systemd = lib.mkEnableOption "systemd service for ironbar."; systemd = mkEnableOption "systemd service for ironbar.";
style = lib.mkOption { style = mkOption {
type = lib.types.either (lib.types.lines) (lib.types.path); type = types.either (types.lines) (types.path);
default = ""; default = "";
description = "The stylesheet to apply to ironbar."; description = "The stylesheet to apply to ironbar.";
}; };
config = lib.mkOption { config = mkOption {
type = jsonFormat.type; type = jsonFormat.type;
default = {}; default = {};
description = "The config to pass to ironbar."; description = "The config to pass to ironbar.";
}; };
features = lib.mkOption { features = mkOption {
type = lib.types.listOf lib.types.nonEmptyStr; type = types.listOf types.nonEmptyStr;
default = []; default = [];
description = "The features to be used."; description = "The features to be used.";
}; };
}; };
config = lib.mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ home.packages = [
cfg.package cfg.package
]; ];
xdg.configFile = { xdg.configFile = {
"ironbar/config.json" = lib.mkIf (cfg.config != "") { "ironbar/config.json" = mkIf (cfg.config != "") {
onChange = "${lib.getExe cfg.package} reload"; onChange = "${getExe cfg.package} reload";
source = jsonFormat.generate "ironbar-config" cfg.config; source = jsonFormat.generate "ironbar-config" cfg.config;
}; };
"ironbar/style.css" = lib.mkIf (cfg.style != "") ( "ironbar/style.css" = mkIf (cfg.style != "") (
if builtins.isPath cfg.style || lib.isStorePath cfg.style if builtins.isPath cfg.style || lib.isStorePath cfg.style
then {source = cfg.style;} then {source = cfg.style;}
else {text = cfg.style;} else {text = cfg.style;}
); );
}; };
systemd.user.services.ironbar = lib.mkIf cfg.systemd { systemd.user.services.ironbar = mkIf cfg.systemd {
Unit = { Unit = {
Description = "Systemd service for Ironbar"; Description = "Systemd service for Ironbar";
Documentation = "https://github.com/JakeStanger/ironbar"; Documentation = "https://github.com/JakeStanger/ironbar";
@ -70,8 +78,8 @@ in {
}; };
Service = { Service = {
ExecReload = "${lib.getExe cfg.package} reload"; ExecReload = "${getExe cfg.package} reload";
ExecStart = "${lib.getExe cfg.package}"; ExecStart = "${getExe cfg.package}";
KillMode = "mixed"; KillMode = "mixed";
Restart = "on-failure"; Restart = "on-failure";
}; };
@ -79,9 +87,9 @@ in {
Install.WantedBy = [ Install.WantedBy = [
config.wayland.systemd.target config.wayland.systemd.target
"tray.target" "tray.target"
(lib.mkIf config.wayland.windowManager.hyprland.enable "hyprland-session.target") (mkIf config.wayland.windowManager.hyprland.enable "hyprland-session.target")
(lib.mkIf config.wayland.windowManager.sway.enable "sway-session.target") (mkIf config.wayland.windowManager.sway.enable "sway-session.target")
(lib.mkIf config.wayland.windowManager.river.enable "river-session.target") (mkIf config.wayland.windowManager.river.enable "river-session.target")
]; ];
}; };
}; };

View file

@ -23,16 +23,44 @@
installShellFiles, installShellFiles,
adwaita-icon-theme, adwaita-icon-theme,
hicolor-icon-theme, hicolor-icon-theme,
rustPlatform,
lib, lib,
version ? "git", version ? "git",
features ? [], features ? [],
builderName ? "nix", naersk,
builder ? {},
}: let }: let
hasFeature = f: features == [] || builtins.elem f features; hasFeature = f: features == [] || builtins.elem f features;
flags = let
noDefault =
if features == []
then ""
else "--no-default-features";
basePkg = rec { featuresStr =
if features == []
then ""
else ''-F "${builtins.concatStringsSep "," features}"'';
in [
noDefault
featuresStr
];
lgi = luajitPackages.lgi;
gappsWrapperArgs =
''
# Thumbnailers
--prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share"
--prefix XDG_DATA_DIRS : "${librsvg}/share"
--prefix XDG_DATA_DIRS : "${webp-pixbuf-loader}/share"
--prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
# gtk-launch
--suffix PATH : "${lib.makeBinPath [gtk3]}"
''
+ lib.optionalString (hasFeature "cairo") ''
--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"
'';
in
naersk.buildPackage {
inherit version; inherit version;
pname = "ironbar"; pname = "ironbar";
@ -48,14 +76,17 @@
ideRelated = fs.unions [ ideRelated = fs.unions [
(lib.path.append root ".idea") (lib.path.append root ".idea")
]; ];
in fs.toSource { in
fs.toSource {
inherit root; inherit root;
# NOTE: can possibly filter out more # NOTE: can possibly filter out more
fileset = fs.difference root (fs.unions [ fileset = fs.difference root (
fs.unions [
nixRelated nixRelated
cicdRelated cicdRelated
ideRelated ideRelated
]); ]
);
}; };
nativeBuildInputs = [ nativeBuildInputs = [
@ -82,27 +113,14 @@
++ lib.optionals (hasFeature "tray") [libdbusmenu-gtk3] ++ lib.optionals (hasFeature "tray") [libdbusmenu-gtk3]
++ lib.optionals (hasFeature "volume") [libpulseaudio] ++ lib.optionals (hasFeature "volume") [libpulseaudio]
++ lib.optionals (hasFeature "cairo") [luajit] ++ lib.optionals (hasFeature "cairo") [luajit]
++ lib.optionals (hasFeature "keyboard") [libinput libevdev]; ++ lib.optionals (hasFeature "keyboard") [
libinput
libevdev
];
propagatedBuildInputs = [gtk3]; propagatedBuildInputs = [gtk3];
lgi = luajitPackages.lgi; cargoBuildOptions = old: old ++ flags;
gappsWrapperArgs =
''
# Thumbnailers
--prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share"
--prefix XDG_DATA_DIRS : "${librsvg}/share"
--prefix XDG_DATA_DIRS : "${webp-pixbuf-loader}/share"
--prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
# gtk-launch
--suffix PATH : "${lib.makeBinPath [gtk3]}"
''
+ lib.optionalString (hasFeature "cairo") ''
--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"
'';
preFixup = '' preFixup = ''
gappsWrapperArgs+=( gappsWrapperArgs+=(
@ -119,48 +137,16 @@
passthru = { passthru = {
updateScript = gnome.updateScript { updateScript = gnome.updateScript {
packageName = pname; packageName = "ironbar";
attrPath = "gnome.${pname}"; attrPath = "gnome.ironbar";
}; };
}; };
meta = with lib; { meta = {
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 = lib.licenses.mit;
platforms = platforms.linux; platforms = lib.platforms.linux;
mainProgram = "ironbar"; mainProgram = "ironbar";
}; };
}; }
flags = let
noDefault =
if features == []
then ""
else "--no-default-features";
featuresStr =
if features == []
then ""
else ''-F "${builtins.concatStringsSep "," features}"'';
in [noDefault featuresStr];
in
if builderName == "naersk"
then builder.buildPackage (basePkg // {cargoBuildOptions = old: old ++ flags;})
else if builderName == "crane"
then
builder.buildPackage (basePkg
// {
cargoExtraArgs = builtins.concatStringsSep " " flags;
doCheck = false;
})
else
rustPlatform.buildRustPackage (basePkg
// {
buildNoDefaultFeatures = features != [];
buildFeatures = features;
cargoDeps = rustPlatform.importCargoLock {lockFile = ../Cargo.lock;};
cargoLock.lockFile = ../Cargo.lock;
cargoLock.outputHashes."stray-0.1.3" = "sha256-7mvsWZFmPWti9AiX67h6ZlWiVVRZRWIxq3pVaviOUtc=";
})

View file

@ -1,13 +1,12 @@
(import (import (
(
let let
lock = builtins.fromJSON (builtins.readFile ./flake.lock); lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat; nodeName = lock.nodes.root.inputs.flake-compat;
in in
fetchTarball { fetchTarball {
url = lock.nodes.${nodeName}.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz"; url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash; sha256 = lock.nodes.${nodeName}.locked.narHash;
} }
) ) {src = ./.;}).shellNix
{ src = ./.; }
).shellNix