feat: make soonix a bit more flexible with and without devshell

This commit is contained in:
technofab 2025-09-02 14:21:53 +02:00
parent 3baef660cf
commit 690332ceea
No known key found for this signature in database
6 changed files with 106 additions and 37 deletions

6
flake.lock generated
View file

@ -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": {

View file

@ -22,12 +22,14 @@
(simple "devShells")
(simple "tests")
(simple "docs")
(simple "soonix")
];
}
{
packages = ren.select self [
["repo" "tests"]
["repo" "docs"]
["repo" "soonix" "packages"]
];
};
}

View file

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

View file

@ -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" = "<derivation>";
};
};
};
@ -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
'';
};
}

View file

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

23
nix/repo/soonix.nix Normal file
View file

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