dircolors: add module

PR #1219
This commit is contained in:
Justin Lovinger 2020-05-06 12:23:40 -04:00 committed by Robert Helgesson
parent cca024da2b
commit e9945ee6ee
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
8 changed files with 394 additions and 0 deletions

2
.github/CODEOWNERS vendored
View file

@ -34,6 +34,8 @@
/modules/programs/broot.nix @aheaume
/modules/programs/dircolors.nix @JustinLovinger
/modules/programs/direnv.nix @rycee
/modules/programs/eclipse.nix @rycee

View file

@ -1513,6 +1513,13 @@ in
It can be enabled through the option 'programs.git.delta.enable'.
'';
}
{
time = "2020-05-12T20:09:54+00:00";
message = ''
A new module is available: 'programs.dircolors'
'';
}
];
};
}

View file

@ -55,6 +55,7 @@ let
(loadModule ./programs/browserpass.nix { })
(loadModule ./programs/chromium.nix { condition = hostPlatform.isLinux; })
(loadModule ./programs/command-not-found/command-not-found.nix { })
(loadModule ./programs/dircolors.nix { })
(loadModule ./programs/direnv.nix { })
(loadModule ./programs/eclipse.nix { })
(loadModule ./programs/emacs.nix { })

View file

@ -0,0 +1,222 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.dircolors;
formatLine = n: v: "${n} ${toString v}";
in {
meta.maintainers = [ hm.maintainers.justinlovinger ];
options.programs.dircolors = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to manage <filename>.dir_colors</filename>
and set <code>LS_COLORS</code>.
'';
};
enableBashIntegration = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable Bash integration.
'';
};
enableFishIntegration = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable Fish integration.
'';
};
enableZshIntegration = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable Zsh integration.
'';
};
settings = mkOption {
type = with types; attrsOf str;
default = { };
description = ''
Options to add to <filename>.dir_colors</filename> file.
See <command>dircolors --print-database</command>
for options.
'';
example = literalExample ''
{
OTHER_WRITABLE = "30;46";
".sh" = "01;32";
".csh" = "01;32";
}
'';
};
extraConfig = mkOption {
type = types.lines;
default = "";
description = ''
Extra lines added to <filename>.dir_colors</filename> file.
'';
};
};
config = mkIf cfg.enable {
# Add default settings from `dircolors --print-database`.
programs.dircolors.settings = {
RESET = mkDefault "0";
DIR = mkDefault "01;34";
LINK = mkDefault "01;36";
MULTIHARDLINK = mkDefault "00";
FIFO = mkDefault "40;33";
SOCK = mkDefault "01;35";
DOOR = mkDefault "01;35";
BLK = mkDefault "40;33;01";
CHR = mkDefault "40;33;01";
ORPHAN = mkDefault "40;31;01";
MISSING = mkDefault "00";
SETUID = mkDefault "37;41";
SETGID = mkDefault "30;43";
CAPABILITY = mkDefault "30;41";
STICKY_OTHER_WRITABLE = mkDefault "30;42";
OTHER_WRITABLE = mkDefault "34;42";
STICKY = mkDefault "37;44";
EXEC = mkDefault "01;32";
".tar" = mkDefault "01;31";
".tgz" = mkDefault "01;31";
".arc" = mkDefault "01;31";
".arj" = mkDefault "01;31";
".taz" = mkDefault "01;31";
".lha" = mkDefault "01;31";
".lz4" = mkDefault "01;31";
".lzh" = mkDefault "01;31";
".lzma" = mkDefault "01;31";
".tlz" = mkDefault "01;31";
".txz" = mkDefault "01;31";
".tzo" = mkDefault "01;31";
".t7z" = mkDefault "01;31";
".zip" = mkDefault "01;31";
".z" = mkDefault "01;31";
".dz" = mkDefault "01;31";
".gz" = mkDefault "01;31";
".lrz" = mkDefault "01;31";
".lz" = mkDefault "01;31";
".lzo" = mkDefault "01;31";
".xz" = mkDefault "01;31";
".zst" = mkDefault "01;31";
".tzst" = mkDefault "01;31";
".bz2" = mkDefault "01;31";
".bz" = mkDefault "01;31";
".tbz" = mkDefault "01;31";
".tbz2" = mkDefault "01;31";
".tz" = mkDefault "01;31";
".deb" = mkDefault "01;31";
".rpm" = mkDefault "01;31";
".jar" = mkDefault "01;31";
".war" = mkDefault "01;31";
".ear" = mkDefault "01;31";
".sar" = mkDefault "01;31";
".rar" = mkDefault "01;31";
".alz" = mkDefault "01;31";
".ace" = mkDefault "01;31";
".zoo" = mkDefault "01;31";
".cpio" = mkDefault "01;31";
".7z" = mkDefault "01;31";
".rz" = mkDefault "01;31";
".cab" = mkDefault "01;31";
".wim" = mkDefault "01;31";
".swm" = mkDefault "01;31";
".dwm" = mkDefault "01;31";
".esd" = mkDefault "01;31";
".jpg" = mkDefault "01;35";
".jpeg" = mkDefault "01;35";
".mjpg" = mkDefault "01;35";
".mjpeg" = mkDefault "01;35";
".gif" = mkDefault "01;35";
".bmp" = mkDefault "01;35";
".pbm" = mkDefault "01;35";
".pgm" = mkDefault "01;35";
".ppm" = mkDefault "01;35";
".tga" = mkDefault "01;35";
".xbm" = mkDefault "01;35";
".xpm" = mkDefault "01;35";
".tif" = mkDefault "01;35";
".tiff" = mkDefault "01;35";
".png" = mkDefault "01;35";
".svg" = mkDefault "01;35";
".svgz" = mkDefault "01;35";
".mng" = mkDefault "01;35";
".pcx" = mkDefault "01;35";
".mov" = mkDefault "01;35";
".mpg" = mkDefault "01;35";
".mpeg" = mkDefault "01;35";
".m2v" = mkDefault "01;35";
".mkv" = mkDefault "01;35";
".webm" = mkDefault "01;35";
".ogm" = mkDefault "01;35";
".mp4" = mkDefault "01;35";
".m4v" = mkDefault "01;35";
".mp4v" = mkDefault "01;35";
".vob" = mkDefault "01;35";
".qt" = mkDefault "01;35";
".nuv" = mkDefault "01;35";
".wmv" = mkDefault "01;35";
".asf" = mkDefault "01;35";
".rm" = mkDefault "01;35";
".rmvb" = mkDefault "01;35";
".flc" = mkDefault "01;35";
".avi" = mkDefault "01;35";
".fli" = mkDefault "01;35";
".flv" = mkDefault "01;35";
".gl" = mkDefault "01;35";
".dl" = mkDefault "01;35";
".xcf" = mkDefault "01;35";
".xwd" = mkDefault "01;35";
".yuv" = mkDefault "01;35";
".cgm" = mkDefault "01;35";
".emf" = mkDefault "01;35";
".ogv" = mkDefault "01;35";
".ogx" = mkDefault "01;35";
".aac" = mkDefault "00;36";
".au" = mkDefault "00;36";
".flac" = mkDefault "00;36";
".m4a" = mkDefault "00;36";
".mid" = mkDefault "00;36";
".midi" = mkDefault "00;36";
".mka" = mkDefault "00;36";
".mp3" = mkDefault "00;36";
".mpc" = mkDefault "00;36";
".ogg" = mkDefault "00;36";
".ra" = mkDefault "00;36";
".wav" = mkDefault "00;36";
".oga" = mkDefault "00;36";
".opus" = mkDefault "00;36";
".spx" = mkDefault "00;36";
".xspf" = mkDefault "00;36";
};
home.file.".dir_colors".text = concatStringsSep "\n" ([ ]
++ optional (cfg.extraConfig != "") cfg.extraConfig
++ mapAttrsToList formatLine cfg.settings) + "\n";
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
eval $(${pkgs.coreutils}/bin/dircolors -b ~/.dir_colors)
'';
programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
eval (${pkgs.coreutils}/bin/dircolors -c ~/.dir_colors)
'';
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
eval $(${pkgs.coreutils}/bin/dircolors -b ~/.dir_colors)
'';
};
}

