summary refs log tree commit diff
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2024-10-22 23:17:33 +0200
committerMel <einebeere@gmail.com>2024-10-22 23:40:59 +0200
commitbb0e4c7b5bbec7b8d8e3433a87683e9bb5ec307a (patch)
tree87e0cf82dc573f9000dfb998326e504fa2e2a0d6
parent42d23c55e924b5100d5c357458f20de640db2400 (diff)
downloadminerals-bb0e4c7b5bbec7b8d8e3433a87683e9bb5ec307a.tar.zst
minerals-bb0e4c7b5bbec7b8d8e3433a87683e9bb5ec307a.zip
Add compatibility scripts for nixos-option and other legacy nix tools
Signed-off-by: Mel <einebeere@gmail.com>
-rw-r--r--compat/default.nix20
-rw-r--r--compat/flake-compat.nix11
-rw-r--r--compat/nixos/default.nix13
-rw-r--r--flake.lock16
-rw-r--r--flake.nix7
5 files changed, 66 insertions, 1 deletions
diff --git a/compat/default.nix b/compat/default.nix
new file mode 100644
index 0000000..0077090
--- /dev/null
+++ b/compat/default.nix
@@ -0,0 +1,20 @@
+# compatability files for `nixos-option` and other legacy
+# nix tools.
+#
+# `nixos-option` does not support flakes (as of yet),
+# so we need to give it the path to `<nixpkgs>` (this file)
+# and to `<nixos-config>` (in `./nixos/default.nix`) which
+# then both return the correct outputs from the system flake.
+#
+# can also be useful for running out-of-tree `shell.nix` and `default.nix`
+# files, without creating a custom flake for them and still having them
+# get the correct package sets from the system flake configuration.
+#
+# see here: https://github.com/NixOS/nixpkgs/issues/97855#issuecomment-799925924
+
+{ ... }:
+
+let
+  flake = import ./flake-compat.nix { src = ./..; };
+in
+flake.defaultNix.legacyPackages.${builtins.currentSystem}
diff --git a/compat/flake-compat.nix b/compat/flake-compat.nix
new file mode 100644
index 0000000..ac56432
--- /dev/null
+++ b/compat/flake-compat.nix
@@ -0,0 +1,11 @@
+with builtins;
+let
+  lock = fromJSON (readFile ../flake.lock);
+  
+  flake-compat = builtins.fetchGit (with lock.nodes.flake-compat.locked; {
+    inherit rev;
+    url = "https://github.com/${owner}/${repo}.git";
+  });
+
+in
+{ src, ... }: import flake-compat { inherit src; }
diff --git a/compat/nixos/default.nix b/compat/nixos/default.nix
new file mode 100644
index 0000000..3d547c2
--- /dev/null
+++ b/compat/nixos/default.nix
@@ -0,0 +1,13 @@
+# this file provides the current nixos configuration
+# taken from the system flake.
+# see `../default.nix` for explanation.
+{ nixpkgs ? import <nixpkgs> {}, ... }:
+
+with builtins;
+let
+  me = with builtins;
+    nixpkgs.lib.toLower (head (split "\n" (readFile /etc/hostname)));
+
+  flake = import ../flake-compat.nix { src = ./../..; };
+in
+flake.defaultNix.nixosConfigurations.${me}
diff --git a/flake.lock b/flake.lock
index 0efe3b1..e20833c 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,5 +1,20 @@
 {
   "nodes": {
+    "flake-compat": {
+      "locked": {
+        "lastModified": 1696426674,
+        "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
+        "owner": "edolstra",
+        "repo": "flake-compat",
+        "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
+        "type": "github"
+      },
+      "original": {
+        "owner": "edolstra",
+        "repo": "flake-compat",
+        "type": "github"
+      }
+    },
     "home-manager": {
       "inputs": {
         "nixpkgs": [
@@ -55,6 +70,7 @@
     },
     "root": {
       "inputs": {
+        "flake-compat": "flake-compat",
         "home-manager": "home-manager",
         "nixpkgs": "nixpkgs",
         "nixpkgs-unstable": "nixpkgs-unstable"
diff --git a/flake.nix b/flake.nix
index 7075583..25e94d1 100644
--- a/flake.nix
+++ b/flake.nix
@@ -8,9 +8,11 @@
       url = "github:nix-community/home-manager/release-24.05";
       inputs.nixpkgs.follows = "nixpkgs";
     };
+
+    flake-compat.url = "github:edolstra/flake-compat";
   };
 
-  outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, home-manager }:
+  outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, home-manager, ... }:
   let
     system = "x86_64-linux";
 
@@ -47,5 +49,8 @@
         ];
       }
     );
+
+    # compatibility wrapper for nixos-option
+    legacyPackages.${system} = with packageSets; pkgs.recurseIntoAttrs pkgs;
   };
 }