Skip to content

Commit

Permalink
format with nixpkgs-fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Misterio77 committed Apr 21, 2023
1 parent 493d113 commit 4ccd57b
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 27 deletions.
7 changes: 5 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ let
sha256 = locked.narHash;
};

in { nixpkgs-lib ? import ((fromFlake "nixpkgs-lib") + "/lib")
, base16-schemes ? fromFlake "base16-schemes", ... }: rec {
in
{ nixpkgs-lib ? import ((fromFlake "nixpkgs-lib") + "/lib")
, base16-schemes ? fromFlake "base16-schemes"
, ...
}: rec {
lib = import ./lib;
lib-contrib = import ./lib/contrib;
lib-core = import ./lib/core { inherit nixpkgs-lib; };
Expand Down
2 changes: 1 addition & 1 deletion lib/contrib/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{pkgs ? (builtins.trace "nix-colors/lib-contrib: using <nixpkgs> as pkgs because the pkgs parameter was not provided" (import <nixpkgs> {}))}:
{ pkgs ? (builtins.trace "nix-colors/lib-contrib: using <nixpkgs> as pkgs because the pkgs parameter was not provided" (import <nixpkgs> { })) }:
rec {
# Takes a scheme, resulting wallpaper height and width, plus logo scale, and ouputs the generated wallpaper path
# Example:
Expand Down
3 changes: 2 additions & 1 deletion lib/contrib/gtk-theme.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let
mkdir -p $out/bin
ln -s ${pkgs.resvg}/bin/resvg $out/bin/rendersvg
'';
in pkgs.stdenv.mkDerivation rec {
in
pkgs.stdenv.mkDerivation rec {
name = "generated-gtk-theme-${scheme.slug}";
src = pkgs.fetchFromGitHub {
owner = "nana-4";
Expand Down
3 changes: 2 additions & 1 deletion lib/contrib/vim-theme.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
let
c = scheme.colors;
slug = scheme.slug;
in pkgs.writeTextDir "colors/nix-${slug}.vim" ''
in
pkgs.writeTextDir "colors/nix-${slug}.vim" ''
let g:colors_name="nix-${slug}"
set termguicolors
Expand Down
15 changes: 10 additions & 5 deletions lib/core/conversions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ let
let
inherit (nixpkgs-lib) toLower;
lowerHex = toLower hex;
in if builtins.stringLength hex != 1 then
in
if builtins.stringLength hex != 1 then
throw "Function only accepts a single character."
else if hexToDecMap ? ${lowerHex} then
hexToDecMap."${lowerHex}"
else
throw "Character ${hex} is not a hexadecimal value.";
in rec {
in
rec {
/* Converts from hexadecimal to decimal.
Type: hexToDec :: string -> int
Expand All @@ -88,7 +90,8 @@ in rec {
decimals = builtins.map hexCharToDec (stringToCharacters hex);
decimalsAscending = reverseList decimals;
decimalsPowered = imap0 base16To10 decimalsAscending;
in foldl builtins.add 0 decimalsPowered;
in
foldl builtins.add 0 decimalsPowered;

/* Converts a 6 character hexadecimal string to RGB values.
Expand All @@ -110,7 +113,8 @@ in rec {
rgbStartIndex = [ 0 2 4 ];
hexList = builtins.map (x: builtins.substring x 2 hex) rgbStartIndex;
hexLength = builtins.stringLength hex;
in if hexLength != 6 then
in
if hexLength != 6 then
throw ''
Unsupported hex string length of ${builtins.toString hexLength}.
Length must be exactly 6.
Expand All @@ -133,5 +137,6 @@ in rec {
inherit (nixpkgs-lib) concatStringsSep;
hexInRGB = hexToRGB hex;
hexInRGBString = map toString hexInRGB;
in concatStringsSep sep hexInRGBString;
in
concatStringsSep sep hexInRGBString;
}
3 changes: 2 additions & 1 deletion lib/core/math.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
let
x = pow base (exponent / 2);
odd_exp = mod exponent 2 == 1;
in x * x * (if odd_exp then base else 1)
in
x * x * (if odd_exp then base else 1)
else if exponent == 1 then
base
else if exponent == 0 && base == 0 then
Expand Down
9 changes: 6 additions & 3 deletions lib/core/schemeFromYAML.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ let
sep = builtins.unsafeDiscardStringContext _sep;
s = builtins.unsafeDiscardStringContext _s;
splits = filter builtins.isString (builtins.split (escapeRegex sep) s);
in map (v: addContextFrom _sep (addContextFrom _s v)) splits;
in
map (v: addContextFrom _sep (addContextFrom _s v)) splits;
nameValuePair = name: value: { inherit name value; };

# From https://github.com/arcnmx/nixexprs
Expand All @@ -41,7 +42,8 @@ let
lines = splitString "\n" yaml;
lines' = map stripLine lines;
lines'' = filter usefulLine lines';
in mapListToAttrs attrLine lines'';
in
mapListToAttrs attrLine lines'';

convertScheme = slug: set: {
name = set.scheme;
Expand All @@ -55,4 +57,5 @@ let
};

schemeFromYAML = slug: content: convertScheme slug (fromYAML content);
in schemeFromYAML
in
schemeFromYAML
6 changes: 4 additions & 2 deletions lib/core/schemeToYAML.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ let
scheme: "${scheme.name}"
author: "${scheme.author}"
'' + concatMapStrings # Add a line for each base0X color
(color: ''${color}: "${scheme.colors.${color}}"'') colorNames;
in schemeToYAML
(color: ''${color}: "${scheme.colors.${color}}"'')
colorNames;
in
schemeToYAML
3 changes: 2 additions & 1 deletion lib/core/tests/conversions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
let
conversions = import ../conversions.nix { inherit nixpkgs-lib; };
inherit (nixpkgs-lib) runTests;
in runTests {
in
runTests {
testHexToDec_1 = {
expr = conversions.hexToDec "12";
expected = 18;
Expand Down
3 changes: 2 additions & 1 deletion lib/core/tests/math.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
let
math = import ../math.nix { inherit nixpkgs-lib; };
inherit (nixpkgs-lib) runTests;
in runTests {
in
runTests {
testPow_1 = {
expr = math.pow 0 1000;
expected = 0;
Expand Down
23 changes: 14 additions & 9 deletions schemes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ let
let
sufLen = stringLength suffix;
sLen = stringLength str;
in if sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str then
in
if sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str then
substring 0 (sLen - sufLen) str
else
str;
hasSuffix = suffix: content:
let
lenContent = stringLength content;
lenSuffix = stringLength suffix;
in lenContent >= lenSuffix
in
lenContent >= lenSuffix
&& substring (lenContent - lenSuffix) lenContent content == suffix;

stripYamlExtension = filename:
Expand All @@ -28,10 +30,13 @@ let

colorSchemeFiles = filter isYamlFile (attrNames (readDir base16-schemes));

colorSchemes = listToAttrs (map (filename: rec {
# Scheme slug
name = stripYamlExtension (baseNameOf filename);
# Scheme contents
value = schemeFromYAML name (readFile "${base16-schemes}/${filename}");
}) colorSchemeFiles);
in colorSchemes
colorSchemes = listToAttrs (map
(filename: rec {
# Scheme slug
name = stripYamlExtension (baseNameOf filename);
# Scheme contents
value = schemeFromYAML name (readFile "${base16-schemes}/${filename}");
})
colorSchemeFiles);
in
colorSchemes

0 comments on commit 4ccd57b

Please sign in to comment.