about summary refs log tree commit diff stats
path: root/flake
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-08-22 15:23:42 +0200
committerSoispha <soispha@vhack.eu>2023-08-22 15:23:42 +0200
commitdcc9461cc55e1936f2546ac2ac7da243eb48306f (patch)
tree5e662c8f09579a7ce8a9f2401b93063185371cb7 /flake
parentBuild(flake): Update (diff)
downloadnixos-config-dcc9461cc55e1936f2546ac2ac7da243eb48306f.tar.gz
nixos-config-dcc9461cc55e1936f2546ac2ac7da243eb48306f.zip
Feat(flake): Provide the neovim config as a package
Diffstat (limited to 'flake')
-rw-r--r--flake/default.nix2
-rw-r--r--flake/packages/default.nix44
-rw-r--r--flake/packages/merge.nix86
3 files changed, 131 insertions, 1 deletions
diff --git a/flake/default.nix b/flake/default.nix
index a8c597e9..63dea536 100644
--- a/flake/default.nix
+++ b/flake/default.nix
@@ -93,7 +93,7 @@ in {
       ;
   };
   packages."${system}" = import ./packages {
-    inherit nixos-generators defaultSpecialArgs defaultModules pkgs sysLib;
+    inherit nixos-generators defaultSpecialArgs defaultModules pkgs sysLib system nixVim self;
     inherit (pkgs) lib;
   };
 
diff --git a/flake/packages/default.nix b/flake/packages/default.nix
index 4ab68775..708852a0 100644
--- a/flake/packages/default.nix
+++ b/flake/packages/default.nix
@@ -1,12 +1,54 @@
 {
+  self,
   nixos-generators,
   defaultSpecialArgs,
   defaultModules,
   pkgs,
   sysLib,
+  nixVim,
+  system,
   ...
 }: let
+  inherit (pkgs) lib;
+  inherit (import ./merge.nix {inherit lib;}) merge;
   output = import ../../bootstrap {inherit pkgs sysLib;};
+  args = {
+    inherit pkgs;
+    inherit (pkgs) lib;
+  };
+  nvim =
+    builtins.mapAttrs (
+      name: value: let
+        nvim_config =
+          import ../../home-manager/soispha/config/neovim/nixvim/default.nix
+          args;
+        build_args = args // {nixosConfig = value.config;};
+
+        merge_attrs = list_of_attrs: builtins.foldl' (x: y: merge [x y]) {} list_of_attrs;
+        resolve_imports = attrs:
+          merge_attrs (builtins.map (v: import v build_args)
+            attrs.imports);
+
+        resolve_imports' = attrs:
+          if builtins.any (n: n == "imports") (builtins.attrNames attrs)
+          then
+            resolve_imports' (merge_attrs [
+              (resolve_imports attrs)
+              (builtins.removeAttrs
+                attrs
+                ["imports"])
+            ])
+          else attrs;
+
+        complete_config = resolve_imports' nvim_config;
+      in
+        nixVim.legacyPackages."${system}".makeNixvim
+        (
+          builtins.removeAttrs
+          complete_config.programs.nixvim ["enable"]
+        )
+    )
+    self.nixosConfigurations;
 in
   {
     install-iso = nixos-generators.nixosGenerate {
@@ -27,5 +69,7 @@ in
         ++ defaultModules;
       format = "iso";
     };
+    vim = nvim.tiamat;
+    inherit nvim;
   }
   // output
diff --git a/flake/packages/merge.nix b/flake/packages/merge.nix
new file mode 100644
index 00000000..8c8ed134
--- /dev/null
+++ b/flake/packages/merge.nix
@@ -0,0 +1,86 @@
+{lib, ...}: let
+  merge = merge_list: let
+    head_of_merge = builtins.head merge_list;
+  in
+    if builtins.isAttrs head_of_merge
+    then
+      builtins.zipAttrsWith (
+        name: values: let
+          head_value = builtins.head values;
+        in
+          if builtins.isString head_value
+          then builtins.concatStringsSep "" values
+          else if builtins.isList head_value
+          then builtins.concatLists values
+          else if builtins.isAttrs head_value
+          then merge values
+          else builtins.head values
+      )
+      merge_list
+    else if builtins.isString head_of_merge
+    then builtins.concatStringsSep "" merge_list
+    else if builtins.isList head_of_merge
+    then builtins.concatLists merge_list
+    else builtins.head merge_list;
+
+  # Tests
+  ## Strings
+  a = {
+    a = ''
+      This is some
+    '';
+  };
+  b = {
+    a = ''
+      example text
+    '';
+  };
+  c = {
+    a = "(which is nice)";
+  };
+  ## Lists
+  d = {
+    a = ["element1" "element2"];
+  };
+  e = {
+    a = [["elment3" "elemnt4"]];
+  };
+  f = {
+    a = ["elemnt5"];
+  };
+  ## Pure strings
+  g = "This";
+  h = "is";
+  i = "some example text";
+  j = ''
+    (with a newline)
+  '';
+  ## Pure lists
+  k = ["element1"];
+  l = ["element2" "element3"];
+  m = ["element4"];
+
+  ## Prepared tests
+  tests = {
+    tests = []; # Uncomment to actually run the tests
+    test_strings = {
+      expr = merge [a b c];
+      expected = {a = "This is some\nexample text\n(which is nice)";};
+    };
+    test_lists = {
+      expr = merge [d e f];
+      expected = {a = ["element1" "element2" ["elment3" "elemnt4"] "elemnt5"];};
+    };
+    test_pure_strings = {
+      expr = merge [g h i j];
+      expected = "Thisissome example text(with a newline)\n";
+    };
+    test_pure_lists = {
+      expr = merge [k l m];
+      expected = ["element1" "element2" "element3" "element4"];
+    };
+  };
+in {
+  inherit merge;
+  result = lib.debug.runTests tests;
+}