Add a home-manager nix module (#11)

Add a home-manager module to simplify installation and config management
on nix systems. This greatly reduces the setup time and
makes it integrate better with other programs on nix, mainly Hyprland
which this module is based on.
This commit is contained in:
Edvin Källström 2023-03-13 21:00:08 +01:00 committed by GitHub
parent 00caccc459
commit 3b6bafe91a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 10 deletions

View file

@ -32,7 +32,10 @@ You can install it e.g.: with yay
```yay -S gbar-git``` ```yay -S gbar-git```
## Building and installation (Nix) ## Building and installation (Nix)
You can install the nix flake in a number of ways, either through your system/home flake or simply running nix build to get the binary directly. If you choose the Nix/NixOS installation there are a couple of ways to do it but they all require you to have flakes enabled.
- Building it seperately and just running the binary, run nix build in the directory and use the binary from ./result/bin
- Import the flake to inputs and then add `gBar.defaultPackage.x86_64-linux` to either environment.systemPackages or home.packages.
- Use the home manager module. This is done by, as in the previous way, importing the flake and then adding `gBar.homeManagerModules.x86_64-linux.default` into your home-manager imorts section. This exposes the option programs.gBar to home manager and you can look at the module file to see available options.
## Running gBar ## Running gBar
*Open bar on monitor 0* *Open bar on monitor 0*

View file

@ -13,7 +13,6 @@
gbar = (with pkgs; stdenv.mkDerivation { gbar = (with pkgs; stdenv.mkDerivation {
name = "gbar"; name = "gbar";
src = ./.; src = ./.;
nativeBuildInputs = [ nativeBuildInputs = [
@ -31,21 +30,15 @@
gtk-layer-shell gtk-layer-shell
libpulseaudio libpulseaudio
]; ];
}); });
in rec { in {
defaultApp = flake-utils.lib.mkApp {
drv = defaultPackage;
};
defaultPackage = gbar; defaultPackage = gbar;
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
buildInputs = [ buildInputs = [
gbar gbar
]; ];
}; };
homeManagerModules.default = import ./module.nix self;
} }
); );
} }

54
module.nix Normal file
View file

@ -0,0 +1,54 @@
# Based on Hyprland's home-manager and NixOS module
self:
{ config
, lib
, pkgs
, ...
}: let
cfg = config.programs.gBar;
defaultGBarPackage = self.defaultPackage.x86_64-linux;
in {
options.programs.gBar = {
enable = lib.mkEnableOption "Wether to enable gBar, a blazingly fast statusbar written in c++";
package = lib.mkOption {
type = lib.types.nullOr lib.types.package;
default = defaultGBarPackage;
defaultText = lib.literalExpression "<gBar flake>.packages.<system>.default";
example = lib.literalExpression "<gBar flake>.packages.<system>.default.override { }";
description = ''
gBar package to use.
'';
};
extraConfig = lib.mkOption {
type = lib.types.nullOr lib.types.lines;
default = null;
description = ''
Configuration to write to ~/.config/gBar/config, if none nothing happens
'';
};
extraCSS = lib.mkOption {
type = lib.types.nullOr lib.types.lines;
default = null;
description = ''
Configuration to write to ~/.config/gBar/config, if none nothing happens
'';
};
};
config = lib.mkIf cfg.enable {
home.packages = lib.optional (cfg.package != null) cfg.package;
xdg.configFile."gBar/config" = lib.mkIf (cfg.extraConfig != null) {
text = cfg.extraConfig;
};
xdg.configFile."gBar/style.css" = lib.mkIf (cfg.extraCSS != null) {
text = cfg.extraCSS;
};
};
}