diff --git a/flake.nix b/flake.nix index 204898c..191c5fb 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,20 @@ # WARNING this is very much still experimental. description = "A collection of darwin modules"; - outputs = { self, nixpkgs }: { + outputs = { self, nixpkgs }: + let + versionsModule = { lib, ... }: { + _file = ./flake.nix; + config = { + system.darwinVersionSuffix = ".${nixpkgs.shortRev or "dirty"}"; + system.darwinRevision = lib.mkIf (self ? rev) self.rev; + + system.nixpkgsVersionSuffix = ".${lib.substring 0 8 (nixpkgs.lastModifiedDate or nixpkgs.lastModified or "19700101")}.${nixpkgs.shortRev or "dirty"}"; + system.nixpkgsRevision = lib.mkIf (nixpkgs ? rev) nixpkgs.rev; + }; + }; + in + { lib = { # TODO handle multiple architectures. @@ -10,8 +23,7 @@ darwinSystem = { modules, inputs ? {}, ... }@args: self.lib.evalConfig (args // { inputs = { inherit nixpkgs; darwin = self; } // inputs; - modules = modules ++ [ - ]; + modules = modules ++ [ versionsModule ]; }); }; diff --git a/modules/system/version.nix b/modules/system/version.nix index 46291d6..7b9236d 100644 --- a/modules/system/version.nix +++ b/modules/system/version.nix @@ -59,6 +59,12 @@ in description = "The full darwin version (e.g. darwin4.master)."; }; + system.darwinVersionSuffix = mkOption { + internal = true; + type = types.str; + description = "The short darwin version suffix (e.g. .2abdb5a)."; + }; + system.darwinRevision = mkOption { internal = true; type = types.str; @@ -78,6 +84,12 @@ in description = "The full nixpkgs version (e.g. 16.03.1160.f2d4ee1)."; }; + system.nixpkgsVersionSuffix = mkOption { + internal = true; + type = types.str; + description = "The short nixpkgs version suffix (e.g. .1160.f2d4ee1)."; + }; + system.nixpkgsRevision = mkOption { internal = true; type = types.str; @@ -89,12 +101,14 @@ in # These defaults are set here rather than up there so that # changing them would not rebuild the manual - system.darwinLabel = "${cfg.nixpkgsVersion}+${cfg.darwinVersion}"; - system.darwinVersion = "darwin" + toString cfg.stateVersion + "." + darwin.shortRev; + system.darwinLabel = mkDefault "${cfg.nixpkgsVersion}+${cfg.darwinVersion}"; + system.darwinVersion = mkDefault "darwin${toString cfg.stateVersion}${cfg.darwinVersionSuffix}"; + system.darwinVersionSuffix = mkDefault ".${darwin.shortRev}"; system.darwinRevision = mkIf (darwin ? rev) (mkDefault darwin.rev); - system.nixpkgsVersion = mkDefault (cfg.nixpkgsRelease + nixpkgsSuffix); + system.nixpkgsVersion = mkDefault "${cfg.nixpkgsRelease}${cfg.nixpkgsVersionSuffix}"; system.nixpkgsRelease = mkDefault (fileContents releaseFile); + system.nixpkgsVersionSuffix = mkDefault nixpkgsSuffix; system.nixpkgsRevision = mkIf (nixpkgs ? rev) (mkDefault nixpkgs.rev); assertions = [ { assertion = cfg.stateVersion <= defaultStateVersion; message = "system.stateVersion = ${toString cfg.stateVersion}; is not a valid value"; } ];