Add NixOS module

This commit is contained in:
Agatha Lovelace 2023-04-20 22:01:38 +02:00
parent 06b6ae85e8
commit 2574b83cb0
Signed by: sorceress
GPG Key ID: 01D0B3AB10CED4F8
5 changed files with 82 additions and 5 deletions

1
.direnv/flake-profile Symbolic link
View File

@ -0,0 +1 @@
flake-profile-1-link

View File

@ -0,0 +1 @@
/nix/store/vhxg5a3va792mff3i55jgcd2fayjzc2z-nix-shell-env

View File

@ -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

View File

@ -33,4 +33,20 @@ Options:
--saturate <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"; }
```

View File

@ -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;
};
};
};
}