diff --git a/default.nix b/default.nix index 477e232..54b0010 100644 --- a/default.nix +++ b/default.nix @@ -31,6 +31,7 @@ let ./modules/system/applications.nix ./modules/system/etc.nix ./modules/system/launchd.nix + ./modules/system/version.nix ./modules/time ./modules/networking ./modules/nix diff --git a/modules/system/default.nix b/modules/system/default.nix index 1cc0290..2d0e750 100644 --- a/modules/system/default.nix +++ b/modules/system/default.nix @@ -42,11 +42,6 @@ in ''; }; - system.darwinLabel = mkOption { - type = types.str; - default = pkgs.lib.nixpkgsVersion; - }; - assertions = mkOption { type = types.listOf types.unspecified; internal = true; diff --git a/modules/system/version.nix b/modules/system/version.nix new file mode 100644 index 0000000..5a6b247 --- /dev/null +++ b/modules/system/version.nix @@ -0,0 +1,76 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.system; + + gitCommitId = lib.substring 0 7 (commitIdFromGitRepo gitRepo); + gitRepo = "${toString pkgs.path}/.git"; + releaseFile = "${toString pkgs.path}/.version"; + revisionFile = "${toString pkgs.path}/.git-revision"; + suffixFile = "${toString pkgs.path}/.version-suffix"; +in + +{ + options = { + system.stateVersion = mkOption { + type = types.int; + default = 2; + description = '' + Every once in a while, a new NixOS release may change + configuration defaults in a way incompatible with stateful + data. For instance, if the default version of PostgreSQL + changes, the new version will probably be unable to read your + existing databases. To prevent such breakage, you can set the + value of this option to the NixOS release with which you want + to be compatible. The effect is that NixOS will option + defaults corresponding to the specified release (such as using + an older version of PostgreSQL). + ''; + }; + + system.darwinLabel = mkOption { + type = types.str; + default = cfg.nixpkgsVersion; + description = "Label to be used in the names of generated outputs."; + }; + + system.nixpkgsRelease = mkOption { + readOnly = true; + type = types.str; + default = fileContents releaseFile; + description = "The nixpkgs release (e.g. 16.03)."; + }; + + system.nixpkgsVersion = mkOption { + internal = true; + type = types.str; + description = "The full nixpkgs version (e.g. 16.03.1160.f2d4ee1)."; + }; + + system.nixpkgsVersionSuffix = mkOption { + internal = true; + type = types.str; + default = "pre-git"; + description = "The nixpkgs version suffix (e.g. 1160.f2d4ee1)."; + }; + + system.nixpkgsRevision = mkOption { + internal = true; + type = types.str; + default = "master"; + description = "The nixpkgs git revision from which this configuration was built."; + }; + }; + + config = { + + # These defaults are set here rather than up there so that + # changing them would not rebuild the manual + system.nixpkgsVersion = mkDefault (cfg.nixpkgsRelease + cfg.nixpkgsVersionSuffix); + system.nixpkgsRevision = mkIf (pathIsDirectory gitRepo) (mkDefault gitCommitId); + system.nixpkgsVersionSuffix = mkIf (pathIsDirectory gitRepo) (mkDefault (".git." + gitCommitId)); + + }; +}