- Add utils.readFile which reads a file and evaluates any nix in ${{null}}
brackets like that, returning a string. This should be a drop-in replacement
for builtins.readFile
- Add utils.interpolateFile which does the same as readFile but also writes to
the store and returns a store path for the new file. This should be a drop-in
wrapper for a path
- Use utils.interpolateFile on the xmonad config file
- Use a relative file path contained in nix interpolation brackets in the xmonad
config file
- Use package paths inside the included file (all included paths are also
interpolated)
- Update xmonad to have better volume change support
- Update xmonad to have better multi-display support (actually start polybar,
display different colors for second displays)
development
parent
1eece6e167
commit
3a9a2b1ee0
@ -0,0 +1,30 @@
|
||||
#!${{pkgs.python3}}/bin/python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
args = sys.argv
|
||||
|
||||
device_argument = "--default-source" if "-i" in args else ""
|
||||
|
||||
control_argument = ""
|
||||
control_argument += "-i" if "-u" in args else ""
|
||||
control_argument += "-d" if "-d" in args else ""
|
||||
control_argument += "-t" if "-m" in args else " 5"
|
||||
|
||||
os.system(
|
||||
f"${{pkgs.pamixer}}/bin/pamixer {device_argument} {control_argument} --set-limit 150"
|
||||
)
|
||||
mute_char = (
|
||||
"!"
|
||||
if subprocess.getoutput(f"${{pkgs.pamixer}}/bin/pamixer {device_argument} --get-mute")
|
||||
== "true"
|
||||
else ""
|
||||
)
|
||||
volume = subprocess.getoutput(f"${{pkgs.pamixer}}/bin/pamixer {device_argument} --get-volume")
|
||||
|
||||
socket_path = f"{os.environ['XDG_RUNTIME_DIR']}/xob.sock"
|
||||
|
||||
with open(socket_path, "w") as socket:
|
||||
socket.write(f"{volume}{mute_char}\n")
|
||||
@ -1,12 +1,27 @@
|
||||
lib:
|
||||
lib.pipe ./. [
|
||||
(import ./nixFilesInWithName.nix lib)
|
||||
(builtins.map ({ name
|
||||
, path
|
||||
,
|
||||
}: {
|
||||
name = lib.removeSuffix ".nix" name;
|
||||
value = import path lib;
|
||||
}))
|
||||
builtins.listToAttrs
|
||||
]
|
||||
pkgs_or_lib:
|
||||
let
|
||||
is_pkgs = pkgs_or_lib ? lib;
|
||||
lib = if is_pkgs then pkgs_or_lib.lib else pkgs_or_lib;
|
||||
utils = lib.pipe ./. [
|
||||
(import ./nixFilesInWithName.nix lib)
|
||||
(builtins.map (file: rec {
|
||||
name = lib.removeSuffix ".nix" file.name;
|
||||
func = import file.path;
|
||||
accepts_pkgs = builtins.hasAttr "pkgs" (builtins.functionArgs func);
|
||||
value =
|
||||
if accepts_pkgs then
|
||||
func
|
||||
(builtins.intersectAttrs (builtins.functionArgs func) {
|
||||
inherit
|
||||
lib utils; pkgs = pkgs_or_lib;
|
||||
})
|
||||
else if is_pkgs
|
||||
then func lib
|
||||
else
|
||||
func pkgs_or_lib;
|
||||
include = file.name != "default.nix" && (!accepts_pkgs || is_pkgs);
|
||||
}))
|
||||
(builtins.filter (utility: utility.include))
|
||||
builtins.listToAttrs
|
||||
];
|
||||
in utils
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
{ utils, pkgs }: file: pkgs.lib.pipe file [
|
||||
utils.readFile
|
||||
(text: pkgs.writeTextFile {
|
||||
name = builtins.baseNameOf file;
|
||||
inherit text;
|
||||
executable = true; # TODO: write and use utils.isExecutable
|
||||
})
|
||||
]
|
||||
@ -0,0 +1,42 @@
|
||||
{ pkgs, utils }:
|
||||
let
|
||||
lib = pkgs.lib;
|
||||
in
|
||||
file: lib.pipe file [
|
||||
builtins.readFile
|
||||
(builtins.split "\\\$\\{\\{([^}]*)}}")
|
||||
(map (part:
|
||||
if builtins.typeOf part == "string"
|
||||
then part
|
||||
else
|
||||
import
|
||||
(
|
||||
(
|
||||
pkgs.writeText "generated.nix" ("pkgs: lib: " + (builtins.elemAt part 0))
|
||||
).outPath
|
||||
)
|
||||
pkgs
|
||||
lib
|
||||
))
|
||||
(map (part:
|
||||
if builtins.typeOf part == "string" then part
|
||||
else if builtins.typeOf part == "path" then
|
||||
let
|
||||
stringified = toString part;
|
||||
in
|
||||
builtins.toString (utils.interpolateFile (
|
||||
file + "/.." + (builtins.substring
|
||||
(builtins.stringLength "/nix/store")
|
||||
(builtins.stringLength
|
||||
stringified)
|
||||
stringified)
|
||||
# ^ Somewhat of a hack, works because we know that the file path
|
||||
# is a text file (i.e. not a directory) as we read it earlier and
|
||||
# relative paths end up in /nix/store due to the writeText. Absolute
|
||||
# paths are not supported
|
||||
))
|
||||
else
|
||||
toString part
|
||||
))
|
||||
(builtins.concatStringsSep "")
|
||||
]
|
||||
Loading…
Reference in new issue