-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose namespaced lib on pkgs #155
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm not clear on the benefit here. Can you perhaps give a good example? |
Hm, ok. I'll try to explain myself better:
show me the codecommit af904bd2818c7f30906a1ed91695feb9cbf0300c
Author: David Arnold <[email protected]>
Date: Mon Mar 1 15:13:28 2021 -0500
readd: plut packages and library functions
diff --git a/lib/default.nix b/lib/default.nix
index 74e74cf..4812bbd 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -229,4 +229,7 @@ in
})
{ }
packagesNames;
+
+ # Utilities
+ mkPlutoApp = pkgs.callPackage ./nixos-lib/mkPlutoApp { };
}
diff --git a/lib/nixos-lib/mkPlutoApp/default.nix b/lib/nixos-lib/mkPlutoApp/default.nix
new file mode 100644
index 0000000..84616ef
--- /dev/null
+++ b/lib/nixos-lib/mkPlutoApp/default.nix
@@ -0,0 +1,15 @@
+{ pkgs, writers, ... }:
+{ name, cmd, workspace, baseKey }:
+let
+ isWorkspaceEmpty = writers.writePython3 "is-workspace-empty" {
+ libraries = [ pkgs.python3Packages.i3ipc ];
+ } (builtins.readFile ./is-workspace-empty.py);
+
+ ws = builtins.toString workspace;
+in
+''
+
+ # ${name}
+ #bindsym ${baseKey}+${ws} workspace ${ws}; exec ${cmd}
+ bindsym ${baseKey}+${ws} workspace ${ws}; exec bash -c "${isWorkspaceEmpty} && ${cmd}"
+''
diff --git a/lib/nixos-lib/mkPlutoApp/is-workspace-empty.py b/lib/nixos-lib/mkPlutoApp/is-workspace-empty.py
new file mode 100644
index 0000000..915c88a
--- /dev/null
+++ b/lib/nixos-lib/mkPlutoApp/is-workspace-empty.py
@@ -0,0 +1,16 @@
+# returns 0/1 if current workspace is empty/non-empty
+
+import i3ipc
+
+i3 = i3ipc.Connection()
+tree = i3.get_tree()
+
+
+def current_workspace():
+ return tree.find_focused().workspace()
+
+
+if current_workspace().leaves():
+ print("Error current workspace is not empty")
+ exit(1)
+exit(0) Note: # /modules/pluto/programs/ethercalc.nix
{ config, lib, myLib, pkgs, ... }:
with lib;
let
cfg = config.pluto.programs.${name};
name = "ethercalc";
url = "https://ethercalc.org/";
in
{
##### interface
options.pluto.programs.${name} = {
enable = mkEnableOption name;
workspace = mkOption {
type = with types; nullOr int;
};
};
##### implementation
config.services.xserver.windowManager.i3.extraConfig = mkIf cfg.enable [
(
myLib.mkPlutoApp {
inherit name;
cmd = "${pkgs.surf}/bin/surf ${url}";
workspace = cfg.workspace;
baseKey = config.pluto.keymap.open;
}
)
];
} |
Are you aware that lib is already available via |
Ah ok, I was already mislead on the first point. 👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm not 100% sure if the local library is already supercharged on
lib
, but also for sharing as an overlay I think a name spaced identifier is a better solution in any case.Currently, I adopted
myLib
, but that should probably becomemyname.lib
so that I can use library functions more cleanly from fellow devossers. Though, I didn't want to propose that together with this PR, since it is an independent change / discussion.