feat: use unf for docs

This commit is contained in:
atagen 2025-05-25 16:04:54 +10:00
parent 716a656fa3
commit 619876884d
7 changed files with 289 additions and 88 deletions

View File

@ -17,60 +17,20 @@ this may conflict with behaviour of some editors (ie. vscode), particularly if
they are started via a .desktop shortcut.
#### a brief disclaimer
`smooooth` is in a very early but entirely functional state.
`smooooth` is in an early but entirely functional state.
it may be subject to changes, full rewrites, or unending neglect.
it may be subject to changes, ~full rewrites,~ or unending neglect.
enjoy !
## i hear you whispering the words
### to melt everyone, but you stay so cold
simply add `smooooth.url = git+https://git.atagen.co/atagen/smooooth.git` to your
flake inputs, and the reciprocal `{ smooooth }` entry to your output function.
now you can import `smooooth.nixosModules.smooooth` in your config modules, and
utilise the below listed options to get started !
utilise the [supplied module options](https://docs.atagen.co/smooooth) to get started !
## to melt everyone, but you stay so cold
### services.smooooth.enable
`bool`
Enable the smooooth nixos hot reloader.
### services.smooooth.blockers
`listOf str`
A list of executable names that are allowed to block the reload.
### services.smooooth.path
`str`
The full path to the root of your flake.
### services.smooooth.pollingRate
`int`
How frequently to poll when waiting on a blocked reload.
### services.smooooth.nixPackage
`package`
Your preferred package providing a `nix` executable.
### services.smooooth.package
`package`
Your preferred `smooooth` package.

119
flake.lock generated
View File

@ -1,5 +1,58 @@
{
"nodes": {
"flake-compat": {
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1743550720,
"narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "c621e8422220273271f52058f618c94e405bb0f5",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"ndg": {
"inputs": {
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1748103964,
"narHash": "sha256-aRFl6I3x1aKzeOBaD/OJHYv+OQ+qE+3FR9uKhIvfW+A=",
"owner": "feel-co",
"repo": "ndg",
"rev": "c556c4cbcba61474bf8a342a31a2d94cbefd8986",
"type": "github"
},
"original": {
"owner": "feel-co",
"repo": "ndg",
"type": "github"
}
},
"nix-systems": {
"locked": {
"lastModified": 1689347949,
@ -31,10 +84,74 @@
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1743296961,
"narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1745930157,
"narHash": "sha256-y3h3NLnzRSiUkYpnfvnS669zWZLoqqI6NprtLQ+5dck=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "46e634be05ce9dc6d4db8e664515ba10b78151ae",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1747958103,
"narHash": "sha256-qmmFCrfBwSHoWw7cVK4Aj+fns+c54EBP8cGqp/yK410=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "fe51d34885f7b5e3e7b59572796e1bcb427eccb1",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nix-systems": "nix-systems",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"unf": "unf"
}
},
"unf": {
"inputs": {
"ndg": "ndg",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1748163510,
"narHash": "sha256-k/DaP83w2vFJjQaI/J28DlYNCOYCxPzUPhyfkXsBnCY=",
"path": "/home/bolt/code/unf",
"type": "path"
},
"original": {
"path": "/home/bolt/code/unf",
"type": "path"
}
}
},

View File

@ -2,18 +2,19 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nix-systems.url = "github:nix-systems/default-linux";
unf.url = "path:/home/bolt/code/unf";
};
outputs =
inputs:
with inputs;
let
get = builtins.attrValues;
collectPkgs = builtins.attrValues;
forAllSystems =
function:
nixpkgs.lib.genAttrs (import nix-systems) (system: function nixpkgs.legacyPackages.${system});
deps = forAllSystems (pkgs: {
dev = get {
dev = collectPkgs {
inherit (pkgs) just;
inherit (pkgs.ocamlPackages)
utop
@ -24,7 +25,7 @@
;
};
build =
get {
collectPkgs {
inherit (pkgs.ocamlPackages)
ocaml
lwt
@ -52,17 +53,28 @@
buildInputs = deps.${pkgs.system}.build;
};
obus = pkgs.callPackage ./nix/obus.nix { };
docs = pkgs.callPackage unf.lib.pak-chooie {
inherit self;
projectName = "smooooth";
newPath = "https://git.atagen.co/atagen/smooooth/src";
modules = [
./nix/interface.nix
./nix/impl.nix
];
};
});
nixosModules.smooooth =
{
config,
pkgs,
lib,
...
}:
{
imports = [ ./module.nix ];
imports = [
./nix/interface.nix
./nix/impl.nix
];
services.smooooth.package = self.packages.${pkgs.system}.default;
};
};

46
nix/docs.nix Normal file
View File

@ -0,0 +1,46 @@
{
pkgs,
lib,
ndg-builder,
}:
let
eval = lib.evalModules {
specialArgs = { inherit pkgs; };
modules = [
./module.nix
];
};
optionsDoc = pkgs.nixosOptionsDoc {
inherit (eval) options;
transformOptions =
opt:
opt
// {
# Clean up declaration sites to not refer to the source tree.
declarations =
let
devDir = toString /home/bolt/code/smooooth;
inherit (lib) hasPrefix removePrefix;
in
map (
decl:
if hasPrefix (toString devDir) (toString decl) then
let
subpath = removePrefix "/" (removePrefix (toString devDir) (toString decl));
in
{
url = "https://git.atagen.co/atagen/smooooth/${subpath}";
name = subpath;
}
else
decl
) opt.declarations;
};
};
in
ndg-builder.override {
title = "smooooth documentation";
rawModules = [ ./module.nix ];
}

46
nix/impl.nix Normal file
View File

@ -0,0 +1,46 @@
{
lib,
config,
...
}:
let
cfg = config.services.smooooth;
in
{
config = lib.mkIf config.services.smooooth.enable {
environment.etc."smooooth.json".text = builtins.toJSON {
inherit (cfg) path;
blockers =
let
withDefaults = map (
b: if builtins.typeOf b == "string" then { "${b}" = "stop"; } else b
) cfg.blockers;
merged = lib.mergeAttrsList withDefaults;
# FIXME clumsy, could do better
transformed = lib.mapAttrsToList (n: v: {
name = n;
cond = [
(lib.toSentenceCase v)
];
}) merged;
in
transformed;
};
systemd.user = {
services.smooooth = {
enable = true;
path = [
cfg.package
cfg.nixPackage
];
wantedBy = [ "graphical-session.target" ];
after = [ "graphical-session.target" ];
serviceConfig = {
Restart = "always";
Type = "notify";
ExecStart = "${lib.getExe cfg.package}";
};
};
};
};
}

56
nix/interface.nix Normal file
View File

@ -0,0 +1,56 @@
{
pkgs,
lib,
...
}:
let
inherit (lib) types;
inherit (lib.options) mkEnableOption mkOption;
in
{
options.services.smooooth = {
enable = mkEnableOption "the smooooth nixos hot reloader";
blockers = mkOption {
description = "names of processes that may block reloading by holding a flake (sub)path open. default state is \"stop\"";
default = [
"nano"
"nvim"
"vim"
"vi"
"hx"
];
example = [
"hx"
{
nano = "die";
nvim = "stop";
}
{ fish = "die"; }
];
type =
with types;
listOf (
either str (
attrsOf (enum [
"stop"
"die"
])
)
);
};
path = mkOption {
description = "path to the root of your flake.";
type = types.str;
};
nixPackage = mkOption {
description = "preferred package providing a `nix` executable.";
default = pkgs.nix;
defaultText = "pkgs.nix";
type = types.package;
};
package = mkOption {
description = "smooooth package";
type = types.package;
};
};
}

View File

@ -1,13 +1,11 @@
{
pkgs,
lib,
config,
...
}:
let
inherit (lib) types;
inherit (lib.options) mkEnableOption mkOption;
cfg = config.services.smooooth;
in
{
options.services.smooooth = {
@ -42,6 +40,7 @@ in
nixPackage = mkOption {
description = "preferred package providing a `nix` executable.";
default = pkgs.nix;
defaultText = "pkgs.nix";
type = types.package;
};
package = mkOption {
@ -50,39 +49,4 @@ in
};
};
config = lib.mkIf cfg.enable {
environment.etc."smooooth.json".text = builtins.toJSON {
inherit (cfg) path;
blockers =
let
withDefaults = map (
b: if builtins.typeOf b == "string" then { "${b}" = "stop"; } else b
) cfg.blockers;
merged = lib.mergeAttrsList withDefaults;
# FIXME clumsy, could do better
transformed = lib.mapAttrsToList (n: v: {
name = n;
cond = [
(lib.toSentenceCase v)
];
}) merged;
in
transformed;
};
systemd.user = {
services.smooooth = {
enable = true;
path = [
cfg.package
];
wantedBy = [ "graphical-session.target" ];
after = [ "graphical-session.target" ];
serviceConfig = {
Restart = "always";
Type = "notify";
ExecStart = "${lib.getExe cfg.package}";
};
};
};
};
}