From c1fea3021494430190a7cb87504bafbc3f6426b4 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 20 Jul 2025 13:37:42 +0300 Subject: [PATCH 1/2] meta: add flake-compat & expose flakeless interface Signed-off-by: NotAShelf Change-Id: I6a6a6964afc8b84fe10106f0a90d4bf3acaeee85 --- default.nix | 15 +++++++++++++++ flake.lock | 17 +++++++++++++++++ flake.nix | 47 +++++++++++++++++++++++++++++++++-------------- shell.nix | 7 +++++++ 4 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 default.nix create mode 100644 shell.nix diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..e597b612 --- /dev/null +++ b/default.nix @@ -0,0 +1,15 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + inherit (lock.nodes.flake-compat.locked) url rev narHash; + in + builtins.fetchTarball { + url = "${url}/archive/${rev}.tar.gz"; + sha256 = narHash; + } + ) { + src = ./.; + copySourceTreeToStore = false; + useBuiltinsFetchTree = true; + }) +.defaultNix diff --git a/flake.lock b/flake.lock index c530031d..d33a8f7d 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1751685974, + "narHash": "sha256-NKw96t+BgHIYzHUjkTK95FqYRVKB8DHpVhefWSz/kTw=", + "ref": "refs/heads/main", + "rev": "549f2762aebeff29a2e5ece7a7dc0f955281a1d1", + "revCount": 92, + "type": "git", + "url": "https://git.lix.systems/lix-project/flake-compat.git" + }, + "original": { + "type": "git", + "url": "https://git.lix.systems/lix-project/flake-compat.git" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -73,6 +89,7 @@ }, "root": { "inputs": { + "flake-compat": "flake-compat", "flake-parts": "flake-parts", "flake-utils": "flake-utils", "mnw": "mnw", diff --git a/flake.nix b/flake.nix index 35f69ea6..74dcca35 100644 --- a/flake.nix +++ b/flake.nix @@ -5,8 +5,9 @@ self, ... } @ inputs: let - # call the extended library with `inputs` - # inputs is used to get the original standard library, and to pass inputs to the plugin autodiscovery function + # Call the extended library with `inputs`. + # inputs is used to get the original standard library, and to pass inputs + # to the plugin autodiscovery function lib = import ./lib/stdlib-extended.nix {inherit inputs self;}; in flake-parts.lib.mkFlake { @@ -29,6 +30,8 @@ inherit (lib.nvim) neovimConfiguration; }; + inherit (lib.importJSON ./npins/sources.json) pins; + homeManagerModules = { nvf = import ./flake/modules/home-manager.nix {inherit lib inputs;}; default = self.homeManagerModules.nvf; @@ -50,21 +53,33 @@ '' self.nixosModules.nvf; }; - - inherit (lib.importJSON ./npins/sources.json) pins; }; perSystem = {pkgs, ...}: { - # Provide the default formatter. `nix fmt` in project root - # will format available files with the correct formatter. - # P.S: Please do not format with nixfmt! It messes with many - # syntax elements and results in unreadable code. - formatter = pkgs.alejandra; + # Provides the default formatter for 'nix fmt', which will format the + # entire tree with Alejandra. The wrapper script is necessary due to + # changes to the behaviour of Nix, which now encourages wrappers for + # tree-wide formatting. + formatter = pkgs.writeShellApplication { + name = "nix3-fmt-wrapper"; - # Check if codebase is properly formatted. - # This can be initiated with `nix build .#checks..nix-fmt` - # or with `nix flake check` + runtimeInputs = [ + pkgs.alejandra + pkgs.fd + ]; + + text = '' + # Find Nix files in the tree and format them with Alejandra + fd "$@" -t f -e nix -x alejandra -q '{}' + ''; + }; + + # Provides checks to be built an ran on 'nix flake check'. They can also + # be built individually with 'nix build' as described below. checks = { + # Check if codebase is properly formatted. + # This can be initiated with `nix build .#checks..nix-fmt` + # or with `nix flake check` nix-fmt = pkgs.runCommand "nix-fmt-check" {nativeBuildInputs = [pkgs.alejandra];} '' alejandra --check ${self} < /dev/null | tee $out ''; @@ -72,8 +87,9 @@ }; }; - # Flake inputs inputs = { + systems.url = "github:nix-systems/default"; + ## Basic Inputs nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; @@ -87,7 +103,10 @@ inputs.systems.follows = "systems"; }; - systems.url = "github:nix-systems/default"; + flake-compat = { + url = "git+https://git.lix.systems/lix-project/flake-compat.git"; + flake = false; + }; # Alternate neovim-wrapper mnw.url = "github:Gerg-L/mnw"; diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..8d17121f --- /dev/null +++ b/shell.nix @@ -0,0 +1,7 @@ +# Make the behaviour of `nix-shell` consistent with the one of `nix develop` +# by returning the default devShell output from the flake. This is useful when +# I do not want to work with direnv, or simply need backwards compatibility. +{system ? builtins.currentSystem}: let + nvf = import ./.; +in + nvf.devShells.${system}.default From 33a69fae5f2651e7be08420d4488e4a15f90b789 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 20 Jul 2025 14:20:18 +0300 Subject: [PATCH 2/2] docs: add flakeless examples; describe flakes prerequisites Signed-off-by: NotAShelf Change-Id: I6a6a6964c8369dbdf7366e333378ee25d125c707 --- docs/manual/installation/modules/flakes.md | 33 ++++++++++ .../installation/modules/home-manager.md | 62 ++++++++++++++++-- docs/manual/installation/modules/nixos.md | 65 +++++++++++++++++-- docs/manual/try-it-out.md | 16 +++-- 4 files changed, 160 insertions(+), 16 deletions(-) create mode 100644 docs/manual/installation/modules/flakes.md diff --git a/docs/manual/installation/modules/flakes.md b/docs/manual/installation/modules/flakes.md new file mode 100644 index 00000000..273d2b00 --- /dev/null +++ b/docs/manual/installation/modules/flakes.md @@ -0,0 +1,33 @@ +### Prerequisites {#sec-flakes-prerequisites} + +To install nvf with flakes, you must make sure the following requirements are +met. + +1. Nix 2.4 or later must be installed. You may use `nix-shell` to get a later + version of Nix from nixpkgs. +2. Flake-related experimental features must be enabled. Namely, you need + `nix-command` and `flakes`. Some Nix vendors enable those by default, please + consult their documentation if you are not using mainstream Nix. + - When using NixOS, add the following to your `configuration.nix` and rebuild + your system. + + ```nix + nix.settings.experimental-features = "nix-command flakes"; + ``` + + - If you are not using NixOS, add the following to `nix.conf` (located at + `~/.config/nix/` or `/etc/nix/nix.conf`). + + ```bash + experimental-features = nix-command flakes + ``` + + - You may need to restart the Nix daemon with, for example, + `sudo systemctl restart nix-daemon.service`. + + - Alternatively, you can enable flakes on a per-command basis with the + following additional flags to `nix` and `home-manager`: + + ```sh + $ nix --extra-experimental-features "nix-command flakes" + ``` diff --git a/docs/manual/installation/modules/home-manager.md b/docs/manual/installation/modules/home-manager.md index 2b359af5..37d35e2b 100644 --- a/docs/manual/installation/modules/home-manager.md +++ b/docs/manual/installation/modules/home-manager.md @@ -5,9 +5,18 @@ inside the home-manager configuration without having to call for the wrapper yourself. It is the recommended way to use **nvf** alongside the NixOS module depending on your needs. -To use it, we first add the input flake. +## With Flakes {#sec-hm-flakes} + +```{=include=} +flakes.md +``` + +### Usage {#sec-hm-flakes-usage} + +To use **nvf** with flakes, we first need to add the input to our `flake.nix`. ```nix +# flake.nix { inputs = { # Optional, if you intend to follow nvf's obsidian-nvim input @@ -16,7 +25,7 @@ To use it, we first add the input flake. # Required, nvf works best and only directly supports flakes nvf = { - url = "github:notashelf/nvf"; + url = "github:NotAShelf/nvf"; # You can override the input nixpkgs to follow your system's # instance of nixpkgs. This is safe to do as nvf does not depend # on a binary cache. @@ -25,6 +34,8 @@ To use it, we first add the input flake. # for example: inputs.obsidian-nvim.follows = "obsidian-nvim"; # <- this will use the obsidian-nvim from your inputs }; + + # ... }; } ``` @@ -39,7 +50,7 @@ Followed by importing the home-manager module somewhere in your configuration. } ``` -## Example Installation {#sec-example-installation-hm} +### Example Installation {#sec-example-installation-hm} ```nix { @@ -66,7 +77,8 @@ Once the module is properly imported by your host, you will be able to use the `programs.nvf` module option anywhere in your configuration in order to configure **nvf**. -```nix{ +```nix +{ programs.nvf = { enable = true; # your settings need to go into the settings attribute set @@ -89,3 +101,45 @@ installation sections of the manual. You may find all available options in the [appendix](https://notashelf.github.io/nvf/options) ::: + +## Without Flakes {#sec-hm-flakeless} + +As of v0.8, it is possible to install **nvf** on a system if you are not using +flakes. This is possible thanks to the flake-compat project. + +To get started, you must fetch the repository using `builtins.fetchTarball` or a +similar mechanism. + +```nix +# home.nix +let + nvf = import (builtins.fetchTarball { + url = "https://github.com/notashelf/nvf/archive/.tar.gz"; + # Optionally, you can add 'sha256' for verification and caching + # sha256 = ""; + }); +in { + imports = [ + # Import the NixOS module from your fetched input + nvf.homeManagerModules.nvf + ]; + + # Once the module is imported, you may use `programs.nvf` as exposed by the + # NixOS module. + programs.nvf.enable = true; +} +``` + +[npins]: https://github.com/andir/npins +[niv]: https://github.com/nmattia/niv + +::: {.tip} + +Nix2 does not have a builtin lockfile mechanism like flakes. As such you must +manually update the URL and hash for your input. This is annoying to deal with, +and most users choose to defer this task to projects such as [npins] or [niv]. +If you are new to NixOS, I encourage you to look into Flakes and see if they fit +your use case. Alternatively, look into the aforementioned projects for more +convenient dependency management mechanisms. + +::: diff --git a/docs/manual/installation/modules/nixos.md b/docs/manual/installation/modules/nixos.md index bcf7472b..946905c1 100644 --- a/docs/manual/installation/modules/nixos.md +++ b/docs/manual/installation/modules/nixos.md @@ -5,9 +5,18 @@ the NixOS configuration without having to call for the wrapper yourself. It is the recommended way to use **nvf** alongside the home-manager module depending on your needs. -To use it, we first add the input flake. +## With Flakes {#sec-nixos-flakes} + +```{=include=} +flakes.md +``` + +### Usage {#sec-nixos-flakes-usage} + +To use **nvf** with flakes, we first need to add the input to our `flake.nix`. ```nix +# flake.nix { inputs = { # Optional, if you intend to follow nvf's obsidian-nvim input @@ -16,7 +25,7 @@ To use it, we first add the input flake. # Required, nvf works best and only directly supports flakes nvf = { - url = "github:notashelf/nvf"; + url = "github:NotAShelf/nvf"; # You can override the input nixpkgs to follow your system's # instance of nixpkgs. This is safe to do as nvf does not depend # on a binary cache. @@ -25,6 +34,8 @@ To use it, we first add the input flake. # for example: inputs.obsidian-nvim.follows = "obsidian-nvim"; # <- this will use the obsidian-nvim from your inputs }; + + # ... }; } ``` @@ -39,7 +50,7 @@ Followed by importing the NixOS module somewhere in your configuration. } ``` -## Example Installation {#sec-example-installation-nixos} +### Example Installation {#sec-example-installation-nixos} ```nix { @@ -64,10 +75,12 @@ Once the module is properly imported by your host, you will be able to use the `programs.nvf` module option anywhere in your configuration in order to configure **nvf**. -```nix{ +```nix +{ programs.nvf = { enable = true; - # your settings need to go into the settings attribute set + + # Your settings need to go into the settings attribute set # most settings are documented in the appendix settings = { vim.viAlias = false; @@ -87,3 +100,45 @@ installation sections of the manual. You may find all available options in the [appendix](https://notashelf.github.io/nvf/options) ::: + +## Without Flakes {#sec-nixos-flakeless} + +As of v0.8, it is possible to install **nvf** on a system if you are not using +flakes. This is possible thanks to the flake-compat project. + +To get started, you must fetch the repository using `builtins.fetchTarball` or a +similar mechanism. + +```nix +# configuration.nix +let + nvf = import (builtins.fetchTarball { + url = "https://github.com/notashelf/nvf/archive/.tar.gz"; + # Optionally, you can add 'sha256' for verification and caching + # sha256 = ""; + }); +in { + imports = [ + # Import the NixOS module from your fetched input + nvf.nixosModules.nvf + ]; + + # Once the module is imported, you may use `programs.nvf` as exposed by the + # NixOS module. + programs.nvf.enable = true; +} +``` + +[npins]: https://github.com/andir/npins +[niv]: https://github.com/nmattia/niv + +::: {.tip} + +Nix2 does not have a builtin lockfile mechanism like flakes. As such you must +manually update the URL and hash for your input. This is annoying to deal with, +and most users choose to defer this task to projects such as [npins] or [niv]. +If you are new to NixOS, I encourage you to look into Flakes and see if they fit +your use case. Alternatively, look into the aforementioned projects for more +convenient dependency management mechanisms. + +::: diff --git a/docs/manual/try-it-out.md b/docs/manual/try-it-out.md index 5f326b15..a5d20363 100644 --- a/docs/manual/try-it-out.md +++ b/docs/manual/try-it-out.md @@ -5,19 +5,20 @@ installing it to your machine. Below are the commands you may run to try out different configurations provided by this flake. As of v0.5, two specialized configurations are provided: -- **Nix** - Nix language server + simple utility plugins -- **Maximal** - Variable language servers + utility and decorative plugins +- **Nix** (`packages.nix`) - Nix language server + simple utility plugins +- **Maximal** (`packages.maximal`) - Variable language servers + utility and + decorative plugins You may try out any of the provided configurations using the `nix run` command on a system where Nix is installed. -```bash +```sh $ cachix use nvf # Optional: it'll save you CPU resources and time -$ nix run github:notashelf/nvf#nix # will run the default minimal configuration +$ nix run github:notashelf/nvf#nix # Will run the default minimal configuration ``` -Do keep in mind that this is **susceptible to garbage collection** meaning it -will be removed from your Nix store once you garbage collect. +Do keep in mind that this is **susceptible to garbage collection** meaning that +the built outputs will be removed from your Nix store once you garbage collect. ## Using Prebuilt Configs {#sec-using-prebuilt-configs} @@ -65,6 +66,7 @@ companion or fun plugins. ::: {.warning} Running the maximal config will download _a lot_ of packages as it is -downloading language servers, formatters, and more. +downloading language servers, formatters, and more. If CPU time and bandwidth +are concerns, please use the default package instead. :::