Skip to content

Commit

Permalink
Configure formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
pltanton committed May 17, 2024
1 parent ce664fe commit 6974459
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
13 changes: 9 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

inputs.flakelight.url = "github:nix-community/flakelight";

outputs = inputs@{ flakelight, ... }: flakelight ./. {
devShell.packages = pkgs: with pkgs; [ go ];
homeModule = ./nix/hm-module.nix;
};
outputs = inputs @ {flakelight, ...}:
flakelight ./. {
devShell.packages = pkgs: with pkgs; [go alejandra dprint];
formatters = {
"*.yml" = "dprint fmt";
"*.md" = "dprint fmt";
"*.nix" = "alejandra";
};
};
}
31 changes: 17 additions & 14 deletions nix/hm-module.nix → nix/homeModule.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{ config, lib, pkgs, ... }:
with lib;
let
{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.programs.autobrowser;
configFile = pkgs.writeText "autobrowser.config"
configFile =
pkgs.writeText "autobrowser.config"
(builtins.concatStringsSep "\n" (
(lib.mapAttrsToList (k: v: "${k}:=${v}") cfg.variables) ++
cfg.rules ++
[ "${cfg.default}:fallback" ]
(lib.mapAttrsToList (k: v: "${k}:=${v}") cfg.variables)
++ cfg.rules
++ ["${cfg.default}:fallback"]
));
in
{
in {
options.programs.autobrowser = {
enable = lib.mkEnableOption "whenever to enable autobrowser as default browser";
package = mkPackageOption pkgs "autobrowser" { };
package = mkPackageOption pkgs "autobrowser" {};
variables = mkOption {
type = with lib.types; attrsOf str;
description = "Attribute set of variables";
default = { };
default = {};
};
rules = mkOption {
type = with lib.types; listOf str;
example = [ "firefox {}:app.class=telegram" "firefox -p work {}:url.regex='.*atlassian.org.*'" ];
example = ["firefox {}:app.class=telegram" "firefox -p work {}:url.regex='.*atlassian.org.*'"];
description = "List of rules";
};
default = mkOption {
Expand All @@ -33,7 +37,7 @@ in
config = mkIf cfg.enable {
home.packages = [
(pkgs.writeTextDir "share/applications/autobrowser.desktop"
(lib.generators.toINI { } {
(lib.generators.toINI {} {
"Desktop Entry" = {
Type = "Application";
Exec = "${cfg.package}/bin/autobrowser -config ${configFile} -url %u";
Expand All @@ -55,4 +59,3 @@ in
};
};
}

7 changes: 5 additions & 2 deletions nix/packages/_default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{ lib, buildGoModule }:
{
lib,
buildGoModule,
}:
buildGoModule {
pname = "autobrowser";
version = "0";
Expand All @@ -11,7 +14,7 @@ buildGoModule {
platforms = platforms.linux;
mainProgram = "autobrowser";
};
src = import ../src.nix { inherit lib; };
src = import ../src.nix {inherit lib;};

modRoot = "linux";
}
7 changes: 5 additions & 2 deletions nix/packages/common.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# This package is need for testing
{ lib, buildGoModule }:
{
lib,
buildGoModule,
}:
buildGoModule {
pname = "autobrowser-common";
version = "0";
vendorHash = null;
src = import ../src.nix { inherit lib; };
src = import ../src.nix {inherit lib;};

modRoot = "common";
}
9 changes: 5 additions & 4 deletions nix/src.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ lib }:
{lib}:
lib.cleanSourceWith {
filter = name: type:
let baseName = baseNameOf (toString name);
in !(lib.hasSuffix ".nix" baseName);
filter = name: type: let
baseName = baseNameOf (toString name);
in
!(lib.hasSuffix ".nix" baseName);
src = lib.cleanSource ../.;
}

0 comments on commit 6974459

Please sign in to comment.