{"id":13822089,"url":"https://github.com/bertof/nix-rice","last_synced_at":"2025-04-07T07:11:06.014Z","repository":{"id":153972287,"uuid":"380437006","full_name":"bertof/nix-rice","owner":"bertof","description":"A library to functionally define your configuration and theme (rice) with Nix","archived":false,"fork":false,"pushed_at":"2025-03-25T13:01:04.000Z","size":1181,"stargazers_count":101,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T05:09:01.385Z","etag":null,"topics":["color","color-scheme","hacktoberfest","home-manager","linux","macos","nix","nixos","rice"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bertof.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-26T06:59:21.000Z","updated_at":"2025-03-30T09:08:17.000Z","dependencies_parsed_at":"2024-01-15T15:46:33.004Z","dependency_job_id":"4fb4263c-1857-4577-a29f-9fde96f57496","html_url":"https://github.com/bertof/nix-rice","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertof%2Fnix-rice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertof%2Fnix-rice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertof%2Fnix-rice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertof%2Fnix-rice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bertof","download_url":"https://codeload.github.com/bertof/nix-rice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608151,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color","color-scheme","hacktoberfest","home-manager","linux","macos","nix","nixos","rice"],"created_at":"2024-08-04T08:01:42.091Z","updated_at":"2025-04-07T07:11:05.977Z","avatar_url":"https://github.com/bertof.png","language":"Nix","funding_links":[],"categories":["Nix"],"sub_categories":[],"readme":"# nix-rice\n\n**Bring ricing to Nix!**\n\nNix-rice is a nix library compatible with both standard and flakes dependency systems.\nIt provides a simple overlay to provide unified color scheme management for your packages\n\n## Why\n\nNix standard library does not have direct support for colors and their hexadecimal representation, commonly used in package configurations. This library tries to solve this by adding:\n\n- Support to color definitions and transformations (RGBA and HSLA)\n- Color serialization and deserialization as hexadecimal strings\n- Color palette definitions and transformations\n- Huge library of ready to use themes based on [kovidgoyal's kitty-themes](https://github.com/kovidgoyal/kitty-themes)\n\n## Importing nix-rice in your configuration\n\nNix-rice supports both the standard derivation input system and the new flake system.\n\n\n### Nix-rice with default import system\n\n1. Fetch the `nix-rice` using `fetchGit` as `nix-rice`\n2. Either load the library:\n  a. Import the library file using `nix-rice-lib = import (nix-rice + \"/lib.nix\")`; \n  b. Access the library using using `nix-rice-lib`\n3. Or load the overlay:\n  a. Import the overlay file using `nix-rice-overlay = import (nix-rice + \"/overlay.nix\")`;\n  b. Apply the overlay when importing `nixpkgs`\n  c. Access the library using `nixpkgs.lib.nix-rice`\n\nExample:\n\n```nix\nlet\n  nix-rice = builtins.fetchGit {\n    url = \"https://github.com/bertof/nix-rice.git\";\n    ref = \"refs/tags/v0.3.0\";  \n  };\n  nix-rice-overlay = import (nix-rice + \"/overlay.nix\");\n  pkgs = import \u003cnixpkgs\u003e { overlays = [ nix-rice-overlay ];};\nin\n{\n  # \u003c YOUR CONFIGURATION HERE \u003e\n}\n```\n\n### Nix-rice with flakes\n\n1. Add `nix-rice` to your inputs;\n2. Access the library, either through `nix-rice.lib` or, applying the standard overlay, through `pkgs.lib.nix-rice`.\n\nExample:\n\n```nix\n\n{\n  inputs = {\n    # \u003c OTHER INPUTS HERE \u003e\n    nixpkgs.url = \"github:NixOS/nixpkgs/release-22.11\";\n    flake-utils.url = \"github:numtide/flake-utils\";\n    nix-rice = { url = \"github:bertof/nix-rice\"; };\n  };\n\n  outputs = { self, nixpkgs, nix-rice }: \n  let\n    overlays = [ nix-rice.overlays.default ];\n  in\n    flake-utils.lib.eachDefaultSystem (system: \n      let\n        pkgs = import nixpkgs { inherit overlays; };\n      in\n      {\n        # \u003c YOUR CONFIGURATION HERE \u003e\n      });\n}\n\n```\n\n## How to use it\n\nNix-rice provides a the library module with the following submodules:\n\n- `op`: extends the standard library with utility functions for managing numbers;\n- `float`: extends the standard library with float-specific functions, like integer division, module operator, ceil, floor and float conversion;\n- `hex`: contains a hexadecimal parser and serializer for integers\n- `color`: contains the logic for color parsing, transformation, serialization and conversion;\n- `palette`: contains the logic for color palette parsing, transformation, serialization and conversion;\n- `kitty-themes`: contains a [Kitty terminal](https://github.com/kovidgoyal/kitty) configuration parser and theme loader.\n\nThe general workflow to use Nix-rice is the following:\n\n1. **Define a color palette**: you can load any of the themes in [Kitty themes](https://github.com/kovidgoyal/kitty-themes/tree/4d309e984b81dd120d7a697abe4f817da6f3cfe5/themes) or create one from scratch:\n  ```nix\n  with pkgs.lib.nix-rice;\n  colorPalette = palette.tPalette color.hexToRgba {\n    red = \"#FF0000FF\";\n    green = \"#00FF00FF\";\n    green = \"#0000FFFF\";\n    # \u003c ANY OTHER COLOR HERE \u003e\n  };\n  ```\n  `color.hexToRgba` is applied recursively, so you can have nested or lazy evaluated colors, i.e. you can load your palette from a JSON file and parse it with Nix-rice.\n  \n  **TIP**: it's useful to store your parsed palette in your configuration as an overlay, so that you can load it from any package and more uniformly apply transformations:\n  ```nix\n  self: super: with super.lib.nix-rice; let theme = kitty-themes.getThemeByName \"Cattppuccin-Mocha\"; in {\n    rice.colorPalette = rec {\n      normal = palette.defaultPalette // {\n        black = theme.color0;\n        red = theme.color1;\n        green = theme.color2;\n        yellow = theme.color3;\n        blue = theme.color4;\n        magenta = theme.color5;\n        cyan = theme.color6;\n        white = theme.color7;\n      };\n      bright = palette.brighten 10 normal // {\n        black = theme.color8;\n        red = theme.color9;\n        green = theme.color10;\n        yellow = theme.color11;\n        blue = theme.color12;\n        magenta = theme.color13;\n        cyan = theme.color14;\n        white = theme.color15;\n      };\n    } // theme;\n  }\n  ```\n\n2. Transform: transform and adapt your palette. \n   Nix-rice provides bidirectional conversion for RGBA and HSLA.\n   For ease of use, Nix-rice also provides `brighten` and `darken` functions.\n   Future plans include the extension of transformation functions with several mixing modes.\n\n3. Translate: convert your palette to the most appropriate serialization.\n   Nix-rice provides bidirectional conversion for upper case and lower case versions of RGB, RGBA, ARGB, both with and without the initial `#`.\n   Convert the palette to its serialized version and use it in your configurations.\n\n   This is example shows part of configuration for BSPWM through `home-manager`:\n   ```nix\n   { pkgs, lib, ... }:\n   with pkgs.lib.nix-rice;\n   let strPalette = palette.toRGBHex pkgs.rice.colorPalette;\n   in {\n     xsession.windowManager.bspwm = {\n       enable = true;\n       settings = {\n         border_width = 1;\n         border_radius = 8;\n         window_gap = 2;\n         split_ratio = 0.5;\n         top_padding = 0;\n         borderless_monocle = true;\n         gapless_monocle = false;\n         normal_border_color = strPalette.normal.blue;\n         focused_border_color = strPalette.bright.red;\n       };\n     };\n   }\n   ```\n\n   This is an example on the integration of Nix-rice with Alacritty through `home-manager`:\n   ```nix\n   { pkgs, ... }:\n   let\n     strPalette = with pkgs.rice;\n       pkgs.lib.nix-rice.palette.toRgbHex rec {\n         inherit (colorPalette) normal bright primary;\n         dim = colorPalette.dark;\n         cursor = {\n           cursor = normal.white;\n           text = normal.black;\n         };\n         vi_mode_cursor = {\n           cursor = normal.white;\n           text = normal.black;\n         };\n         selection.background = dim.blue;\n         search = {\n           matches.background = dim.cyan;\n           bar = {\n             foreground = dim.cyan;\n             background = dim.yellow;\n           };\n         };\n       };\n   in\n   {\n     # Include fonts packages\n     home.packages = [ pkgs.rice.font.monospace.package ];\n     programs.alacritty = {\n       enable = true;\n       settings = {\n         # env.TERM = \"xterm-256color\";\n         env.TERM = \"alacritty\";\n         scrolling.history = 3000;\n         font = {\n           normal.family = pkgs.rice.font.monospace.name;\n           size = pkgs.rice.font.monospace.size / 1.5; # Font size is broken\n         };\n         window.opacity = pkgs.rice.opacity;\n         mouse = {\n           # hide_when_typing = true;\n           hints.modifiers = \"Control\";\n         };\n         colors = with pkgs.rice;\n           strPalette // {\n             selection.text = \"CellForeground\";\n             search.matches.foreground = \"CellForeground\";\n           };\n       };\n     };\n   }\n   ````\n\n## Complete overlay example\n\nThis is a complete overlay example saving the theme in the `rice` derivation.\nThis also includes font configuration and fail safe colors definitions using `palette.defaultPalette`.\n\n```nix\nself: super:\nwith super.lib.nix-rice;\nlet theme = kitty-themes.getThemeByName \"Catppuccin-Mocha\";\nin {\n  rice = {\n    colorPalette = rec {\n      normal = palette.defaultPalette // {\n        black = theme.color0;\n        red = theme.color1;\n        green = theme.color2;\n        yellow = theme.color3;\n        blue = theme.color4;\n        magenta = theme.color5;\n        cyan = theme.color6;\n        white = theme.color7;\n      };\n      bright = palette.brighten 10 normal // {\n        black = theme.color8;\n        red = theme.color9;\n        green = theme.color10;\n        yellow = theme.color11;\n        blue = theme.color12;\n        magenta = theme.color13;\n        cyan = theme.color14;\n        white = theme.color15;\n      };\n      dark = palette.darken 10 normal;\n      primary = {\n        inherit (theme) background foreground;\n        bright_foreground = color.brighten 10 theme.foreground;\n        dim_foreground = color.darken 10 theme.foreground;\n      };\n    } // theme;\n    font = {\n      normal = {\n        name = \"Cantarell\";\n        package = self.cantarell-fonts;\n        size = 10;\n      };\n      monospace = {\n        name = \"FiraCode Nerd Font Mono\";\n        package = self.nerdfonts.override { fonts = [ \"FiraCode\" ]; };\n        size = 10;\n      };\n    };\n    opacity = 0.95;\n  };\n}\n```\n\n## Updates\n\nWhile the library interface is mostly set, it might change in the future (new transformations, palette generation, conversion to specific programs configurations). It is therefore suggested to use a pinned version like in the example above.\n\n\n## Contributions\n\nFeel free to modify this library as you please: addition and fixes are welcome. Do yow want to include your favorite theme? Add a new transformation? Send a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbertof%2Fnix-rice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbertof%2Fnix-rice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbertof%2Fnix-rice/lists"}