About
History
New snippet →
Upload snippet →
Snippet #2390 (python)
#2390
Expires in: 0 minutes
View Raw
{
config
,
pkgs
,
lib
,
...
}:
let
layouts
=
config
.
custom
.
customKeyboardLayouts
;
xkeyboard_config_custom
=
pkgs
.
xkeyboard_config
.
overrideAttrs
(
old
:
{
patches
=
[(
let
nlayouts
=
builtins
.
length
(
builtins
.
attrNames
layouts
);
in
builtins
.
toFile
"add-layout.patch"
''
---
a
/
rules
/
evdev
.
xml
.
in
+++
b
/
rules
/
evdev
.
xml
.
in
@@
-
6059
,
6
+
6059
,
$
{
toString
(
6
+
9
*
nlayouts
)}
@@
</
variant
>
</
variantList
>
</
layout
>
$
{
lib
.
concatStringsSep
"
\n
"
(
lib
.
mapAttrsToList
(
k
:
v
:
''
+
<
layout
>
+
<
configItem
>
+
<
name
>
$
{
k
}
</
name
>
+
<
_shortDescription
>
$
{
v
.
short
or
k
}
</
_shortDescription
>
+
<
_description
>
$
{
v
.
desc
}
</
_description
>
+
<
languageList
/>
+
</
configItem
>
+
<
variantList
/>
+
</
layout
>
''
)
layouts
)}
</
layoutList
>
<
optionList
>
<
group
allowMultipleSelection
=
"true"
>
''
)];
});
xkbDir
=
pkgs
.
buildEnv
{
name
=
"xkbdir_custom"
;
paths
=
[
"$
{xkeyboard_config_custom}
/share/X11/xkb"
(
pkgs
.
runCommand
"xkbdir_custom"
{}
''
mkdir
-
p
$
out
/
symbols
$
{
lib
.
concatStringsSep
"
\n
"
(
lib
.
mapAttrsToList
(
k
:
v
:
''
ln
-
s
$
{
v
.
src
}
$
out
/
symbols
/
$
{
k
}
''
)
layouts
)}
''
)
];
};
in
{
options
=
{
custom
.
customKeyboardLayouts
=
lib
.
mkOption
{
default
=
{};
type
=
lib
.
types
.
attrs
;
};
};
config
=
lib
.
mkIf
(
layouts
!=
{})
{
custom
.
overrideXkbDir
=
true
;
services
.
xserver
.
xkbDir
=
xkbDir
;
};
}
Wrap long lines
Reply to this snippet →
Honeypot, don't fill.
{ config, pkgs, lib, ... }: let layouts = config.custom.customKeyboardLayouts; xkeyboard_config_custom = pkgs.xkeyboard_config.overrideAttrs (old: { patches = [(let nlayouts = builtins.length (builtins.attrNames layouts); in builtins.toFile "add-layout.patch" '' --- a/rules/evdev.xml.in +++ b/rules/evdev.xml.in @@ -6059,6 +6059,${toString (6+9*nlayouts)} @@ </variant> </variantList> </layout> ${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: '' + <layout> + <configItem> + <name>${k}</name> + <_shortDescription>${v.short or k}</_shortDescription> + <_description>${v.desc}</_description> + <languageList/> + </configItem> + <variantList/> + </layout>'' ) layouts)} </layoutList> <optionList> <group allowMultipleSelection="true"> '')]; }); xkbDir = pkgs.buildEnv { name = "xkbdir_custom"; paths = [ "${xkeyboard_config_custom}/share/X11/xkb" (pkgs.runCommand "xkbdir_custom" {} '' mkdir -p $out/symbols ${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: '' ln -s ${v.src} $out/symbols/${k} '') layouts)} '') ]; }; in { options = { custom.customKeyboardLayouts = lib.mkOption { default = {}; type = lib.types.attrs; }; }; config = lib.mkIf (layouts != {}) { custom.overrideXkbDir = true; services.xserver.xkbDir = xkbDir; }; }
Text (preformatted)
Text (not code)
----------
ABAP
ApacheConf
AppleScript
ActionScript
Bash
BBCode
C
Clojure
COBOL
CSS
CUDA
Dart
Delphi
Diff
Django
Erlang
Fortran
Go
Groovy
Haml
Haskell
HTML
HTTP
INI
IRC
Java
JavaScript
JSON
Lua
Makefile
Mako
Mason
Matlab
Modula
Monkey
MySQL
NumPy
OCaml
Perl
PHP
PostScript
PowerShell
Prolog
Properties
Puppet
Python
Ruby
reStructuredText
Rust
Sass
Scala
Scheme
Scilab
SCSS
Smalltalk
Smarty
SQL
Tcl
Tcsh
TeX
Text (Preformatted)
Text (non-code)
VB.net
VimL
XML
XQuery
XSLT
YAML
Author:
⌘+⏎ or Ctrl+⏎
Expire in
One Time Snippet
In one hour
In one week
In one month