fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.2 KiB53 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.editorconfig;
8
9  iniFormat = pkgs.formats.ini { };
10
11in {
12  meta.maintainers = with maintainers; [ loicreynier ];
13
14  options.editorconfig = {
15    enable = mkEnableOption "EditorConfig home configuration file";
16
17    settings = mkOption {
18      type = iniFormat.type;
19      default = { };
20      description = ''
21        Configuration written to {file}`$HOME/.editorconfig`.
22        `root = true` is automatically added to the file,
23        it must not be added here.
24        See <https://editorconfig.org> for documentation.
25      '';
26      example = literalExpression ''
27        {
28          "*" = {
29            charset = "utf-8";
30            end_of_line = "lf";
31            trim_trailing_whitespace = true;
32            insert_final_newline = true;
33            max_line_width = 78;
34            indent_style = "space";
35            indent_size = 4;
36          };
37        };
38      '';
39    };
40  };
41
42  config = mkIf (cfg.enable && cfg.settings != { }) {
43    home.file.".editorconfig".text = let
44      renderedSettings = generators.toINIWithGlobalSection { } {
45        globalSection = { root = true; };
46        sections = cfg.settings;
47      };
48    in ''
49      # Generated by Home Manager
50      ${renderedSettings}
51    '';
52  };
53}