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": { "locked": {
"dir": "lib", "dir": "lib",
"lastModified": 1755264589, "lastModified": 1756212334,
"narHash": "sha256-g8KjU4D/nxpMjCLQNP90VAAWUH89yvONRfChyhhzq4c=", "narHash": "sha256-jSSd5pH34azi3/TiuY/Ioi63VgWdsHBeOmkM66Fz1fI=",
"owner": "rensa-nix", "owner": "rensa-nix",
"repo": "core", "repo": "core",
"rev": "9f20f8c94b09a1c85356f8340ebe0a339b0d32e6", "rev": "519ed97c97cb32996b63d2e20349a5d82ad2edc1",
"type": "gitlab" "type": "gitlab"
}, },
"original": { "original": {

View file

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

View file

@ -7,17 +7,30 @@
inherit (lib) mkOption types; inherit (lib) mkOption types;
soonixModule = ./module.nix; soonixModule = ./module.nix;
in { in {
options.soonix = mkOption { options = {
type = types.submodule { soonix = mkOption {
# propagate pkgs to the soonix module type = types.submodule {
_module.args.pkgs = pkgs; # propagate pkgs to the soonix module
imports = [soonixModule]; _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 = { config.enterShellCommands.soonix = {
text = config.soonix.shellHook; text =
if config.soonixShellHook != null
then config.soonixShellHook
else config.soonix.shellHook;
deps = ["env"]; deps = ["env"];
}; };
} }

View file

@ -24,24 +24,32 @@ in {
output = mkOption { output = mkOption {
type = types.str; 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 { generator = mkOption {
type = types.enum ["nix" "string" "derivation" "gotmpl" "jinja" "template"]; 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"; default = "nix";
}; };
data = mkOption { data = mkOption {
type = types.anything; type = types.anything;
description = "The input data for the chosen generator."; description = ''
The input data for the chosen generator.
'';
}; };
opts = mkOption { opts = mkOption {
type = types.attrs; type = types.attrs;
default = {}; default = {};
description = "Generator-specific options."; description = ''
Generator-specific options.
'';
}; };
hook = mkOption { hook = mkOption {
@ -50,31 +58,41 @@ in {
mode = mkOption { mode = mkOption {
type = types.enum ["link" "copy"]; type = types.enum ["link" "copy"];
default = "link"; default = "link";
description = "How the file should be managed (link or copy)."; description = ''
How the file should be managed (link or copy).
'';
}; };
gitignore = mkOption { gitignore = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
description = "Whether to add the output path to .gitignore."; description = ''
Whether to add the output path to .gitignore.
'';
}; };
extra = mkOption { extra = mkOption {
type = types.str; type = types.str;
default = ""; default = "";
description = "Additional bash commands to execute after file operation."; description = ''
Additional bash commands to execute after file operation.
'';
}; };
}; };
}; };
default = {}; default = {};
description = "Hook-specific options."; description = ''
Hook-specific options.
'';
}; };
generatedDerivation = mkOption { generatedDerivation = mkOption {
type = types.package; type = types.package;
internal = true; internal = true;
readOnly = true; readOnly = true;
description = "The generated derivation for this file."; description = ''
The generated derivation for this file.
'';
}; };
}; };
@ -87,24 +105,42 @@ in {
}; };
})); }));
default = {}; default = {};
description = "Configuration of the hooks."; description = ''
Configuration of the hooks.
'';
}; };
shellHook = mkOption { shellHook = mkOption {
type = types.str; type = types.str;
readOnly = true; 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 { shellHookFile = mkOption {
type = types.package; type = types.package;
readOnly = true; readOnly = true;
description = "Generated shell hook script for managing all files (readonly)."; description = ''
Generated shell hook script for managing all files. (readonly)
'';
}; };
finalFiles = mkOption { finalFiles = mkOption {
type = types.package; type = types.package;
readOnly = true; 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 ""; else "";
shellHookFile = pkgs.writeShellScript "shellHook" shellHook; shellHookFile = pkgs.writeShellScript "shellHook" shellHook;
finalFiles = buildAllFiles allFiles; 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 }: let
inherit (inputs) pkgs devshell soonix treefmt; inherit (inputs) pkgs devshell soonix treefmt;
soonixShellHook = cell.soonix.shellHook;
in { in {
default = devshell.mkShell { default = devshell.mkShell {
imports = [soonix.devshellModule]; imports = [soonix.devshellModule];
@ -17,19 +18,6 @@ in {
}; };
}) })
]; ];
inherit soonixShellHook;
soonix.hooks.test = {
output = "test.yaml";
generator = "nix";
data = {
name = "soonix-test";
version = "1.0.0";
};
opts.format = "yaml";
hook = {
mode = "copy";
gitignore = true;
};
};
}; };
} }

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