From 3b6bafe91a64f272777a372f567092be98b562ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvin=20K=C3=A4llstr=C3=B6m?= <84442052+Eken-beep@users.noreply.github.com> Date: Mon, 13 Mar 2023 21:00:08 +0100 Subject: [PATCH] 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. --- README.md | 5 ++++- flake.nix | 11 ++--------- module.nix | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 module.nix diff --git a/README.md b/README.md index 3598689..768a90d 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,10 @@ You can install it e.g.: with yay ```yay -S gbar-git``` ## 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 *Open bar on monitor 0* diff --git a/flake.nix b/flake.nix index eaae0b2..b58f0bd 100644 --- a/flake.nix +++ b/flake.nix @@ -13,7 +13,6 @@ gbar = (with pkgs; stdenv.mkDerivation { name = "gbar"; - src = ./.; nativeBuildInputs = [ @@ -31,21 +30,15 @@ gtk-layer-shell libpulseaudio ]; - - }); - in rec { - defaultApp = flake-utils.lib.mkApp { - drv = defaultPackage; - }; + in { defaultPackage = gbar; devShell = pkgs.mkShell { buildInputs = [ gbar ]; }; + homeManagerModules.default = import ./module.nix self; } - ); } - diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..5ff1c0a --- /dev/null +++ b/module.nix @@ -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 ".packages..default"; + example = lib.literalExpression ".packages..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; + }; + }; +}