From 619876884dc25e5a87734af90051a2fb427bfa76 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 25 May 2025 16:04:54 +1000 Subject: [PATCH] feat: use unf for docs --- README.md | 50 ++------------- flake.lock | 119 ++++++++++++++++++++++++++++++++++- flake.nix | 22 +++++-- nix/docs.nix | 46 ++++++++++++++ nix/impl.nix | 46 ++++++++++++++ nix/interface.nix | 56 +++++++++++++++++ module.nix => nix/module.nix | 38 +---------- 7 files changed, 289 insertions(+), 88 deletions(-) create mode 100644 nix/docs.nix create mode 100644 nix/impl.nix create mode 100644 nix/interface.nix rename module.nix => nix/module.nix (52%) diff --git a/README.md b/README.md index 5d60ea9..69ad4ed 100644 --- a/README.md +++ b/README.md @@ -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. - diff --git a/flake.lock b/flake.lock index ee725c5..57939f8 100644 --- a/flake.lock +++ b/flake.lock @@ -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" } } }, diff --git a/flake.nix b/flake.nix index a7f2bc7..ce202d2 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; }; diff --git a/nix/docs.nix b/nix/docs.nix new file mode 100644 index 0000000..aa29e90 --- /dev/null +++ b/nix/docs.nix @@ -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 ]; +} diff --git a/nix/impl.nix b/nix/impl.nix new file mode 100644 index 0000000..56753a5 --- /dev/null +++ b/nix/impl.nix @@ -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}"; + }; + }; + }; + }; +} diff --git a/nix/interface.nix b/nix/interface.nix new file mode 100644 index 0000000..45f2e2f --- /dev/null +++ b/nix/interface.nix @@ -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; + }; + }; +} diff --git a/module.nix b/nix/module.nix similarity index 52% rename from module.nix rename to nix/module.nix index 7a98395..93de484 100644 --- a/module.nix +++ b/nix/module.nix @@ -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}"; - }; - }; - }; - }; }