flake

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

default.nix (8567B)


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