Skip to content

Commit

Permalink
feat: add nix flake support
Browse files Browse the repository at this point in the history
* Add nix flake

* Fix readme syntax issue

* Format nix flake

* ci(build): add nix flake support

* ci(build): fix workflow_dispatch casing

* ci(build): fix nix flake lock update job

* ci: add nix flake lock update timer job

old method didn't work

* improve example and add cachix info

Co-authored-by: Jake Stanger <[email protected]>
  • Loading branch information
yavko and JakeStanger authored Nov 26, 2022
1 parent 47420d8 commit a3f90ad
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build

on:
workflow_dispatch:
push:
branches: [ "master" ]
pull_request:
Expand Down Expand Up @@ -35,3 +36,25 @@ jobs:

- name: Check formatting
run: cargo fmt --check



build-nix:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: cachix/install-nix-action@v17
with:
install_url: https://nixos.org/nix/install
extra_nix_config: |
auto-optimise-store = true
experimental-features = nix-command flakes
- uses: cachix/cachix-action@v11
with:
name: jakestanger
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'

- run: nix build --print-build-logs
27 changes: 27 additions & 0 deletions .github/workflows/update-nix-flake-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: update-nix-flake-lock
on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: '0 0 1 * *' # first day of every month

jobs:
update-nix-flake-lock:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Nix
uses: cachix/install-nix-action@v16
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@vX
with:
pr-title: "Update flake.lock" # Title of PR to be created
pr-labels: | # Labels to be set on the PR
dependencies
automated
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,49 @@ yay -S ironbar-git

[aur package](https://aur.archlinux.org/packages/ironbar-git)

### Nix Flake

#### Example
Here is an example nix flake that uses ironbar, this is just a
proof of concept, please adapt it to your config

```nix
{
# Add the ironbar flake input
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.ironbar = {
url = "github:JakeStanger/ironbar";
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.hm = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs: {
homeManagerConfigurations."USER@HOSTNAME" = inputs.hm.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
# And add the home-manager module
inputs.ironbar.homeManagerModules.default
{
# And configure
programs.ironbar = {
enable = true;
config = {};
style = "";
};
}
];
};
};
}
```

#### Binary Caching
There is also a cachix cache at `https://app.cachix.org/cache/jakestanger`
incase you don't want to compile ironbar!

### Source

```sh
Expand Down Expand Up @@ -86,4 +129,4 @@ Please check [here](https://github.com/JakeStanger/ironbar/blob/master/CONTRIBUT

- [Waybar](https://github.com/Alexays/Waybar) - A lot of the initial inspiration, and a pretty great bar.
- [Rustbar](https://github.com/zeroeightysix/rustbar) - Served as a good demo for writing a basic GTK bar in Rust
- [Smithay Client Toolkit](https://github.com/Smithay/client-toolkit) - Essential in being able to communicate to Wayland
- [Smithay Client Toolkit](https://github.com/Smithay/client-toolkit) - Essential in being able to communicate to Wayland
64 changes: 64 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 142 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
description = "Nix Flake for ironbar";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
#nci.url = "github:yusdacra/nix-cargo-integration";
#nci.inputs.nixpkgs.follows = "nixpkgs";
#nci.inputs.rust-overlay.follows = "rust-overlay";
};
outputs = {
self,
nixpkgs,
rust-overlay,
...
}: 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
];
};
mkRustToolchain = pkgs: pkgs.rust-bin.stable.latest.default;
in {
overlays.default = final: prev: let
rust = mkRustToolchain final;

rustPlatform = prev.makeRustPlatform {
cargo = rust;
rustc = rust;
};
in {
ironbar = rustPlatform.buildRustPackage {
pname = "ironbar";
version = self.rev or "dirty";
src = builtins.path {
name = "ironbar";
path = prev.lib.cleanSource ./.;
};
cargoDeps = rustPlatform.importCargoLock {lockFile = ./Cargo.lock;};
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = with prev; [pkg-config];
buildInputs = with prev; [gtk3 gdk-pixbuf gtk-layer-shell libxkbcommon];
};
};
packages = genSystems (
system: let
pkgs = pkgsFor system;
in
(self.overlays.default pkgs pkgs)
// {
default = self.packages.${system}.ironbar;
}
);
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
];

RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
};
});
homeManagerModules.default = {
config,
lib,
pkgs,
...
}: let
cfg = config.programs.ironbar;
defaultIronbarPackage = self.packages.${pkgs.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";
};
};
config = lib.mkIf cfg.enable {
home.packages = [cfg.package];
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 = "${cfg.package}/bin/ironbar";
};
Install.WantedBy = [
(lib.mkIf config.wayland.windowManager.hyprland.systemdIntegration "hyprland-session.target")
(lib.mkIf config.wayland.windowManager.sway.systemdIntegration "sway-session.target")
];
};
};
};
};
}

0 comments on commit a3f90ad

Please sign in to comment.