From 45414c48b9818d91de0b30dc002ec768ff57ad93 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Wed, 9 Jul 2025 09:35:56 +0800 Subject: [PATCH] feat(nix): pass flake self to darwin modules and add revision --- flake.nix | 7 +++++-- nix/configurations.nix | 1 + nix/meta.nix | 1 + nix/modules/cli/nix.nix | 7 +++++++ nix/modules/system/system.nix | 7 ++++++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index d6fc5e2..5e22b8c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,14 @@ { outputs = - inputs: + { self, ... }@inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } ( (inputs.import-tree ./nix) // { systems = import inputs.systems; - flake.paths.root = ./.; + flake = { + inherit self; + paths.root = ./.; + }; } ); inputs = { diff --git a/nix/configurations.nix b/nix/configurations.nix index 737700d..efac889 100644 --- a/nix/configurations.nix +++ b/nix/configurations.nix @@ -38,6 +38,7 @@ let } else if class == "darwin" then darwinSystem { + specialArgs = { inherit (config.flake) self; }; modules = [ cfg.modules.darwin.default ]; } else diff --git a/nix/meta.nix b/nix/meta.nix index a10a6da..5c8f8fc 100644 --- a/nix/meta.nix +++ b/nix/meta.nix @@ -56,6 +56,7 @@ let in { options.flake = mkSubmoduleOptions { + self = mkOption { type = raw; }; lib = mkOption { type = lazyAttrsOf raw; default = { }; diff --git a/nix/modules/cli/nix.nix b/nix/modules/cli/nix.nix index ad97ee5..a69b1d6 100644 --- a/nix/modules/cli/nix.nix +++ b/nix/modules/cli/nix.nix @@ -3,4 +3,11 @@ "nix-command" "flakes" ]; + flake.modules.darwin.default = { + nix.enable = false; + nix.settings.experimental-features = [ + "nix-command" + "flakes" + ]; + }; } diff --git a/nix/modules/system/system.nix b/nix/modules/system/system.nix index ead2992..9b50970 100644 --- a/nix/modules/system/system.nix +++ b/nix/modules/system/system.nix @@ -12,6 +12,11 @@ { home.stateVersion = osConfig.system.stateVersion; }; - darwin.default.system.stateVersion = 6; + darwin.default = + { self, ... }: + { + system.configurationRevision = self.rev or self.dirtyRev or null; + system.stateVersion = 6; + }; }; }