From 0274dbfb69e77b092fa1f819c063f0683475b84e Mon Sep 17 00:00:00 2001 From: Valeriy Litkovskyy Date: Sun, 19 Mar 2023 17:05:38 +0100 Subject: [PATCH] [nix] Refactor flake --- flake.lock | 319 ++++++++++++++++++++++++++++++++--- flake.nix | 120 +++---------- nix/automation/devshells.nix | 13 ++ nix/automation/lib.nix | 28 +++ nix/automation/packages.nix | 32 ++++ nix/main/packages.nix | 21 +++ 6 files changed, 420 insertions(+), 113 deletions(-) create mode 100644 nix/automation/devshells.nix create mode 100644 nix/automation/lib.nix create mode 100644 nix/automation/packages.nix create mode 100644 nix/main/packages.nix diff --git a/flake.lock b/flake.lock index 85468d3..98963d1 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,70 @@ { "nodes": { + "blank": { + "locked": { + "lastModified": 1625557891, + "narHash": "sha256-O8/MWsPBGhhyPoPLHZAuoZiiHo9q6FLlEeIDEXuj6T4=", + "owner": "divnix", + "repo": "blank", + "rev": "5a5d2684073d9f563072ed07c871d577a6c614a8", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "blank", + "type": "github" + } + }, + "devshell": { + "inputs": { + "flake-utils": [ + "std", + "flake-utils" + ], + "nixpkgs": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1678957337, + "narHash": "sha256-Gw4nVbuKRdTwPngeOZQOzH/IFowmz4LryMPDiJN/ah4=", + "owner": "numtide", + "repo": "devshell", + "rev": "3e0e60ab37cd0bf7ab59888f5c32499d851edb47", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "dmerge": { + "inputs": { + "nixlib": [ + "std", + "nixpkgs" + ], + "yants": [ + "std", + "yants" + ] + }, + "locked": { + "lastModified": 1659548052, + "narHash": "sha256-fzI2gp1skGA8mQo/FBFrUAtY0GQkAIAaV/V127TJPyY=", + "owner": "divnix", + "repo": "data-merge", + "rev": "d160d18ce7b1a45b88344aa3f13ed1163954b497", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "data-merge", + "type": "github" + } + }, "eldev": { "flake": false, "locked": { @@ -20,19 +85,22 @@ "emacs-overlay": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { - "lastModified": 1671617692, - "narHash": "sha256-XvzdVbu4xyIUx11iF7UZYFpDRhalxpmdjc0i/DBBvJc=", + "lastModified": 1679220587, + "narHash": "sha256-e7AcTQIkUblq9xUdUL2KzVOiJoYxHgrl5skX+FuoCg8=", "owner": "nix-community", "repo": "emacs-overlay", - "rev": "75f08c349147a291cb18ef3dba2e87e129d467be", + "rev": "d1eecfd0f159569736fca5ccb9584df334c27202", "type": "github" }, "original": { - "id": "emacs-overlay", - "type": "indirect" + "owner": "nix-community", + "repo": "emacs-overlay", + "type": "github" } }, "flake-utils": { @@ -50,35 +118,246 @@ "type": "github" } }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "incl": { + "inputs": { + "nixlib": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1669263024, + "narHash": "sha256-E/+23NKtxAqYG/0ydYgxlgarKnxmDbg6rCMWnOBqn9Q=", + "owner": "divnix", + "repo": "incl", + "rev": "ce7bebaee048e4cd7ebdb4cee7885e00c4e2abca", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "incl", + "type": "github" + } + }, + "n2c": { + "inputs": { + "flake-utils": [ + "std", + "flake-utils" + ], + "nixpkgs": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1677330646, + "narHash": "sha256-hUYCwJneMjnxTvj30Fjow6UMJUITqHlpUGpXMPXUJsU=", + "owner": "nlewo", + "repo": "nix2container", + "rev": "ebca8f58d450cae1a19c07701a5a8ae40afc9efc", + "type": "github" + }, + "original": { + "owner": "nlewo", + "repo": "nix2container", + "type": "github" + } + }, + "nixago": { + "inputs": { + "flake-utils": [ + "std", + "flake-utils" + ], + "nixago-exts": [ + "std", + "blank" + ], + "nixpkgs": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1676075813, + "narHash": "sha256-X/aIT8Qc8UCqnxJvaZykx3CJ0ZnDFvO+dqp/7fglZWo=", + "owner": "nix-community", + "repo": "nixago", + "rev": "9cab4dde31ec2f2c05d702ea8648ce580664e906", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixago", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 0, - "narHash": "sha256-hVj8yEs5PAbR3cPPpmOtJYxZ8P+hD7RZTMSV9U0QYPA=", - "path": "/nix/store/cdl137dpgb9h3883j249naz9bav7ayrl-source", - "type": "path" + "lastModified": 1679198465, + "narHash": "sha256-VfXpHpniNWgg7pBzxb20pRX7kqn80LApPDQYTReiFCw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5a05160f7671434e1c833b1b01284b876e04eca4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nosys": { + "locked": { + "lastModified": 1668010795, + "narHash": "sha256-JBDVBnos8g0toU7EhIIqQ1If5m/nyBqtHhL3sicdPwI=", + "owner": "divnix", + "repo": "nosys", + "rev": "feade0141487801c71ff55623b421ed535dbdefa", + "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "divnix", + "repo": "nosys", + "type": "github" } }, - "nixpkgs_2": { + "paisano": { + "inputs": { + "nixpkgs": [ + "std", + "nixpkgs" + ], + "nosys": "nosys", + "yants": [ + "std", + "yants" + ] + }, "locked": { - "lastModified": 0, - "narHash": "sha256-hVj8yEs5PAbR3cPPpmOtJYxZ8P+hD7RZTMSV9U0QYPA=", - "path": "/nix/store/cdl137dpgb9h3883j249naz9bav7ayrl-source", - "type": "path" + "lastModified": 1678562978, + "narHash": "sha256-GaPyKdB0RvSBIgPxKkdJHTG/FyKsT0Ku5zifLEjr3QQ=", + "owner": "paisano-nix", + "repo": "core", + "rev": "f71a2db9414d66663c03a65ade97a9f353fb6d55", + "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "paisano-nix", + "repo": "core", + "type": "github" + } + }, + "paisano-tui": { + "inputs": { + "nixpkgs": [ + "std", + "blank" + ], + "std": [ + "std" + ] + }, + "locked": { + "lastModified": 1677533603, + "narHash": "sha256-Nq1dH/qn7Wg/Tj1+id+ZM3o0fzqonW73jAgY3mCp35M=", + "owner": "paisano-nix", + "repo": "tui", + "rev": "802958d123b0a5437441be0cab1dee487b0ed3eb", + "type": "github" + }, + "original": { + "owner": "paisano-nix", + "repo": "tui", + "type": "github" } }, "root": { "inputs": { "eldev": "eldev", "emacs-overlay": "emacs-overlay", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs", + "std": "std" + } + }, + "std": { + "inputs": { + "arion": [ + "std", + "blank" + ], + "blank": "blank", + "devshell": "devshell", + "dmerge": "dmerge", + "flake-utils": "flake-utils_2", + "incl": "incl", + "makes": [ + "std", + "blank" + ], + "microvm": [ + "std", + "blank" + ], + "n2c": "n2c", + "nixago": "nixago", + "nixpkgs": [ + "nixpkgs" + ], + "paisano": "paisano", + "paisano-tui": "paisano-tui", + "yants": "yants" + }, + "locked": { + "lastModified": 1679093481, + "narHash": "sha256-RwkTO+7ayaekfYRHnjDOFQp14sPhYSe/HukzwFVf+xs=", + "owner": "divnix", + "repo": "std", + "rev": "0e7c4e6acc7206b3d661c56dca17febe28f021de", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "std", + "type": "github" + } + }, + "yants": { + "inputs": { + "nixpkgs": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1667096281, + "narHash": "sha256-wRRec6ze0gJHmGn6m57/zhz/Kdvp9HS4Nl5fkQ+uIuA=", + "owner": "divnix", + "repo": "yants", + "rev": "d18f356ec25cb94dc9c275870c3a7927a10f8c3c", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "yants", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 9a104ed..ba833cc 100644 --- a/flake.nix +++ b/flake.nix @@ -1,99 +1,33 @@ { - inputs.eldev = { - url = "github:doublep/eldev/1.3.1"; - flake = false; + description = "Emacs package"; + + inputs = { + eldev.flake = false; + eldev.url = "github:doublep/eldev/1.3.1"; + emacs-overlay.inputs.nixpkgs.follows = "nixpkgs"; + emacs-overlay.url = "github:nix-community/emacs-overlay"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + std.inputs.nixpkgs.follows = "nixpkgs"; + std.url = "github:divnix/std"; }; + outputs = { + std, self, - nixpkgs, - emacs-overlay, - eldev, - }: let - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - overlays = [self.overlays.eldev self.overlays.default]; - }; - - inherit (builtins) attrNames elemAt foldl' head map match readDir readFile; - inherit (builtins) stringLength tail; - inherit (pkgs.lib.lists) filter; - inherit (pkgs.lib.sources) sourceFilesBySuffices; - inherit (pkgs.lib.strings) hasSuffix removeSuffix; - parse = pkgs.callPackage "${emacs-overlay}/parse.nix" {}; - - names = filter (hasSuffix ".el") (attrNames (readDir self)); - name = removeSuffix ".el" (foldl' (acc: elm: - if (stringLength elm) < (stringLength acc) - then elm - else acc) (head names) (tail names)); - mainFile = readFile "${self}/${name}.el"; - - version = elemAt (match ".*\n;; Version: ([^\n]+).*" mainFile) 0; - url = elemAt (match ".*\n;; URL: ([^\n]+).*" mainFile) 0; - deps = parse.parsePackagesFromPackageRequires mainFile; - in { - overlays = { - default = final: prev: { - emacsPackagesFor = emacs: - (prev.emacsPackagesFor emacs).overrideScope' ( - efinal: eprev: { - ${name} = efinal.melpaBuild { - inherit version; - pname = name; - src = self; - commit = self.rev; - recipe = final.writeText "recipe" '' - (${name} :fetcher git :url "${url}") - ''; - packageRequires = map (dep: efinal.${dep}) deps; - }; - } - ); - }; - - eldev = final: prev: { - eldev = final.stdenv.mkDerivation { - name = "eldev"; - src = eldev; - dontUnpack = true; - dontPatch = true; - dontConfigure = true; - dontBuild = true; - nativeBuildInputs = [final.emacs]; - installPhase = '' - mkdir -p $out/bin - cp $src/bin/eldev $out/bin/ - ''; - }; - }; + ... + } @ inputs: + std.growOn { + inherit inputs; + cellsFrom = ./nix; + cellBlocks = with std.blockTypes; [ + (functions "lib") + (installables "packages") + (installables "devshells") + ]; + } + { + devShells = std.harvest self ["automation" "devshells"]; + packages = std.harvest self ["main" "packages"]; + checks = std.harvest self [["automation" "packages"] ["main" "packages"]]; }; - - devShells.${system}.default = pkgs.mkShell { - inherit name; - buildInputs = [pkgs.alejandra pkgs.eldev pkgs.statix]; - shellHook = '' - export ELDEV_DIR=$PWD/.eldev - ''; - }; - - packages.${system} = { - ${name} = (pkgs.emacsPackagesFor pkgs.emacs).${name}; - }; - - checks.${system} = - self.packages.${system} - // { - tests = pkgs.runCommand "run-tests" {} '' - cp ${sourceFilesBySuffices ./. [".el"]}/* . - loadfiles="" - for file in *.el ; do - loadfiles="$loadfiles -l $file" - done - ${pkgs.emacs}/bin/emacs -Q -module-assertions -batch \ - -L . $loadfiles -f ert-run-tests-batch-and-exit \ - && touch $out - ''; - }; - }; } diff --git a/nix/automation/devshells.nix b/nix/automation/devshells.nix new file mode 100644 index 0000000..473179a --- /dev/null +++ b/nix/automation/devshells.nix @@ -0,0 +1,13 @@ +{ + inputs, + cell, +}: let + inherit (inputs) nixpkgs; +in { + default = nixpkgs.mkShell { + packages = [cell.packages.eldev nixpkgs.alejandra nixpkgs.statix]; + shellHook = '' + export ELDEV_DIR=$PWD/.eldev + ''; + }; +} diff --git a/nix/automation/lib.nix b/nix/automation/lib.nix new file mode 100644 index 0000000..c4ffb8f --- /dev/null +++ b/nix/automation/lib.nix @@ -0,0 +1,28 @@ +{ + inputs, + cell, +}: let + l = inputs.nixpkgs.lib // builtins; + + parse = import "${inputs.emacs-overlay}/parse.nix" { + inherit (inputs.nixpkgs) lib; + pkgs = {inherit (inputs.nixpkgs) lib;}; + }; + + names = + l.lists.filter + (l.strings.hasSuffix ".el") + (l.attrNames (l.readDir inputs.self)); + + name = l.strings.removeSuffix ".el" (l.foldl' (acc: elm: + if (l.stringLength elm) < (l.stringLength acc) + then elm + else acc) (l.head names) (l.tail names)); + + mainFile = l.readFile "${inputs.self}/${name}.el"; +in { + inherit name; + deps = parse.parsePackagesFromPackageRequires mainFile; + url = l.elemAt (l.match ".*\n;; URL: ([^\n]+).*" mainFile) 0; + version = l.elemAt (l.match ".*\n;; Version: ([^\n]+).*" mainFile) 0; +} diff --git a/nix/automation/packages.nix b/nix/automation/packages.nix new file mode 100644 index 0000000..f00ca00 --- /dev/null +++ b/nix/automation/packages.nix @@ -0,0 +1,32 @@ +{ + inputs, + cell, +}: let + inherit (inputs) nixpkgs; + l = inputs.nixpkgs.lib // builtins; +in { + eldev = nixpkgs.stdenv.mkDerivation { + name = "eldev"; + src = inputs.eldev; + dontUnpack = true; + dontPatch = true; + dontConfigure = true; + dontBuild = true; + nativeBuildInputs = [nixpkgs.emacs]; + installPhase = '' + mkdir -p $out/bin + cp $src/bin/eldev $out/bin/ + ''; + }; + + emacsPackageTests = nixpkgs.runCommand "emacs-package-tests" {} '' + cp ${l.sources.sourceFilesBySuffices inputs.self [".el"]}/*.el . + loadfiles="" + for file in *.el ; do + loadfiles="$loadfiles -l $file" + done + ${nixpkgs.emacs}/bin/emacs -Q -module-assertions -batch \ + -L . $loadfiles -f ert-run-tests-batch-and-exit \ + && touch $out + ''; +} diff --git a/nix/main/packages.nix b/nix/main/packages.nix new file mode 100644 index 0000000..c05104d --- /dev/null +++ b/nix/main/packages.nix @@ -0,0 +1,21 @@ +{ + inputs, + cell, +}: let + inherit (inputs) nixpkgs self; + l = inputs.nixpkgs.lib // builtins; + meta = inputs.cells.automation.lib; + epkgs = nixpkgs.emacs.pkgs; +in { + default = cell.packages."emacsPackages/${meta.name}"; + "emacsPackages/${meta.name}" = epkgs.melpaBuild { + inherit (meta) version; + pname = meta.name; + src = self; + commit = self.rev or "0000000000000000000000000000000000000000"; + recipe = nixpkgs.writeText "recipe" '' + (${meta.name} :fetcher git :url "${meta.url}") + ''; + packageRequires = l.attrsets.attrVals meta.deps epkgs; + }; +}