diff --git a/flake.lock b/flake.lock index 2faa24f..a04947a 100644 --- a/flake.lock +++ b/flake.lock @@ -37,11 +37,11 @@ }, "locked": { "dir": "lib", - "lastModified": 1755264589, - "narHash": "sha256-g8KjU4D/nxpMjCLQNP90VAAWUH89yvONRfChyhhzq4c=", + "lastModified": 1756212334, + "narHash": "sha256-jSSd5pH34azi3/TiuY/Ioi63VgWdsHBeOmkM66Fz1fI=", "owner": "rensa-nix", "repo": "core", - "rev": "9f20f8c94b09a1c85356f8340ebe0a339b0d32e6", + "rev": "519ed97c97cb32996b63d2e20349a5d82ad2edc1", "type": "gitlab" }, "original": { diff --git a/flake.nix b/flake.nix index f143c7f..9489736 100644 --- a/flake.nix +++ b/flake.nix @@ -22,12 +22,14 @@ (simple "devShells") (simple "tests") (simple "docs") + (simple "soonix") ]; } { packages = ren.select self [ ["repo" "tests"] ["repo" "docs"] + ["repo" "soonix" "packages"] ]; }; } diff --git a/lib/devshellModule.nix b/lib/devshellModule.nix index 91a90e9..be2be3e 100644 --- a/lib/devshellModule.nix +++ b/lib/devshellModule.nix @@ -7,17 +7,30 @@ inherit (lib) mkOption types; soonixModule = ./module.nix; in { - options.soonix = mkOption { - type = types.submodule { - # propagate pkgs to the soonix module - _module.args.pkgs = pkgs; - imports = [soonixModule]; + options = { + soonix = mkOption { + type = types.submodule { + # propagate pkgs to the soonix module + _module.args.pkgs = pkgs; + imports = [soonixModule]; + }; + default = {}; + }; + soonixShellHook = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Set the shell hook manually, useful if you already use `soonix.make` and + want to add the devshell integration. + ''; }; - default = {}; }; config.enterShellCommands.soonix = { - text = config.soonix.shellHook; + text = + if config.soonixShellHook != null + then config.soonixShellHook + else config.soonix.shellHook; deps = ["env"]; }; } diff --git a/lib/module.nix b/lib/module.nix index 93a2243..4233de1 100644 --- a/lib/module.nix +++ b/lib/module.nix @@ -24,24 +24,32 @@ in { output = mkOption { type = types.str; - description = "The relative path where the generated file should be placed."; + description = '' + The relative path where the generated file should be placed. + ''; }; generator = mkOption { type = types.enum ["nix" "string" "derivation" "gotmpl" "jinja" "template"]; - description = "Which engine to use for content generation."; + description = '' + Which engine to use for content generation. + ''; default = "nix"; }; data = mkOption { type = types.anything; - description = "The input data for the chosen generator."; + description = '' + The input data for the chosen generator. + ''; }; opts = mkOption { type = types.attrs; default = {}; - description = "Generator-specific options."; + description = '' + Generator-specific options. + ''; }; hook = mkOption { @@ -50,31 +58,41 @@ in { mode = mkOption { type = types.enum ["link" "copy"]; default = "link"; - description = "How the file should be managed (link or copy)."; + description = '' + How the file should be managed (link or copy). + ''; }; gitignore = mkOption { type = types.bool; default = true; - description = "Whether to add the output path to .gitignore."; + description = '' + Whether to add the output path to .gitignore. + ''; }; extra = mkOption { type = types.str; default = ""; - description = "Additional bash commands to execute after file operation."; + description = '' + Additional bash commands to execute after file operation. + ''; }; }; }; default = {}; - description = "Hook-specific options."; + description = '' + Hook-specific options. + ''; }; generatedDerivation = mkOption { type = types.package; internal = true; readOnly = true; - description = "The generated derivation for this file."; + description = '' + The generated derivation for this file. + ''; }; }; @@ -87,24 +105,42 @@ in { }; })); default = {}; - description = "Configuration of the hooks."; + description = '' + Configuration of the hooks. + ''; }; shellHook = mkOption { type = types.str; readOnly = true; - description = "Generated shell hook script (as a string) for managing all files (readonly)."; + description = '' + Generated shell hook script (as a string) for managing all files. (readonly) + ''; }; shellHookFile = mkOption { type = types.package; readOnly = true; - description = "Generated shell hook script for managing all files (readonly)."; + description = '' + Generated shell hook script for managing all files. (readonly) + ''; }; finalFiles = mkOption { type = types.package; readOnly = true; - description = "Aggregated derivation containing all managed files (readonly)."; + description = '' + Aggregated derivation containing all managed files. (readonly) + ''; + }; + packages = mkOption { + type = types.attrsOf types.package; + readOnly = true; + description = '' + Packages for updating the hooks without a devshell. (readonly) + ''; + example = { + "soonix:update" = ""; + }; }; }; @@ -259,5 +295,12 @@ in { else ""; shellHookFile = pkgs.writeShellScript "shellHook" shellHook; finalFiles = buildAllFiles allFiles; + # make it simpler to update the hooks without any devshell + packages."soonix:update" = pkgs.writeShellScriptBin "soonix:update" '' + function _soonix() { + ${shellHook} + } + _soonix + ''; }; } diff --git a/nix/repo/devShells.nix b/nix/repo/devShells.nix index 8e5c5a8..541661a 100644 --- a/nix/repo/devShells.nix +++ b/nix/repo/devShells.nix @@ -4,6 +4,7 @@ ... }: let inherit (inputs) pkgs devshell soonix treefmt; + soonixShellHook = cell.soonix.shellHook; in { default = devshell.mkShell { imports = [soonix.devshellModule]; @@ -17,19 +18,6 @@ in { }; }) ]; - - soonix.hooks.test = { - output = "test.yaml"; - generator = "nix"; - data = { - name = "soonix-test"; - version = "1.0.0"; - }; - opts.format = "yaml"; - hook = { - mode = "copy"; - gitignore = true; - }; - }; + inherit soonixShellHook; }; } diff --git a/nix/repo/soonix.nix b/nix/repo/soonix.nix new file mode 100644 index 0000000..2644f32 --- /dev/null +++ b/nix/repo/soonix.nix @@ -0,0 +1,23 @@ +{ + inputs, + ... +}: let + inherit (inputs) soonix; +in + (soonix.make { + hooks = { + test = { + output = "test.yaml"; + generator = "nix"; + data = { + name = "soonix-test"; + version = "1.0.0"; + }; + opts.format = "yaml"; + hook = { + mode = "copy"; + gitignore = true; + }; + }; + }; + }).config