Open bphenriques opened 1 year ago
What is the recommended way to use with NixOS?
Using home-manager, one can do:
xdg.configFile = {
"input-remapper/config.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/modules/input-remapper/config.json";
"input-remapper/presets/Logitech G305/Media.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/modules/input-remapper/Media.json";
};
Trying my best to follow your dot files. As I am new to nix and programming as a whole, I am lost.
In your peripheral.nix are other attributes being referenced other than what is at the top of the file? The note "ensure config is within home-manager's context" I am not sure exactly what home = { config, ... }: is doing.
Does home reference /home/default.nix and DOTFILES_LOCATION= ?
I need to get input-remapper up and running on my new system. I have become very reliant on these customizations.
In your peripheral.nix are other attributes being referenced other than what is at the top of the file? The note "ensure config is within home-manager's context" I am not sure exactly what home = { config, ... }: is doing.
Will do my best to break it down, I am not super proficient with some concepts but I can try to help.
Does home reference /home/default.nix and DOTFILES_LOCATION= ?
home
refers to an alias that I created:
{
imports = [
(mkAliasOptionModule ["home"] ["home-manager" "users" "bphenriques"])
];
Let me try to break it down:
{ config, ... }:
{
...
home = { config, ... }: {
xdg.configFile = {
"input-remapper/config.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/config.json";
"input-remapper/presets/Logitech G305/Media.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/Media.json";
};
};
}
home
is actually a alias to my user's home:
{
imports = [
(mkAliasOptionModule ["home"] ["home-manager" "users" "bphenriques"])
];
Let's re-write without the alias:
{ config, ... }:
{
...
home-manager.users.bphenriques = { config, ... }: {
xdg.configFile = {
"input-remapper/config.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/config.json";
"input-remapper/presets/Logitech G305/Media.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/Media.json";
};
};
}
Now, lets focus on this bit:
home-manager.users.bphenriques = { config, ... }: {
home-manager
typically receives a set ({ key = value; key2 = value2 }
) but it also supports receiving a function. Note that, the current peripherals.nix
file is a NixOS configuration, therefore the config
on the top of the file represents a NixOS configuration, not a home-manager one. Therefore the following would fail because config.lib.file.mkOutOfStoreSymlink
is not defined in NixOS:
{ config, ... }:
{
...
# Fails because `config` refers to NixOS where `config.lib.file.mkOutOfStoreSymlink` is not defined
home-manager.users.bphenriques = {
xdg.configFile = {
"input-remapper/config.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/config.json";
"input-remapper/presets/Logitech G305/Media.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/Media.json";
};
};
}
Therefore, I need to use the alternative syntax where I can pass in a function that receives { config, ... }
and returns a set { ... }
. That config
that is passed is a point to home-manager's configuration where config.lib.file.mkOutOfStoreSymlink
is defined (see source):
{ config, ... }:
{
...
home-manager.users.bphenriques = { config, ... }: {
xdg.configFile = {
"input-remapper/config.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/config.json";
"input-remapper/presets/Logitech G305/Media.json".source = config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/Media.json";
};
};
}
Note: depending on your setup, you may avoid { config, ... }:
. I am doing this way because I want to keep both input-remapper
system service and and the home configuration in the same file.
Now, why: config.lib.file.mkOutOfStoreSymlink "${hostDir}/input-remapper/Media.json"
and not ./input-remapper/Media.json"
?
The reason is because files in the nix-store are readonly to the user that runs input-remapper
:
OSError: [Errno 30] Read-only file system: '/home/bphenriques/.config/input-remapper/presets/Logitech G305/Media.json'
As a workaround, we can actually create "out of store" files (config.lib.file.mkOutOfStoreSymlink
) where the file in the store actually ends up pointing to a absolute path ${hostDir}/modules/input-remapper/config.json
that the input-remapper can write to using the default user. The path has to be absolute.
Each setup is unique and Nix is not the easiest language to learn, specially if you are not familiar with some programming concepts (functions and scope is one of them). I hope this break down helps you a bit more :)
You my friend went above and beyond! I appreciate it very much. Looking over this now.
I'll report back if I get things working. With the time and effort placed in your explanation; I will most likely learn something!
Thank you again 👍
Btw, if you have more questions create a issue in my dotfiles repository to avoid discussing in this thread (would be off-topic).
Hello!
I have been using version 1.5 (the last one in NixOS packages) and so far the experience is great. However, I would like to configure input-remapper as part of my NixOS settings like so:
But the following happens:
Questions:
input-remapper-gtk -d --config-dir /tmp/scratch-place
whereinput-remapper
can write into and where we can fetch the final configs before adding them to the NixOS setup. This leads to more questions, however it is starting point.Thank you!
Edit: just noticed that maybe this one https://github.com/sezanzeb/input-remapper/issues/448 may be linked here