View file

@ -39,6 +39,7 @@ import nmt {
./modules/programs/aria2
./modules/programs/bash
./modules/programs/browserpass
./modules/programs/dircolors
./modules/programs/fish
./modules/programs/git
./modules/programs/gpg

View file

@ -0,0 +1 @@
{ dircolors-settings = ./settings.nix; }

View file

@ -0,0 +1,133 @@
# Extra dircolors configuration.
.7z 01;31
.aac 00;36
.ace 01;31
.alz 01;31
.arc 01;31
.arj 01;31
.asf 01;35
.au 00;36
.avi 01;35
.bmp 01;35
.bz 01;31
.bz2 01;31
.cab 01;31
.cgm 01;35
.cpio 01;31
.csh 01;32
.deb 01;31
.dl 01;35
.dwm 01;31
.dz 01;31
.ear 01;31
.emf 01;35
.esd 01;31
.flac 00;36
.flc 01;35
.fli 01;35
.flv 01;35
.gif 01;35
.gl 01;35
.gz 01;31
.jar 01;31
.jpeg 01;35
.jpg 01;35
.lha 01;31
.lrz 01;31
.lz 01;31
.lz4 01;31
.lzh 01;31
.lzma 01;31
.lzo 01;31
.m2v 01;35
.m4a 00;36
.m4v 01;35
.mid 00;36
.midi 00;36
.mjpeg 01;35
.mjpg 01;35
.mka 00;36
.mkv 01;35
.mng 01;35
.mov 01;35
.mp3 00;36
.mp4 01;35
.mp4v 01;35
.mpc 00;36
.mpeg 01;35
.mpg 01;35
.nuv 01;35
.oga 00;36
.ogg 00;36
.ogm 01;35
.ogv 01;35
.ogx 01;35
.opus 00;36
.pbm 01;35
.pcx 01;35
.pgm 01;35
.png 01;35
.ppm 01;35
.qt 01;35
.ra 00;36
.rar 01;31
.rm 01;35
.rmvb 01;35
.rpm 01;31
.rz 01;31
.sar 01;31
.sh 01;32
.spx 00;36
.svg 01;35
.svgz 01;35
.swm 01;31
.t7z 01;31
.tar 01;31
.taz 01;31
.tbz 01;31
.tbz2 01;31
.tga 01;35
.tgz 01;31
.tif 01;35
.tiff 01;35
.tlz 01;31
.txz 01;31
.tz 01;31
.tzo 01;31
.tzst 01;31
.vob 01;35
.war 01;31
.wav 00;36
.webm 01;35
.wim 01;31
.wmv 01;35
.xbm 01;35
.xcf 01;35
.xpm 01;35
.xspf 00;36
.xwd 01;35
.xz 01;31
.yuv 01;35
.z 01;31
.zip 01;31
.zoo 01;31
.zst 01;31
BLK 40;33;01
CAPABILITY 30;41
CHR 40;33;01
DIR 01;34
DOOR 01;35
EXEC 01;32
FIFO 40;33
LINK 01;36
MISSING 00
MULTIHARDLINK 00
ORPHAN 40;31;01
OTHER_WRITABLE 30;46
RESET 0
SETGID 30;43
SETUID 37;41
SOCK 01;35
STICKY 37;44
STICKY_OTHER_WRITABLE 30;42

View file

@ -0,0 +1,27 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
programs.dircolors = {
enable = true;
settings = {
OTHER_WRITABLE = "30;46";
".sh" = "01;32";
".csh" = "01;32";
};
extraConfig = ''
# Extra dircolors configuration.
'';
};
nmt.script = ''
assertFileContent \
home-files/.dir_colors \
${./settings-expected.conf}
'';
};
}