ironbar/flake.nix

223 lines
6.3 KiB
Nix
Raw Normal View History

{
description = "Nix Flake for ironbar";
2024-04-17 23:43:46 +03:00
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
2024-04-17 23:43:46 +03:00
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-04-17 23:43:46 +03:00
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-04-17 23:43:46 +03:00
naersk.url = "github:nix-community/naersk";
};
2024-03-31 02:43:30 +03:00
2024-04-17 23:43:46 +03:00
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 = [ self.overlays.default rust-overlay.overlays.default ];
};
2024-04-17 23:43:46 +03:00
mkRustToolchain = pkgs:
pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
};
2024-04-17 23:43:46 +03:00
in {
overlays.default = final: prev:
let
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 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;
};
};
2024-04-17 23:43:46 +03:00
packages = genSystems (system:
let pkgs = pkgsFor system;
in (self.overlays.default pkgs pkgs) // {
default = self.packages.${system}.ironbar;
});
apps = genSystems (system:
let pkgs = pkgsFor system;
2024-04-18 00:04:19 +03:00
in rec {
2024-04-17 23:43:46 +03:00
ironbar = {
type = "app";
program = "${pkgs.ironbar}/bin/ironbar";
};
2024-04-18 00:04:19 +03:00
default = ironbar;
2024-04-17 23:43:46 +03:00
});
devShells = genSystems (system:
let
pkgs = pkgsFor system;
rust = mkRustToolchain pkgs;
in {
default = pkgs.mkShell {
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.";
};
2024-04-17 23:43:46 +03:00
systemd = lib.mkOption {
type = lib.types.bool;
default = pkgs.stdenv.isLinux;
description = "Whether to enable to systemd service for ironbar.";
};
2024-04-17 23:43:46 +03:00
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.";
};
};
2024-04-17 23:43:46 +03:00
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; };
};
2024-04-17 23:43:46 +03:00
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")
];
};
};
};
};
2024-04-17 23:43:46 +03:00
nixConfig = {
2024-04-17 23:43:46 +03:00
extra-substituters = [ "https://cache.garnix.io" ];
extra-trusted-public-keys =
[ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
};
}