Skip to content

Commit

Permalink
chore: add default nixos module
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwjackson committed May 20, 2024
1 parent a2abaf2 commit 8023a1e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 63 deletions.
67 changes: 4 additions & 63 deletions modules/nixos/default/default.nix
Original file line number Diff line number Diff line change
@@ -1,64 +1,5 @@
{
config,
inputs,
lib,
pkgs,
...
}: let
inherit (pkgs.stdenv.hostPlatform) system;
pname = "tmesh";

package = inputs.self.packages.${system}.${pname};
cfg = config.programs.${pname};
jsonConfig = builtins.toJSON cfg.settings;
jsonConfigFile = pkgs.writeText "config.json" jsonConfig;
in {
options.programs.${pname} = {
enable = lib.mkEnableOption "${pname}";

settings = lib.mkOption {
type = lib.types.attrs;
default = {};
description = "Configuration settings.";
};

package = lib.mkOption {
type = lib.types.package;
default = package;
description = "The package to use for ${pname}.";
};

tmeshServerTmuxConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Tmux configuration for tmesh server.";
};

tmeshTmuxConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Tmux configuration for tmesh.";
};
};

config = lib.mkIf cfg.enable {
environment.etc."${pname}/config.json".source = jsonConfigFile;

environment.etc."${pname}/tmesh-server.tmux.conf" = {
text = cfg.tmeshServerTmuxConfig;
mode = "0644";
};

environment.etc."${pname}/tmesh.tmux.conf" = {
text = cfg.tmeshTmuxConfig;
mode = "0644";
};

environment.systemPackages = [
(pkgs.writeScriptBin "${pname}" ''
#!${pkgs.stdenv.shell}
exec ${pkgs.lib.meta.getExe cfg.package} --config ${jsonConfigFile} "$@"
'')
];
};
{...}: {
import = [
../tmesh
];
}
64 changes: 64 additions & 0 deletions modules/nixos/tmesh/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
config,
inputs,
lib,
pkgs,
...
}: let
inherit (pkgs.stdenv.hostPlatform) system;
pname = "tmesh";

package = inputs.self.packages.${system}.${pname};
cfg = config.programs.${pname};
jsonConfig = builtins.toJSON cfg.settings;
jsonConfigFile = pkgs.writeText "config.json" jsonConfig;
in {
options.programs.${pname} = {
enable = lib.mkEnableOption "${pname}";

settings = lib.mkOption {
type = lib.types.attrs;
default = {};
description = "Configuration settings.";
};

package = lib.mkOption {
type = lib.types.package;
default = package;
description = "The package to use for ${pname}.";
};

tmeshServerTmuxConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Tmux configuration for tmesh server.";
};

tmeshTmuxConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Tmux configuration for tmesh.";
};
};

config = lib.mkIf cfg.enable {
environment.etc."${pname}/config.json".source = jsonConfigFile;

environment.etc."${pname}/tmesh-server.tmux.conf" = {
text = cfg.tmeshServerTmuxConfig;
mode = "0644";
};

environment.etc."${pname}/tmesh.tmux.conf" = {
text = cfg.tmeshTmuxConfig;
mode = "0644";
};

environment.systemPackages = [
(pkgs.writeScriptBin "${pname}" ''
#!${pkgs.stdenv.shell}
exec ${pkgs.lib.meta.getExe cfg.package} --config ${jsonConfigFile} "$@"
'')
];
};
}

0 comments on commit 8023a1e

Please sign in to comment.