feat: home-manager module
This commit is contained in:
1 parent
85559b1031
commit
4c6ee710a8
4 files changed
+132
-3
No files matched your search
+66
-2
@@ -1,10 +1,45 @@
|
|||||||
{ ... }:
|
{ self, ... }:
|
||||||
{
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, self', ... }:
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
self',
|
||||||
|
...
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
valw = self'.packages.default;
|
valw = self'.packages.default;
|
||||||
|
|
||||||
|
# The home-manager module, evaluated with stand-ins for the two
|
||||||
|
# home-manager options it sets (no home-manager input needed).
|
||||||
|
homeModule =
|
||||||
|
settings:
|
||||||
|
(lib.evalModules {
|
||||||
|
modules = [
|
||||||
|
self.homeModules.default
|
||||||
|
(
|
||||||
|
{ lib, ... }:
|
||||||
|
{
|
||||||
|
options.home.packages = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.package;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
options.xdg.configFile = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (
|
||||||
|
lib.types.submodule { options.source = lib.mkOption { type = lib.types.path; }; }
|
||||||
|
);
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
config._module.args.pkgs = pkgs;
|
||||||
|
config.programs.valw = {
|
||||||
|
enable = true;
|
||||||
|
inherit settings;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}).config;
|
||||||
|
|
||||||
# Reuses the package's vendored dependencies, runs `cmd` instead of the build.
|
# Reuses the package's vendored dependencies, runs `cmd` instead of the build.
|
||||||
cargoCheck =
|
cargoCheck =
|
||||||
name: tools: cmd:
|
name: tools: cmd:
|
||||||
@@ -19,6 +54,35 @@
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
checks = {
|
checks = {
|
||||||
|
home-module =
|
||||||
|
let
|
||||||
|
plain = homeModule { };
|
||||||
|
set = homeModule {
|
||||||
|
preview.timeout_secs = 3;
|
||||||
|
sound.volume = 0.4;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
assert lib.assertMsg (plain.home.packages == [ valw ]) "the module installs valw";
|
||||||
|
assert lib.assertMsg (plain.xdg.configFile == { }) "no settings, no config file";
|
||||||
|
pkgs.runCommand "valw-home-module" { } ''
|
||||||
|
grep -qx 'timeout_secs = 3' ${set.xdg.configFile."valw/config.toml".source}
|
||||||
|
grep -qx 'volume = 0.4' ${set.xdg.configFile."valw/config.toml".source}
|
||||||
|
touch $out
|
||||||
|
'';
|
||||||
|
|
||||||
|
home-module-rejects =
|
||||||
|
let
|
||||||
|
fails =
|
||||||
|
settings:
|
||||||
|
pkgs.testers.testBuildFailure (homeModule settings).xdg.configFile."valw/config.toml".source;
|
||||||
|
in
|
||||||
|
pkgs.runCommand "valw-home-module-rejects" { } ''
|
||||||
|
grep -q 'sound.volume must be between 0 and 1' ${fails { sound.volume = 2; }}/testBuildFailure.log
|
||||||
|
grep -q 'unknown config key: preview.timout_secs' ${
|
||||||
|
fails { preview.timout_secs = 3; }
|
||||||
|
}/testBuildFailure.log
|
||||||
|
touch $out
|
||||||
|
'';
|
||||||
clippy = cargoCheck "clippy" [ pkgs.clippy ] "cargo clippy --all-targets --offline -- -D warnings";
|
clippy = cargoCheck "clippy" [ pkgs.clippy ] "cargo clippy --all-targets --offline -- -D warnings";
|
||||||
nextest = cargoCheck "nextest" [ pkgs.cargo-nextest ] "cargo nextest run --offline";
|
nextest = cargoCheck "nextest" [ pkgs.cargo-nextest ] "cargo nextest run --offline";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, lib, self', ... }:
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
self',
|
||||||
|
...
|
||||||
|
}:
|
||||||
{
|
{
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
inputsFrom = [ self'.packages.default ];
|
inputsFrom = [ self'.packages.default ];
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
{ withSystem, ... }:
|
||||||
|
{
|
||||||
|
flake.homeModules.default =
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.programs.valw;
|
||||||
|
toml = pkgs.formats.toml { };
|
||||||
|
# valw checks its own config: a typo or a bad value fails the build.
|
||||||
|
checked =
|
||||||
|
settings:
|
||||||
|
let
|
||||||
|
file = toml.generate "valw-config.toml" settings;
|
||||||
|
in
|
||||||
|
pkgs.runCommand "valw-config.toml" { } ''
|
||||||
|
${lib.getExe cfg.package} __check-config ${file}
|
||||||
|
cp ${file} $out
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.programs.valw = {
|
||||||
|
enable = lib.mkEnableOption "valw, macOS-style screenshots for niri";
|
||||||
|
package = lib.mkOption {
|
||||||
|
type = lib.types.package;
|
||||||
|
default = withSystem pkgs.stdenv.hostPlatform.system ({ config, ... }: config.packages.default);
|
||||||
|
defaultText = lib.literalExpression "valw.packages.\${system}.default";
|
||||||
|
description = "The valw package to install and to check the settings with.";
|
||||||
|
};
|
||||||
|
settings = lib.mkOption {
|
||||||
|
inherit (toml) type;
|
||||||
|
default = { };
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
{
|
||||||
|
preview.timeout_secs = 3;
|
||||||
|
sound.volume = 0.4;
|
||||||
|
capture.window_shadow = true;
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
valw's config (`$XDG_CONFIG_HOME/valw/config.toml`), checked by
|
||||||
|
valw at build time. Empty means valw's defaults.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
home.packages = [ cfg.package ];
|
||||||
|
xdg.configFile."valw/config.toml" = lib.mkIf (cfg.settings != { }) {
|
||||||
|
source = checked cfg.settings;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -16,6 +16,9 @@
|
|||||||
".jj"
|
".jj"
|
||||||
# Plan ledgers and review notes; not part of the build.
|
# Plan ledgers and review notes; not part of the build.
|
||||||
".superpowers"
|
".superpowers"
|
||||||
|
# Documentation: a doc change shouldn't rebuild the binary.
|
||||||
|
"docs"
|
||||||
|
"README.md"
|
||||||
"result"
|
"result"
|
||||||
"target"
|
"target"
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in new issue
Block a user