flake

Francesco Saccone's Nix flake.
git clone https://git.francescosaccone.com/flake
Log | Files | Refs | README | LICENSE

default.nix (8602B)


      1 {
      2   lib,
      3   options,
      4   config,
      5   pkgs,
      6   ...
      7 }:
      8 {
      9   imports = [
     10     ./bar
     11   ];
     12 
     13   options.modules.sway = {
     14     enable = lib.mkOption {
     15       description = "Whether to enable the configuration for Sway.";
     16       default = false;
     17       type = lib.types.bool;
     18     };
     19     fonts = {
     20       monospace = lib.mkOption {
     21         type = lib.types.uniq lib.types.str;
     22         description = ''
     23           The monospace font to be used in Sway and its components.
     24         '';
     25       };
     26     };
     27     backgroundImage = lib.mkOption {
     28       description = "The image used as background.";
     29       type = lib.types.uniq lib.types.path;
     30     };
     31     colors = lib.mkOption {
     32       description = "The hex colors, in '#rrggbb[aa]' format.";
     33       type = lib.types.submodule {
     34         options = {
     35           background = lib.mkOption {
     36             description = ''
     37               The background color: it should be continous with the background
     38               image.
     39             '';
     40             type = lib.types.uniq lib.types.str;
     41           };
     42           foreground = lib.mkOption {
     43             description = "The foreground color.";
     44             type = lib.types.uniq lib.types.str;
     45           };
     46           darkRed = lib.mkOption {
     47             description = "The dark red color.";
     48             type = lib.types.uniq lib.types.str;
     49           };
     50           green = lib.mkOption {
     51             description = "The green color.";
     52             type = lib.types.uniq lib.types.str;
     53           };
     54           red = lib.mkOption {
     55             description = "The red color.";
     56             type = lib.types.uniq lib.types.str;
     57           };
     58           transparent = lib.mkOption {
     59             description = "The transparent color.";
     60             readOnly = true;
     61             default = "#00000000";
     62             type = lib.types.uniq lib.types.str;
     63           };
     64         };
     65       };
     66     };
     67   };
     68 
     69   config = lib.mkIf config.modules.sway.enable {
     70     home = {
     71       packages = [
     72         pkgs.swaybg
     73         pkgs.wl-clipboard-rs
     74       ];
     75       pointerCursor = {
     76         gtk.enable = true;
     77         name = "graphite-dark-nord";
     78         package = pkgs.graphite-cursors;
     79         size = 20;
     80       };
     81     };
     82 
     83     wayland.windowManager.sway =
     84       let
     85         inherit (config.modules.sway) backgroundImage colors;
     86         commands = {
     87           terminal =
     88             let
     89               # Remove the leading '#' character.
     90               parseColor = builtins.substring 1 7;
     91 
     92               background = parseColor colors.background;
     93               foreground = parseColor colors.foreground;
     94 
     95               configFile = pkgs.writeText "foot.ini" ''
     96                 [cursor]
     97                 color=${background} ${foreground}
     98                 style=beam
     99                 blink=yes
    100                 blink-rate=500
    101                 beam-thickness=1.5
    102 
    103                 [colors]
    104                 alpha=0.8
    105                 background=${background}
    106                 foreground=${foreground}
    107 
    108                 [main]
    109                 font=${config.modules.sway.fonts.monospace}:size=11
    110                 title=Foot
    111                 locked-title=yes
    112               '';
    113             in
    114             "${pkgs.foot}/bin/foot -c ${configFile}";
    115         };
    116       in
    117       {
    118         enable = true;
    119         package = pkgs.sway;
    120 
    121         xwayland = true;
    122         config = {
    123           fonts = {
    124             names = [
    125               config.modules.sway.fonts.monospace
    126             ];
    127             style = "Regular";
    128             size = 12.0;
    129           };
    130 
    131           defaultWorkspace = "workspace number \"1\"";
    132 
    133           inherit (commands) terminal;
    134           modifier = "Mod4";
    135           floating.modifier = "Mod4";
    136 
    137           output."*".background = "${backgroundImage} fill";
    138 
    139           colors =
    140             let
    141               default = {
    142                 background = colors.foreground;
    143                 border = colors.transparent;
    144                 text = colors.background;
    145               };
    146             in
    147             rec {
    148               focused = {
    149                 background = colors.foreground;
    150                 border = colors.foreground;
    151                 text = colors.background;
    152               };
    153 
    154               focusedInactive = default;
    155               unfocused = default;
    156               urgent = {
    157                 inherit (default)
    158                   background
    159                   text
    160                   ;
    161                 border = colors.red;
    162               };
    163             }
    164             |> builtins.mapAttrs (
    165               name:
    166               {
    167                 background,
    168                 border,
    169                 text,
    170               }:
    171               {
    172                 inherit background border text;
    173                 childBorder = border;
    174                 indicator = border;
    175               }
    176             );
    177 
    178           gaps = {
    179             inner = 14;
    180             outer = 18;
    181           };
    182 
    183           window = {
    184             titlebar = false;
    185           };
    186 
    187           input = {
    188             "type:keyboard" = {
    189               xkb_layout = "it";
    190             };
    191             "*" = {
    192               tap = "enabled";
    193             };
    194           };
    195 
    196           modes.resize = {
    197             "Up" = "resize grow height 7 px or 7 ppt";
    198             "Right" = "resize grow width 7 px or 7 ppt";
    199             "Left" = "resize shrink width 7 px or 7 ppt";
    200             "Down" = "resize shring height 7 px or 7 ppt";
    201 
    202             "Mod4+r" = "mode \"default\"";
    203           };
    204 
    205           keybindings = {
    206             "Mod4+Return" = "exec ${commands.terminal}";
    207 
    208             "XF86AudioRaiseVolume" = ''
    209               exec ${pkgs.alsa-utils}/bin/amixer set Master 10%+
    210             '';
    211             "XF86AudioLowerVolume" = ''
    212               exec ${pkgs.alsa-utils}/bin/amixer set Master 10%-
    213             '';
    214             "XF86AudioMute" = ''
    215               exec ${pkgs.alsa-utils}/bin/amixer set Master toggle
    216             '';
    217             "XF86AudioMicMute" = ''
    218               exec ${pkgs.alsa-utils}/bin/amixer set Capture toggle
    219             '';
    220 
    221             "XF86MonBrightnessUp" = ''
    222               exec ${pkgs.brightnessctl}/bin/brightnessctl set 10%+
    223             '';
    224             "XF86MonBrightnessDown" = ''
    225               exec ${pkgs.brightnessctl}/bin/brightnessctl set 10%-
    226             '';
    227 
    228             "Mod4+q" = "kill";
    229 
    230             "Mod4+Left" = "focus left";
    231             "Mod4+Down" = "focus down";
    232             "Mod4+Up" = "focus up";
    233             "Mod4+Right" = "focus right";
    234 
    235             "Mod4+Shift+Left" = "move left";
    236             "Mod4+Shift+Down" = "move down";
    237             "Mod4+Shift+Up" = "move up";
    238             "Mod4+Shift+Right" = "move right";
    239 
    240             "Mod4+f" = "fullscreen toggle";
    241             "Mod4+Shift+space" = "floating toggle";
    242             "Mod4+space" = "focus mode_toggle";
    243 
    244             "Mod4+1" = "workspace number \"1\"";
    245             "Mod4+2" = "workspace number \"2\"";
    246             "Mod4+3" = "workspace number \"3\"";
    247             "Mod4+4" = "workspace number \"4\"";
    248             "Mod4+5" = "workspace number \"5\"";
    249             "Mod4+6" = "workspace number \"6\"";
    250             "Mod4+7" = "workspace number \"7\"";
    251             "Mod4+8" = "workspace number \"8\"";
    252             "Mod4+9" = "workspace number \"9\"";
    253             "Mod4+0" = "workspace number \"10\"";
    254 
    255             "Mod4+Shift+1" = "move container to workspace number \"1\"";
    256             "Mod4+Shift+2" = "move container to workspace number \"2\"";
    257             "Mod4+Shift+3" = "move container to workspace number \"3\"";
    258             "Mod4+Shift+4" = "move container to workspace number \"4\"";
    259             "Mod4+Shift+5" = "move container to workspace number \"5\"";
    260             "Mod4+Shift+6" = "move container to workspace number \"6\"";
    261             "Mod4+Shift+7" = "move container to workspace number \"7\"";
    262             "Mod4+Shift+8" = "move container to workspace number \"8\"";
    263             "Mod4+Shift+9" = "move container to workspace number \"9\"";
    264             "Mod4+Shift+0" = "move container to workspace number \"10\"";
    265 
    266             "Mod4+Shift+c" = "reload";
    267             "Mod4+Shift+r" = "restart";
    268 
    269             "Mod4+r" = "mode \"resize\"";
    270           };
    271 
    272           startup = [
    273             {
    274               command = "${pkgs.autotiling}/bin/autotiling";
    275               always = true;
    276             }
    277             {
    278               command = "${pkgs.alsa-utils}/bin/amixer set Master 100%";
    279               always = false;
    280             }
    281             {
    282               command = "${pkgs.alsa-utils}/bin/amixer set Capture 100%";
    283               always = false;
    284             }
    285             {
    286               command = "${pkgs.brightnessctl}/bin/brightnessctl set 100%";
    287               always = false;
    288             }
    289           ];
    290         };
    291       };
    292   };
    293 }