From e650c463fceefc0ebd94dadecba44fb1d374aa05 Mon Sep 17 00:00:00 2001 From: fmway Date: Sun, 13 Apr 2025 11:36:57 +0700 Subject: [PATCH] add nix support --- default.nix | 34 ++++++++++++++++++++++++++++++ flake.lock | 43 ++++++++++++++++++++++++++++++++++++++ flake.nix | 26 +++++++++++++++++++++++ readme.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..7ef5153 --- /dev/null +++ b/default.nix @@ -0,0 +1,34 @@ +{ pkgs ? import {}, lib ? pkgs.lib, version ? null, ... }: +let + wl-copy = lib.getExe' pkgs.wl-clipboard "wl-copy"; + wl-paste = lib.getExe' pkgs.wl-clipboard "wl-paste"; + xclip = lib.getExe pkgs.xclip; + php = lib.getExe pkgs.php; + replaces = { + "#!/usr/bin/env php" = "#!/usr/bin/env ${php}"; + "$tool = basename($result[0] ?? '');" = /* php */ '' + if (getenv("XDG_SESSION_TYPE") == "wayland") { + $tool = "wl-copy"; + } else { + $tool = "xclip"; + } + ''; + "= 'xclip" = "= '${xclip}"; + "= 'wl-copy" = "= '${wl-copy}"; + "= 'wl-paste" = "= '${wl-paste}"; + }; + script = pkgs.writeScriptBin "h-m-m" (let + prevScript = lib.fileContents ./h-m-m; + in if pkgs.stdenv.isDarwin then + lib.replaceStrings [ "#!/usr/bin/env php" ] [ "#!/usr/bin/env ${php}" ] prevScript + else + lib.replaceStrings (lib.attrNames replaces) (lib.attrValues replaces) prevScript); +in script // lib.optionals (!isNull version) { + inherit version; +} // { + meta = script.meta // { + description = "h-m-m is a keyboard-centric terminal-based tool for working with mind maps."; + homepage = "https://github.com/nadrad/h-m-m"; + license = lib.licenses.gpl3; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..946bf52 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1744502386, + "narHash": "sha256-QAd1L37eU7ktL2WeLLLTmI6P9moz9+a/ONO8qNBYJgM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f6db44a8daa59c40ae41ba6e5823ec77fe0d2124", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b870c39 --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, systems, ... }: let + eachSystem = nixpkgs.lib.genAttrs (import systems); + version = let + rev = self.shortRev or self.dirtyShortRev or self.lastModified or null; + in if isNull rev then null else "r${toString rev}"; + in { + packages = eachSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + h-m-m = pkgs.callPackage ./. { inherit version; }; + default = self.packages.${system}.h-m-m; + }); + overlays.h-m-m = self: super: { + h-m-m = self.callPackage ./. { inherit version; }; + }; + overlays.default = self.overlays.h-m-m; + }; +} diff --git a/readme.md b/readme.md index f4f06ea..680f593 100644 --- a/readme.md +++ b/readme.md @@ -335,6 +335,66 @@ docker run --rm -it -v $(pwd):/app/ -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY= alias hmm='docker run --rm -it -v $(pwd):/app/ -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY hmm' ``` +## 5. Installation with Nix/NixOS +
+with flakes (NixOS) + +Below is a fragment of a NixOS configuration that add h-m-m to system packages. + +```nix +{ + description = "Simple NixOS configurations"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + h-m-m = { + url = "github:nadrad/h-m-m"; + # Optional but recommended to limit the size of your system closure. + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = { nixpkgs, h-m-m, ... }: { + nixosConfigurations = { + yourHost = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + # ... + { + nixpkgs.overlays = [ h-m-m.overlays.default ]; + } + # add h-m-m to your system + ({ pkgs, ... }: { + environment.systemPackages = [ pkgs.h-m-m ]; + }); + ]; + }; + }; + }; +} +``` +
+ +
+with nix profile + +You can also install it using the imperative method + +```sh +$ nix profile install github:nadrad/h-m-m +``` +
+ +
+with nix shell / nix run + +If you don't want to install it on your system, you can try it with nix run or nix shell. + +```sh +$ nix run github:nadrad/h-m-m -- +# or +$ nix shell github:nadrad/h-m-m +$ h-m-m +``` +
# Feedback