diff --git a/subprojects/bahaghari/default.nix b/subprojects/bahaghari/default.nix index 01f31181..a5ee5567 100644 --- a/subprojects/bahaghari/default.nix +++ b/subprojects/bahaghari/default.nix @@ -3,7 +3,7 @@ # npins sources in here. # # This is just kept for future compatiblity in case we require pkgs or something. -{}: +{ }: { nixosModules = rec { diff --git a/subprojects/bahaghari/flake.nix b/subprojects/bahaghari/flake.nix index ed63966e..6aec7310 100644 --- a/subprojects/bahaghari/flake.nix +++ b/subprojects/bahaghari/flake.nix @@ -1,50 +1,39 @@ # It has a design constraint of requiring no flake inputs as we're already # using npins. { - description = "Specialized set of Nix modules for generating and applying themes."; + description = + "Specialized set of Nix modules for generating and applying themes."; outputs = { ... }: let sources = import ./npins; - systems = [ - "x86_64-linux" - "aarch64-linux" - ]; - eachSystem = - systems: f: + systems = [ "x86_64-linux" "aarch64-linux" ]; + eachSystem = systems: f: let # Merge together the outputs for all systems. - op = - attrs: system: + op = attrs: system: let ret = f system; - op = - attrs: key: - attrs - // { - ${key} = (attrs.${key} or { }) // { - ${system} = ret.${key}; - }; + op = attrs: key: + attrs // { + ${key} = (attrs.${key} or { }) // { ${system} = ret.${key}; }; }; - in - builtins.foldl' op attrs (builtins.attrNames ret); - in - builtins.foldl' op { } ( - systems + in builtins.foldl' op attrs (builtins.attrNames ret); + in builtins.foldl' op { } (systems # add the current system if --impure is used - ++ ( - if builtins ? currentSystem then - if builtins.elem builtins.currentSystem systems then [ ] else [ builtins.currentSystem ] - else + ++ (if builtins ? currentSystem then + if builtins.elem builtins.currentSystem systems then [ ] - ) - ); - in eachSystem systems - (system: let - tests = branch: import ./tests { inherit branch system; }; + else + [ builtins.currentSystem ] + else + [ ])); + in eachSystem systems (system: + let tests = branch: import ./tests { inherit branch system; }; in { - devShells.default = - import ./shell.nix { pkgs = import sources.nixos-stable { inherit system; }; }; + devShells.default = import ./shell.nix { + pkgs = import sources.nixos-stable { inherit system; }; + }; checks = { bahaghariLibStable = (tests "stable").libTestPkg; diff --git a/subprojects/bahaghari/lib/default.nix b/subprojects/bahaghari/lib/default.nix index afa85dcf..44d5a232 100644 --- a/subprojects/bahaghari/lib/default.nix +++ b/subprojects/bahaghari/lib/default.nix @@ -2,10 +2,6 @@ # library anyways. This set is mostly copied over from nixpkgs' way of doing # things. # -# Take note the `lib` attribute throughout all of the library files are -# referring to the Bahaghari library set. We mostly rely on `pkgs.lib` as an -# easy way to identify if we use nixpkgs' standard library. -# # As a design constraint, since this is expected to be evaluated modularly, we # cannot have functions that is expected to be used in `imports` module # attribute such as functions generating a nixpkgs module. Otherwise, we'll @@ -14,18 +10,25 @@ # words, this is a strict utility library that is fully usable outside of # nixpkgs module system which is a happy accident. Hoorah for me? # +# As an additional (and obvious) design constraint, we'll start testing these +# against the Nix and nixpkgs version found on the stable release of NixOS. +# Meaning this library should not rely on additional Nix plugins and only with +# the upstream configuration. +# # And another thing, keep the `pkgs` usage down to a minimum and select the # most oft-used packages as much as possible. We want Bahaghari to be a good # citizen of the Nix ecosystem after all and as a result, we have happy users # and happy dev running in a rainbow la-la land. { pkgs }: -pkgs.lib.makeExtensible - (self: +pkgs.lib.makeExtensible (self: let - callLibs = file: import file { inherit (pkgs) lib; inherit pkgs self; }; - in - { + callLibs = file: + import file { + inherit (pkgs) lib; + inherit pkgs self; + }; + in { trivial = callLibs ./trivial.nix; hex = callLibs ./hex.nix; math = callLibs ./math.nix; @@ -44,11 +47,13 @@ pkgs.lib.makeExtensible # the namespace. tinted-theming = callLibs ./tinted-theming.nix; - inherit (self.trivial) importYAML toYAML toBaseDigitsWithGlyphs - generateGlyphSet generateConversionTable generateBaseDigitType clamp - isNumber scale optionalNull toFloat; + inherit (self.trivial) + importYAML toYAML toBaseDigitsWithGlyphs generateGlyphSet + generateConversionTable generateBaseDigitType clamp isNumber scale + optionalNull toFloat; inherit (self.hex) isHexString; - inherit (self.math) abs pow percentage factorial floor ceil round round' - summate product sqrt remainder mod radiansToDegrees degreesToRadians; + inherit (self.math) + abs pow percentage factorial floor ceil round round' summate product sqrt + remainder mod radiansToDegrees degreesToRadians; }) diff --git a/subprojects/bahaghari/lib/hex.nix b/subprojects/bahaghari/lib/hex.nix index 56876e72..b7e8029e 100644 --- a/subprojects/bahaghari/lib/hex.nix +++ b/subprojects/bahaghari/lib/hex.nix @@ -5,28 +5,10 @@ let glyphList = - [ - "0" - "1" - "2" - "3" - "4" - "5" - "6" - "7" - "8" - "9" - "A" - "B" - "C" - "D" - "E" - "F" - ]; + [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ]; baseSet = self.generateBaseDigitType glyphList; -in -rec { +in rec { inherit (baseSet) glyphSet conversionTable; /* Converts a hexadecimal digit string into its decimal equivalent. @@ -40,11 +22,7 @@ rec { toDec "ff" => 255 */ - toDec = digit: - let - digit' = lib.toUpper digit; - in - baseSet.toDec digit'; + toDec = digit: let digit' = lib.toUpper digit; in baseSet.toDec digit'; /* Converts a decimal digit into its hexadecimal notation. @@ -61,11 +39,11 @@ rec { /* A variant of `lib.lists.range` function just with hexadecimal digits. - Type: range :: Int -> Int -> [ String ] + Type: range :: Int -> Int -> [ String ] - Example: - range 15 18 - => [ "F" "10" "11" ] + Example: + range 15 18 + => [ "F" "10" "11" ] */ range = first: last: builtins.map (n: baseSet.fromDec n) (lib.lists.range first last); @@ -84,8 +62,7 @@ rec { isHexString "WHAT! HELL NO!" => false */ - isHexString = hex: - builtins.match "[A-Fa-f0-9]+" hex != null; + isHexString = hex: builtins.match "[A-Fa-f0-9]+" hex != null; /* Left pads the given hex number with the given number of max amount of digits. It will throw an error if it's not a hex string. @@ -107,10 +84,7 @@ rec { strLength = lib.stringLength hex; reqWidth = n - strLength; components = lib.genList (_: "0") reqWidth ++ [ hex ]; - in - assert lib.assertMsg (isHexString hex) + in assert lib.assertMsg (isHexString hex) "bahaghariLib.hex.pad: given hex number (${hex}) is not valid"; - if (reqWidth <= 0) - then hex - else lib.concatStringsSep "" components; + if (reqWidth <= 0) then hex else lib.concatStringsSep "" components; } diff --git a/subprojects/bahaghari/lib/tinted-theming.nix b/subprojects/bahaghari/lib/tinted-theming.nix index df00e07e..a95c6945 100644 --- a/subprojects/bahaghari/lib/tinted-theming.nix +++ b/subprojects/bahaghari/lib/tinted-theming.nix @@ -9,10 +9,8 @@ let maxDigitLength = lib.lists.length (lib.toBaseDigits 10 i); mkBaseAttr = hex: "base${self.hex.pad maxDigitLength hex}"; schemeNames = builtins.map mkBaseAttr (self.hex.range 0 (i - 1)); - in - (lib.count (name: lib.elem name schemeNames) paletteNames) == i; -in -rec { + in (lib.count (name: lib.elem name schemeNames) paletteNames) == i; +in rec { /* Imports a Base16 scheme. This also handles converting the legacy Base16 schema into the new one if it's detected. Take note, every single token that is not part of the legacy proper is assumed to be part of the @@ -40,14 +38,10 @@ rec { } */ importScheme = yamlpath: - let - scheme = self.importYAML yamlpath; - in - assert lib.assertMsg (isValidScheme scheme || isLegacyScheme scheme) + let scheme = self.importYAML yamlpath; + in assert lib.assertMsg (isValidScheme scheme || isLegacyScheme scheme) "bahaghariLib.tinted-theming.importScheme: Given data is not a valid Tinted Theming scheme"; - if isLegacyScheme scheme - then modernizeLegacyScheme scheme - else scheme; + if isLegacyScheme scheme then modernizeLegacyScheme scheme else scheme; # TODO: Return a Nix object to generate a Tinted Theming color scheme from an # image. @@ -94,8 +88,7 @@ rec { isValidScheme (bahaghariLib.tinted-theming.importScheme ./base16.yml) => true */ - isValidScheme = scheme: - scheme?palette && scheme?author && scheme?name; + isValidScheme = scheme: scheme ? palette && scheme ? author && scheme ? name; /* Checks if the given scheme is in the deprecated Base16 legacy schema. @@ -108,8 +101,7 @@ rec { isLegacyBase16 (bahaghariLib.tinted-theming.importScheme ./modern-base16-scheme.yml) => false */ - isLegacyScheme = scheme: - scheme?scheme && scheme?author; + isLegacyScheme = scheme: scheme ? scheme && scheme ? author; /* Given a legacy BaseX scheme, update the scheme into the current iteration of the Tinted Theming scheme format. @@ -129,22 +121,21 @@ rec { */ modernizeLegacyScheme = scheme: let - system = - if isBase24 scheme - then "base24" - else if isBase16 scheme - then "base16" - else null; + system = if isBase24 scheme then + "base24" + else if isBase16 scheme then + "base16" + else + null; palette = lib.attrsets.removeAttrs scheme [ "author" "description" "scheme" ]; - in - { + in { inherit (scheme) author; inherit palette; name = scheme.scheme; - } - // lib.optionalAttrs (scheme?description) { inherit (scheme) description; } - // lib.optionalAttrs (system != null) { inherit system; }; + } // lib.optionalAttrs (scheme ? description) { + inherit (scheme) description; + } // lib.optionalAttrs (system != null) { inherit system; }; } diff --git a/subprojects/bahaghari/lib/trivial.nix b/subprojects/bahaghari/lib/trivial.nix index e426975b..b7517dd7 100644 --- a/subprojects/bahaghari/lib/trivial.nix +++ b/subprojects/bahaghari/lib/trivial.nix @@ -3,201 +3,193 @@ rec { inherit (pkgs.lib.generators) toYAML; - /** - Read YAML files into a Nix expression similar to lib.importJSON and - lib.importTOML from nixpkgs standard library. Unlike both of them, this - unfortunately relies on an import-from-derivation (IFD) so it isn't exactly - perfect but it is very close. + /* * + Read YAML files into a Nix expression similar to lib.importJSON and + lib.importTOML from nixpkgs standard library. Unlike both of them, this + unfortunately relies on an import-from-derivation (IFD) so it isn't exactly + perfect but it is very close. - This relies on yaml2json which uses the following YAML library which you - can view the following link for more details on YAML compatibility. + This relies on yaml2json which uses the following YAML library which you + can view the following link for more details on YAML compatibility. - https://pkg.go.dev/gopkg.in/yaml.v3#readme-compatibility + https://pkg.go.dev/gopkg.in/yaml.v3#readme-compatibility - # Arguments + # Arguments - file - : The filepath of the YAML file. + file + : The filepath of the YAML file. - # Type + # Type - ``` - importYAML :: Path -> any - ``` + ``` + importYAML :: Path -> any + ``` - # Example + # Example - ``` - importYAML ./simple.yml - => - { - hello = "there"; - how-are-you-doing = "I'm fine. Thank you for asking."; - } - ``` + ``` + importYAML ./simple.yml + => + { + hello = "there"; + how-are-you-doing = "I'm fine. Thank you for asking."; + } + ``` */ importYAML = path: let dataDrv = pkgs.runCommand "convert-yaml-to-json" { } '' ${lib.getExe' pkgs.yaml2json "yaml2json"} < "${path}" > "$out" ''; - in - lib.importJSON dataDrv; + in lib.importJSON dataDrv; - /** - Convert a given decimal number to a specified base digit with the set of - glyphs for each digit as returned from lib.toBaseDigits. + /* * + Convert a given decimal number to a specified base digit with the set of + glyphs for each digit as returned from lib.toBaseDigits. - # Arguments + # Arguments - base - : The base index. + base + : The base index. - glyphs - : An attribute set of decimal values and their glyphs. + glyphs + : An attribute set of decimal values and their glyphs. - i - : The actual integer to be converted. + i + : The actual integer to be converted. - # Type + # Type - ``` - toBaseDigitWithGlyphs :: Int -> Int -> Attrs -> String - ``` + ``` + toBaseDigitWithGlyphs :: Int -> Int -> Attrs -> String + ``` - # Example + # Example - ``` - toBaseDigitWithGlyphs 24 267 { - "0" = "0"; - "1" = "1"; - "2" = "2"; - # ... - "22" = "M"; - "23" = "N"; - } - => - "12H" + ``` + toBaseDigitWithGlyphs 24 267 { + "0" = "0"; + "1" = "1"; + "2" = "2"; + # ... + "22" = "M"; + "23" = "N"; + } + => + "12H" - toBaseDigitWithGlyphs - ``` + toBaseDigitWithGlyphs + ``` */ toBaseDigitsWithGlyphs = base: glyphs: i: let baseDigits = lib.toBaseDigits base i; toBaseDigits = d: glyphs.${builtins.toString d}; - in - lib.concatMapStrings toBaseDigits baseDigits; + in lib.concatMapStrings toBaseDigits baseDigits; - /** - Generates a glyph set usable for `toBaseDigitsWithGlyphs`. Take note the - given list is assumed to be sorted and the generated glyph set starts at - `0` up to (`listLength - 1`). + /* * + Generates a glyph set usable for `toBaseDigitsWithGlyphs`. Take note the + given list is assumed to be sorted and the generated glyph set starts at + `0` up to (`listLength - 1`). - # Arguments + # Arguments - glyphsList - : A sorted list of glyphs. + glyphsList + : A sorted list of glyphs. - # Type + # Type - ``` - generateGlyphSet :: [ String ] -> Attrs - ``` + ``` + generateGlyphSet :: [ String ] -> Attrs + ``` - # Example + # Example - ``` - generateGlyphSet [ "0" "1" "2" "3" "4" "5" "6" "7" "8 "9" "A" "B" "C" "D" "E" "F" ] - => - { - "0" = "0"; - "1" = "1"; - # ... - "14" = "E"; - "15" = "F"; - } - ``` + ``` + generateGlyphSet [ "0" "1" "2" "3" "4" "5" "6" "7" "8 "9" "A" "B" "C" "D" "E" "F" ] + => + { + "0" = "0"; + "1" = "1"; + # ... + "14" = "E"; + "15" = "F"; + } + ``` */ generateGlyphSet = glyphsList: let - glyphsList' = - lib.lists.imap0 - (i: glyph: lib.nameValuePair (builtins.toString i) glyph) - glyphsList; - in - lib.listToAttrs glyphsList'; + glyphsList' = lib.lists.imap0 + (i: glyph: lib.nameValuePair (builtins.toString i) glyph) glyphsList; + in lib.listToAttrs glyphsList'; - /** - Generates a conversion table for a sorted list of glyphs to its decimal - number. Suitable for creating your own conversion function. Accepts the - same argument as `generateGlyphSet`. + /* * + Generates a conversion table for a sorted list of glyphs to its decimal + number. Suitable for creating your own conversion function. Accepts the + same argument as `generateGlyphSet`. - # Arguments + # Arguments - glyphsList - : A sorted list of glyphs. + glyphsList + : A sorted list of glyphs. - # Type + # Type - ``` - generateConversionTable :: [ String ] -> Attrs - ``` + ``` + generateConversionTable :: [ String ] -> Attrs + ``` - # Example + # Example - ``` - generateConversionTable [ "0" "1" "2" "3" "4" "5" "6" "7" "8 "9" "A" "B" "C" "D" "E" "F" ] - => - { - "0" = 0; - "1" = 1; - # ... - "E" = 14; - "F" = 15; - } - ``` + ``` + generateConversionTable [ "0" "1" "2" "3" "4" "5" "6" "7" "8 "9" "A" "B" "C" "D" "E" "F" ] + => + { + "0" = 0; + "1" = 1; + # ... + "E" = 14; + "F" = 15; + } + ``` */ generateConversionTable = glyphsList: let glyphsList' = - lib.lists.imap0 - (i: glyph: lib.nameValuePair glyph i) - glyphsList; - in - lib.listToAttrs glyphsList'; + lib.lists.imap0 (i: glyph: lib.nameValuePair glyph i) glyphsList; + in lib.listToAttrs glyphsList'; - /** - A factory function for generating an attribute set containing a glyph - set, a conversion table, and a conversion function to and from decimal. - Accepts the same list as `generateGlyphSet` and - `generateConversionTable` where it assumes it is sorted and - zero-indexed. + /* * + A factory function for generating an attribute set containing a glyph + set, a conversion table, and a conversion function to and from decimal. + Accepts the same list as `generateGlyphSet` and + `generateConversionTable` where it assumes it is sorted and + zero-indexed. - # Arguments + # Arguments - glyphsList - : A sorted list of glyphs. + glyphsList + : A sorted list of glyphs. - # Type + # Type - ``` - generateBaseDigitType :: [ String ] -> Attrs - ``` + ``` + generateBaseDigitType :: [ String ] -> Attrs + ``` - # Example + # Example - ``` - generateBaseDigitType [ "0" "1" ] - => - { - base = 2; - glyphSet = { "0" = "0"; "1" = "1"; }; - conversionTable = { "0" = 0; "1" = 1; }; - fromDec = ; - toDec = ; - } - ``` + ``` + generateBaseDigitType [ "0" "1" ] + => + { + base = 2; + glyphSet = { "0" = "0"; "1" = "1"; }; + conversionTable = { "0" = 0; "1" = 1; }; + fromDec = ; + toDec = ; + } + ``` */ generateBaseDigitType = glyphsList: rec { base = lib.length glyphsList; @@ -210,193 +202,185 @@ rec { # generation that typically uses hexadecimal (RGB). Plus I don't want to # open a can of worms about implementing this with stringy types. fromDec = decimal: - let - digits = lib.toBaseDigits base decimal; - in - lib.concatMapStrings (d: glyphSet.${builtins.toString d}) digits; + let digits = lib.toBaseDigits base decimal; + in lib.concatMapStrings (d: glyphSet.${builtins.toString d}) digits; toDec = digit: let chars = lib.stringToCharacters digit; maxDigits = (lib.length chars) - 1; - convertDigitToDec = - lib.lists.imap0 (i: v: conversionTable.${v} * (self.math.pow base (maxDigits - i))) chars; - in - lib.foldl (sum: v: sum + v) 0 convertDigitToDec; + convertDigitToDec = lib.lists.imap0 + (i: v: conversionTable.${v} * (self.math.pow base (maxDigits - i))) + chars; + in lib.foldl (sum: v: sum + v) 0 convertDigitToDec; }; - /** - Given a range of two numbers, ensure the value is only returned within the - range. + /* * + Given a range of two numbers, ensure the value is only returned within the + range. - # Arguments + # Arguments - min - : Minimum number of the range. + min + : Minimum number of the range. - max - : Maximum number of the range. + max + : Maximum number of the range. - value - : Number to be used for the function. + value + : Number to be used for the function. - # Type + # Type - ``` - clamp :: Number -> Number -> Number -> Number - ``` + ``` + clamp :: Number -> Number -> Number -> Number + ``` - # Example + # Example - ``` - clamp 0 255 654 - => - 255 + ``` + clamp 0 255 654 + => + 255 - clamp (-100) 100 (-234) - => - -100 + clamp (-100) 100 (-234) + => + -100 - clamp (-100) 100 54 - => - 54 - ``` + clamp (-100) 100 54 + => + 54 + ``` */ - clamp = min: max: value: - lib.min max (lib.max min value); + clamp = min: max: value: lib.min max (lib.max min value); - /** - Given a value, check if it's a number type. + /* * + Given a value, check if it's a number type. - # Arguments + # Arguments - value - : Numerical value. + value + : Numerical value. - # Type + # Type - ``` - isNumber :: Number -> bool - ``` + ``` + isNumber :: Number -> bool + ``` - # Example: + # Example: - ``` - isNumber 3.0 - => - true + ``` + isNumber 3.0 + => + true - isNumber 653 - => - true + isNumber 653 + => + true - isNumber true - => - false - ``` + isNumber true + => + false + ``` */ - isNumber = v: - lib.isInt v || lib.isFloat v; + isNumber = v: lib.isInt v || lib.isFloat v; - /** - Given a Nix number, force it to be a floating value. + /* * + Given a Nix number, force it to be a floating value. - # Arguments + # Arguments - value - : The numerical value. + value + : The numerical value. - # Type + # Type - ``` - toFloat :: Number -> Float - ``` + ``` + toFloat :: Number -> Float + ``` - # Example + # Example - ``` - toFloat 5 - => - 5.0 + ``` + toFloat 5 + => + 5.0 - toFloat 59.0 - => - 59.0 - ``` + toFloat 59.0 + => + 59.0 + ``` */ - toFloat = x: - 1.0 * x; + toFloat = x: 1.0 * x; - /** - Given an initial range of integers, scale the given number with its own - set of range. + /* * + Given an initial range of integers, scale the given number with its own + set of range. - # Arguments + # Arguments - rangeSet - : An attribute set containing the following attributes: `inMin` and `inMax` - for specifying the input's expected range and `outMin` and `outMax` for the - output's. + rangeSet + : An attribute set containing the following attributes: `inMin` and `inMax` + for specifying the input's expected range and `outMin` and `outMax` for the + output's. - value - : The numerical value. + value + : The numerical value. - # Type + # Type - ``` - scale :: Attrs -> Number -> Number - ``` + ``` + scale :: Attrs -> Number -> Number + ``` - # Example + # Example - ``` - scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } 4 - => - 68 + ``` + scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } 4 + => + 68 - scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } (-4) - => - -68 + scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } (-4) + => + -68 - scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } 15 - => - 255 - ``` + scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } 15 + => + 255 + ``` */ - scale = { inMin, inMax, outMin, outMax }: v: + scale = { inMin, inMax, outMin, outMax }: + v: ((v - inMin) * (outMax - outMin)) / ((inMax - inMin) + outMin); - /** - Returns a null value if the condition fails. Otherwise, returns the given - value `as`. + /* * + Returns a null value if the condition fails. Otherwise, returns the given + value `as`. - # Arguments + # Arguments - cond - : Condition that should evaluate as a boolean. + cond + : Condition that should evaluate as a boolean. - as - : Value to be returned if condition returns true. + as + : Value to be returned if condition returns true. - # Type + # Type - ``` - optionalNull :: Bool -> Any -> Any - ``` + ``` + optionalNull :: Bool -> Any -> Any + ``` - # Example + # Example - ``` - optionalNull true "HELLO" - => "HELLO" + ``` + optionalNull true "HELLO" + => "HELLO" - optionalNull (null != null) "HELLO" - => null - ``` + optionalNull (null != null) "HELLO" + => null + ``` */ - optionalNull = cond: as: - if cond then - as - else - null; + optionalNull = cond: as: if cond then as else null; } diff --git a/subprojects/bahaghari/modules/default.nix b/subprojects/bahaghari/modules/default.nix index f198acdd..475e2def 100644 --- a/subprojects/bahaghari/modules/default.nix +++ b/subprojects/bahaghari/modules/default.nix @@ -1,6 +1 @@ -{ - imports = [ - ./tinted-theming - ./extra-arguments.nix - ]; -} +{ imports = [ ./tinted-theming ./extra-arguments.nix ]; } diff --git a/subprojects/bahaghari/modules/extra-arguments.nix b/subprojects/bahaghari/modules/extra-arguments.nix index e0459b69..2fb6e914 100644 --- a/subprojects/bahaghari/modules/extra-arguments.nix +++ b/subprojects/bahaghari/modules/extra-arguments.nix @@ -1,9 +1,7 @@ { config, lib, pkgs, ... }: -let - bahaghariLib = import ../lib { inherit pkgs; }; -in -{ +let bahaghariLib = import ../lib { inherit pkgs; }; +in { # Setting the Bahaghari lib and extra utilities. The extra utilities are # largely based from the `utils` module argument found in NixOS systems. _module.args = { diff --git a/subprojects/bahaghari/modules/tinted-theming/default.nix b/subprojects/bahaghari/modules/tinted-theming/default.nix index 01539ad0..f2379594 100644 --- a/subprojects/bahaghari/modules/tinted-theming/default.nix +++ b/subprojects/bahaghari/modules/tinted-theming/default.nix @@ -1,8 +1,4 @@ # Bahaghari's Tinted Theming user-facing module set. { - imports = [ - ./builder.nix - ./schemes.nix - ./templates.nix - ]; + imports = [ ./builder.nix ./schemes.nix ./templates.nix ]; } diff --git a/subprojects/bahaghari/modules/tinted-theming/schemes.nix b/subprojects/bahaghari/modules/tinted-theming/schemes.nix index 4c228d80..2dc7bd74 100644 --- a/subprojects/bahaghari/modules/tinted-theming/schemes.nix +++ b/subprojects/bahaghari/modules/tinted-theming/schemes.nix @@ -24,12 +24,12 @@ let # also detect this ourselves as well... but with Nixlang? REALLY!?! system = lib.mkOption { type = with lib.types; nullOr (enum [ "base16" "base24" ]); - default = - if (isBase24 config.palette) - then "base24" - else if (isBase16 config.palette) - then "base16" - else null; + default = if (isBase24 config.palette) then + "base24" + else if (isBase16 config.palette) then + "base16" + else + null; example = "base24"; description = '' Indicates which system this scheme supports. This is mainly on the @@ -74,9 +74,8 @@ let }; palette = lib.mkOption { - type = with lib.types; attrsOf ( - coercedTo str (lib.removePrefix "#") str - ); + type = with lib.types; + attrsOf (coercedTo str (lib.removePrefix "#") str); default = { }; example = { base00 = "2b221f"; @@ -104,8 +103,7 @@ let }; }; }; -in -{ +in { options.bahaghari.tinted-theming = { schemes = lib.mkOption { type = with lib.types; attrsOf (submodule schemeType); diff --git a/subprojects/bahaghari/shell.nix b/subprojects/bahaghari/shell.nix index c025b6cd..16c42d64 100644 --- a/subprojects/bahaghari/shell.nix +++ b/subprojects/bahaghari/shell.nix @@ -1,17 +1,14 @@ -let - sources = import ./npins; -in -{ pkgs ? import sources.nixos-stable { } }: +let sources = import ./npins; +in { pkgs ? import sources.nixos-stable { } }: with pkgs; mkShell { - inputsFrom = [ - nix - ]; + inputsFrom = [ nix ]; packages = [ npins + nixdoc treefmt nixfmt-rfc-style diff --git a/subprojects/bahaghari/tests/default.nix b/subprojects/bahaghari/tests/default.nix index 5643ea1d..5e6d253d 100644 --- a/subprojects/bahaghari/tests/default.nix +++ b/subprojects/bahaghari/tests/default.nix @@ -7,21 +7,16 @@ let sources = import ../npins; pkgs = import sources."nixos-${branch}" { inherit system; }; bahaghariLib = import ./lib { inherit pkgs; }; -in -{ +in { lib = bahaghariLib; - libTestPkg = - pkgs.runCommand "bahaghari-lib-test" - { - testData = builtins.toJSON bahaghariLib; - passAsFile = [ "testData" ]; - nativeBuildInputs = with pkgs; [ - yajsv - jq - ]; - } - '' - yajsv -s "${./lib/tests.schema.json}" "$testDataPath" && touch $out || jq . "$testDataPath" - ''; + libTestPkg = pkgs.runCommand "bahaghari-lib-test" { + testData = builtins.toJSON bahaghariLib; + passAsFile = [ "testData" ]; + nativeBuildInputs = with pkgs; [ yajsv jq ]; + } '' + yajsv -s "${ + ./lib/tests.schema.json + }" "$testDataPath" && touch $out || jq . "$testDataPath" + ''; #modules = import ./modules { inherit pkgs; }; } diff --git a/subprojects/bahaghari/tests/lib/default.nix b/subprojects/bahaghari/tests/lib/default.nix index f0cff478..c9c64831 100644 --- a/subprojects/bahaghari/tests/lib/default.nix +++ b/subprojects/bahaghari/tests/lib/default.nix @@ -2,12 +2,13 @@ let lib = import ../../lib { inherit pkgs; }; - callLib = file: import file { - inherit (pkgs) lib; inherit pkgs; - self = lib; - }; -in -{ + callLib = file: + import file { + inherit (pkgs) lib; + inherit pkgs; + self = lib; + }; +in { hex = callLib ./hex.nix; math = callLib ./math.nix; trivial = callLib ./trivial; diff --git a/subprojects/bahaghari/tests/lib/hex.nix b/subprojects/bahaghari/tests/lib/hex.nix index bd558ded..6daecb2f 100644 --- a/subprojects/bahaghari/tests/lib/hex.nix +++ b/subprojects/bahaghari/tests/lib/hex.nix @@ -58,7 +58,8 @@ lib.runTests { testCreateHexRange2 = { expr = self.hex.range 64 76; - expected = [ "40" "41" "42" "43" "44" "45" "46" "47" "48" "49" "4A" "4B" "4C" ]; + expected = + [ "40" "41" "42" "43" "44" "45" "46" "47" "48" "49" "4A" "4B" "4C" ]; }; testCreateHexWithHigherStart = { diff --git a/subprojects/bahaghari/tests/lib/tinted-theming/default.nix b/subprojects/bahaghari/tests/lib/tinted-theming/default.nix index 68f34584..c09c9192 100644 --- a/subprojects/bahaghari/tests/lib/tinted-theming/default.nix +++ b/subprojects/bahaghari/tests/lib/tinted-theming/default.nix @@ -1,12 +1,15 @@ { pkgs, lib, self }: let - sampleBase16Scheme = self.tinted-theming.importScheme ./sample-base16-scheme.yml; - sampleBase16Scheme' = self.tinted-theming.importScheme ./sample-base16-scheme-with-missing-colors.yml; - sampleBase24Scheme = self.tinted-theming.importScheme ./sample-base24-scheme.yml; - sampleBase24Scheme' = self.tinted-theming.importScheme ./sample-base24-scheme-with-missing-colors.yml; -in -lib.runTests { + sampleBase16Scheme = + self.tinted-theming.importScheme ./sample-base16-scheme.yml; + sampleBase16Scheme' = self.tinted-theming.importScheme + ./sample-base16-scheme-with-missing-colors.yml; + sampleBase24Scheme = + self.tinted-theming.importScheme ./sample-base24-scheme.yml; + sampleBase24Scheme' = self.tinted-theming.importScheme + ./sample-base24-scheme-with-missing-colors.yml; +in lib.runTests { testTintedThemingSchemeImport = { expr = self.tinted-theming.importScheme ./sample-base16-scheme.yml; expected = { @@ -121,12 +124,14 @@ lib.runTests { }; testIsALegacyBase16Scheme = { - expr = self.tinted-theming.isLegacyScheme (self.importYAML ./sample-legacy-base16.yml); + expr = self.tinted-theming.isLegacyScheme + (self.importYAML ./sample-legacy-base16.yml); expected = true; }; testIsALegacyBase24Scheme = { - expr = self.tinted-theming.isLegacyScheme (self.importYAML ./sample-legacy-base24.yml); + expr = self.tinted-theming.isLegacyScheme + (self.importYAML ./sample-legacy-base24.yml); expected = true; }; } diff --git a/subprojects/bahaghari/tests/lib/trivial/default.nix b/subprojects/bahaghari/tests/lib/trivial/default.nix index 8d9bec5c..eb43d92f 100644 --- a/subprojects/bahaghari/tests/lib/trivial/default.nix +++ b/subprojects/bahaghari/tests/lib/trivial/default.nix @@ -71,8 +71,7 @@ let }; base24Set = self.trivial.generateBaseDigitType base24GlyphsList; -in -lib.runTests { +in lib.runTests { testGenerateCustomGlyphSet = { expr = self.trivial.generateGlyphSet [ "A" "B" "C" "D" "E" "F" "G" "H" ]; expected = customOctalGlyphs; @@ -84,7 +83,8 @@ lib.runTests { }; testGenerateConversionTable = { - expr = self.trivial.generateConversionTable [ "A" "B" "C" "D" "E" "F" "G" "H" ]; + expr = + self.trivial.generateConversionTable [ "A" "B" "C" "D" "E" "F" "G" "H" ]; expected = { "A" = 0; "B" = 1; @@ -98,25 +98,24 @@ lib.runTests { }; testGenerateConversionTable2 = { - expr = self.trivial.generateConversionTable - [ - "0" - "1" - "2" - "3" - "4" - "5" - "6" - "7" - "8" - "9" - "A" - "B" - "C" - "D" - "E" - "F" - ]; + expr = self.trivial.generateConversionTable [ + "0" + "1" + "2" + "3" + "4" + "5" + "6" + "7" + "8" + "9" + "A" + "B" + "C" + "D" + "E" + "F" + ]; expected = { "0" = 0; "1" = 1; @@ -149,22 +148,22 @@ lib.runTests { }; testBaseDigitWithCustomOctalGlyph = { - expr = self.trivial.toBaseDigitsWithGlyphs 8 9 customOctalGlyphs; + expr = self.trivial.toBaseDigitsWithGlyphs 8 customOctalGlyphs 9; expected = "BB"; }; testBaseDigitWithCustomOctalGlyph2 = { - expr = self.trivial.toBaseDigitsWithGlyphs 8 641 customOctalGlyphs; + expr = self.trivial.toBaseDigitsWithGlyphs 8 customOctalGlyphs 641; expected = "BCAB"; }; testBaseDigitWithProperBase24Glyph = { - expr = self.trivial.toBaseDigitsWithGlyphs 24 641 customBase24Glyphs; + expr = self.trivial.toBaseDigitsWithGlyphs 24 customBase24Glyphs 641; expected = "12H"; }; testBaseDigitWithProperBase24Glyph2 = { - expr = self.trivial.toBaseDigitsWithGlyphs 24 2583 customBase24Glyphs; + expr = self.trivial.toBaseDigitsWithGlyphs 24 customBase24Glyphs 2583; expected = "4BF"; }; @@ -174,7 +173,9 @@ lib.runTests { expr = self.trivial.importYAML ./simple.yml; expected = { hello = "there"; - how-are-you-doing = "I'm fine. Thank you for asking.\n"; + how-are-you-doing = '' + I'm fine. Thank you for asking. + ''; "It's a number" = 53; dog-breeds = [ "chihuahua" "golden retriever" ]; }; @@ -212,7 +213,7 @@ lib.runTests { # YAML is a superset of JSON (or was it the other way around?) after v1.2. testToYAML = { expr = self.trivial.toYAML { } { hello = "there"; }; - expected = "{\"hello\":\"there\"}"; + expected = ''{"hello":"there"}''; }; testNumberClamp = { @@ -231,32 +232,62 @@ lib.runTests { }; testNumberScale = { - expr = self.trivial.scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } 15; + expr = self.trivial.scale { + inMin = 0; + inMax = 15; + outMin = 0; + outMax = 255; + } 15; expected = 255; }; testNumberScale2 = { - expr = self.trivial.scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } 4; + expr = self.trivial.scale { + inMin = 0; + inMax = 15; + outMin = 0; + outMax = 255; + } 4; expected = 68; }; testNumberScale3 = { - expr = self.trivial.scale { inMin = 0; inMax = 15; outMin = 0; outMax = 255; } (-4); + expr = self.trivial.scale { + inMin = 0; + inMax = 15; + outMin = 0; + outMax = 255; + } (-4); expected = (-68); }; testNumberScaleFloat = { - expr = self.trivial.scale { inMin = 0; inMax = 255; outMin = 0.0; outMax = 1.0; } 255; + expr = self.trivial.scale { + inMin = 0; + inMax = 255; + outMin = 0.0; + outMax = 1.0; + } 255; expected = 1.0; }; testNumberScaleFloat2 = { - expr = self.trivial.scale { inMin = 0; inMax = 255; outMin = 0.0; outMax = 1.0; } 127.5; + expr = self.trivial.scale { + inMin = 0; + inMax = 255; + outMin = 0.0; + outMax = 1.0; + } 127.5; expected = 0.5; }; testNumberScaleFloat3 = { - expr = round' (self.trivial.scale { inMin = 0; inMax = 255; outMin = 0.0; outMax = 1.0; } 53); + expr = round' (self.trivial.scale { + inMin = 0; + inMax = 255; + outMin = 0.0; + outMax = 1.0; + } 53); expected = round' 0.207843; }; diff --git a/subprojects/bahaghari/utils/default.nix b/subprojects/bahaghari/utils/default.nix index 7b9b7ab0..e38a9c78 100644 --- a/subprojects/bahaghari/utils/default.nix +++ b/subprojects/bahaghari/utils/default.nix @@ -1,8 +1,4 @@ { config, lib, pkgs, bahaghariLib }@args: -let - callLib = path: import path args; -in -{ - tinted-theming = callLib ./tinted-theming.nix; -} +let callLib = path: import path args; +in { tinted-theming = callLib ./tinted-theming.nix; } diff --git a/subprojects/bahaghari/utils/tinted-theming.nix b/subprojects/bahaghari/utils/tinted-theming.nix index a6accbf0..409c6b1c 100644 --- a/subprojects/bahaghari/utils/tinted-theming.nix +++ b/subprojects/bahaghari/utils/tinted-theming.nix @@ -1,26 +1,20 @@ { config, lib, pkgs, bahaghariLib }: -let - cfg = config.bahaghari.tinted-theming; -in -rec { +let cfg = config.bahaghari.tinted-theming; +in rec { # Return a derivation containing all of the template output from the given # schemes. generateOutputFromSchemes = { schemes ? { }, template }: let - schemesDir = pkgs.runCommand "aggregate-schemes" { } - '' - mkdir -p "$out" - ${ - lib.concatMapStrings (scheme: '' - echo < "$out/${scheme.name}.yml" - ${bahaghariLib.toYAML scheme} - EOF - '') lib.attrNames schemes - } - ''; - in - pkgs.runCommand "generate-templates" { } (cfg.builder.script { + schemesDir = pkgs.runCommand "aggregate-schemes" { } '' + mkdir -p "$out" + ${lib.concatMapStrings (scheme: '' + echo < "$out/${scheme.name}.yml" + ${bahaghariLib.toYAML scheme} + EOF + '') lib.attrNames schemes} + ''; + in pkgs.runCommand "generate-templates" { } (cfg.builder.script { inherit schemesDir; templateDir = template; }); @@ -28,5 +22,8 @@ rec { # Return a derivation containing the generated template with the given # builder script with all of the Tinted Theming schemes. generateOutputFromAllSchemes = { template }: - generateOutputFromSchemes { schemes = cfg.schemes; inherit template; }; + generateOutputFromSchemes { + schemes = cfg.schemes; + inherit template; + }; }