From 2574b83cb0454a146a0346bf0d6a134d62241e60 Mon Sep 17 00:00:00 2001 From: "Agatha V. Lovelace" Date: Thu, 20 Apr 2023 22:01:38 +0200 Subject: [PATCH] Add NixOS module --- .direnv/flake-profile | 1 + .direnv/flake-profile-1-link | 1 + .github/workflows/build_nix.yml | 6 ++-- README.md | 16 +++++++++ flake.nix | 63 +++++++++++++++++++++++++++++++-- 5 files changed, 82 insertions(+), 5 deletions(-) create mode 120000 .direnv/flake-profile create mode 120000 .direnv/flake-profile-1-link diff --git a/.direnv/flake-profile b/.direnv/flake-profile new file mode 120000 index 0000000..0c05709 --- /dev/null +++ b/.direnv/flake-profile @@ -0,0 +1 @@ +flake-profile-1-link \ No newline at end of file diff --git a/.direnv/flake-profile-1-link b/.direnv/flake-profile-1-link new file mode 120000 index 0000000..71d827c --- /dev/null +++ b/.direnv/flake-profile-1-link @@ -0,0 +1 @@ +/nix/store/vhxg5a3va792mff3i55jgcd2fayjzc2z-nix-shell-env \ No newline at end of file diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml index c58ea8f..88a0031 100644 --- a/.github/workflows/build_nix.yml +++ b/.github/workflows/build_nix.yml @@ -10,8 +10,10 @@ jobs: - uses: actions/checkout@v3 - uses: cachix/install-nix-action@v12 - name: Building package - run: nix-build . -A defaultPackage.x86_64-linux + run: nix-build . -A packages.x86_64-linux.default + - name: Get commit hash + run: echo "COMMIT_HASH=${GITHUB_SHA::6}" >> $GITHUB_ENV - uses: actions/upload-artifact@v3 with: - name: url-eater-x86_64-linux + name: colorpickle-${{ env.COMMIT_HASH }}-x86_64-linux path: result/bin/colorpickle diff --git a/README.md b/README.md index 7b18f42..f23db2d 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,20 @@ Options: --saturate Saturate/desaturate colors [default: 0] -h, --help Print help -V, --version Print version +``` + +## Using the NixOS module + +After importing the NixOS module exposed by this flake, a colorscheme can be defined like this: +```nix +environment.graphical.colorschemes.purple = { + image = ../../../external/6.png; + params = [ "--lighten" "0.05" "--bold-delta" "0.1" ]; +}; +``` +The generated colors will be accessible from `environment.graphical.colors.purple` +as an attribute set of hex color strings: +``` +nix-repl> nodes.ritual.config.environment.graphical.colors.purple +{ "0" = "#19172b"; "1" = "#453354"; "10" = "#90629a"; "11" = "#7a6d98"; "12" = "#9a79ab"; "13" = "#a6a1bc"; "14" = "#b69dba"; "15" = "#d0c5dc"; "16" = ""; "2" = "#734e7b"; "3" = "#62577b"; "4" = "#825d94"; "5" = "#8a83a7"; "6" = "#a07fa5"; "7" = "#b7a5c9"; "8" = "#2c294c"; "9" = "#5f4674"; } ``` \ No newline at end of file diff --git a/flake.nix b/flake.nix index 845d2de..faf8c60 100644 --- a/flake.nix +++ b/flake.nix @@ -11,8 +11,8 @@ pkgs = import nixpkgs { inherit system; }; naersk-lib = pkgs.callPackage naersk { }; in { - defaultPackage = naersk-lib.buildPackage ./.; - devShell = with pkgs; + packages.default = naersk-lib.buildPackage ./.; + devShells.default = with pkgs; mkShell { buildInputs = [ cargo @@ -24,5 +24,62 @@ ]; RUST_SRC_PATH = rustPlatform.rustLibSrc; }; - }); + }) // { + nixosModules.default = { config, lib, pkgs, ... }: + with lib; { + options.environment.graphical = with types; { + colorschemes = mkOption { + default = { }; + type = attrsOf (submodule { + options = { + image = mkOption { + type = either str path; + description = + "Path to image that will be used as input for colorscheme generation"; + }; + params = mkOption { + type = listOf str; + default = [ ]; + description = + mdDoc "list of parameters to pass to `colorpickle`"; + example = [ + "--colors" + "8" + "--lighten" + "0.05" + "--bold-delta" + "0.1" + ]; + }; + }; + }); + }; + colors = mkOption { + default = { }; + type = attrsOf (attrsOf str); + }; + }; + + config = let + generate = name: image: args: + pkgs.runCommand "colors-${name}" { + nativeBuildInputs = [ self.packages.${pkgs.system}.default ]; + } '' + colorpickle ${image} ${ + lib.strings.concatStringsSep " " args + } > $out + ''; + formattedColors = name: image: args: + builtins.listToAttrs (lib.lists.imap0 (i: v: { + name = builtins.toString i; + value = v; + }) (lib.strings.splitString "\n" + (builtins.readFile (generate name image args)))); + in { + environment.graphical.colors = lib.attrsets.mapAttrs + (name: value: formattedColors name value.image value.params) + config.environment.graphical.colorschemes; + }; + }; + }; }