diff --git a/nix/checks.ulu.nix b/nix/checks.ulu.nix index ecb0f6a..e0f6f72 100644 --- a/nix/checks.ulu.nix +++ b/nix/checks.ulu.nix @@ -1,10 +1,45 @@ -{ ... }: +{ self, ... }: { perSystem = - { pkgs, self', ... }: + { + pkgs, + lib, + self', + ... + }: let 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. cargoCheck = name: tools: cmd: @@ -19,6 +54,35 @@ in { 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"; nextest = cargoCheck "nextest" [ pkgs.cargo-nextest ] "cargo nextest run --offline"; diff --git a/nix/devshell.ulu.nix b/nix/devshell.ulu.nix index f066634..291a44e 100644 --- a/nix/devshell.ulu.nix +++ b/nix/devshell.ulu.nix @@ -1,7 +1,12 @@ { ... }: { perSystem = - { pkgs, lib, self', ... }: + { + pkgs, + lib, + self', + ... + }: { devShells.default = pkgs.mkShell { inputsFrom = [ self'.packages.default ]; diff --git a/nix/home-module.ulu.nix b/nix/home-module.ulu.nix new file mode 100644 index 0000000..66311fb --- /dev/null +++ b/nix/home-module.ulu.nix @@ -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; + }; + }; + }; +} diff --git a/nix/package.ulu.nix b/nix/package.ulu.nix index c5cd557..5f32eed 100644 --- a/nix/package.ulu.nix +++ b/nix/package.ulu.nix @@ -16,6 +16,9 @@ ".jj" # Plan ledgers and review notes; not part of the build. ".superpowers" + # Documentation: a doc change shouldn't rebuild the binary. + "docs" + "README.md" "result" "target" ]);