From 9f2b67d89b10b2f5375e77c976990f87c869d6fd Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 24 Apr 2018 20:27:10 +0200 Subject: [PATCH 1/4] Revert ".version: remove final newline" This reverts commit e109784f84d44cc73abeaa6c96c5a5d5bf9e3e06. --- .editorconfig | 4 ---- .version | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index f5df33889e6b..7b40ff1ff568 100644 --- a/.editorconfig +++ b/.editorconfig @@ -26,7 +26,3 @@ indent_size = 4 # Match diffs, avoid to trim trailing whitespace [*.{diff,patch}] trim_trailing_whitespace = false - -# https://github.com/NixOS/nixpkgs/pull/39336#discussion_r183387754 -[.version] -insert_final_newline = false diff --git a/.version b/.version index c1b80a502792..770bde1f44b3 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -18.09 \ No newline at end of file +18.09 From f66cdc71a3300581501fd953f8e359b7ff824933 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 24 Apr 2018 20:30:12 +0200 Subject: [PATCH 2/4] osquery: use `stdenv.lib.nixpkgsVersion` This way easier to understand and the officially recommended approach. /cc @dezgeg @fpletz --- pkgs/tools/system/osquery/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/system/osquery/default.nix b/pkgs/tools/system/osquery/default.nix index 2a719efd79b3..b88186a610bf 100644 --- a/pkgs/tools/system/osquery/default.nix +++ b/pkgs/tools/system/osquery/default.nix @@ -24,7 +24,7 @@ stdenv.mkDerivation rec { # this is what `osquery --help` will show as the version. OSQUERY_BUILD_VERSION = version; - OSQUERY_PLATFORM = "nixos;${builtins.readFile "${toString path}/.version"}"; + OSQUERY_PLATFORM = "nixos;${stdenv.lib.nixpkgsVersion}"; src = fetchFromGitHub { owner = "facebook"; From 39909289f452fcd60127cbd2372f22ac35f25d08 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 24 Apr 2018 20:33:35 +0200 Subject: [PATCH 3/4] lib: deduplicate version/suffix references The logic regarding the generated `.version-suffix` file is already defined in `lib/trivial.nix` and shouldn't be duplicated in `nixos/version`. --- lib/trivial.nix | 9 +++++---- nixos/modules/misc/version.nix | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/trivial.nix b/lib/trivial.nix index a928e1dbca98..a6a4abba1189 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -58,11 +58,12 @@ rec { inherit (lib.strings) fileContents; + version = fileContents ../.version; + suffix = let suffixFile = ../.version-suffix; in + if pathExists suffixFile then fileContents suffixFile else "pre-git"; + # Return the Nixpkgs version number. - nixpkgsVersion = - let suffixFile = ../.version-suffix; in - fileContents ../.version - + (if pathExists suffixFile then fileContents suffixFile else "pre-git"); + nixpkgsVersion = version + suffix; # Whether we're being called by nix-shell. inNixShell = builtins.getEnv "IN_NIX_SHELL" != ""; diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index b8f0a223c910..d9d60b725093 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -5,8 +5,6 @@ with lib; let cfg = config.system.nixos; - releaseFile = "${toString pkgs.path}/.version"; - suffixFile = "${toString pkgs.path}/.version-suffix"; revisionFile = "${toString pkgs.path}/.git-revision"; gitRepo = "${toString pkgs.path}/.git"; gitCommitId = lib.substring 0 7 (commitIdFromGitRepo gitRepo); @@ -25,14 +23,14 @@ in nixos.release = mkOption { readOnly = true; type = types.str; - default = fileContents releaseFile; + default = trivial.version; description = "The NixOS release (e.g. 16.03)."; }; nixos.versionSuffix = mkOption { internal = true; type = types.str; - default = if pathExists suffixFile then fileContents suffixFile else "pre-git"; + default = trivial.suffix; description = "The NixOS version suffix (e.g. 1160.f2d4ee1)."; }; From 9274ea390348e17f766732e7fbd335e3bc164954 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 26 Apr 2018 10:31:05 +0200 Subject: [PATCH 4/4] treewide: rename version attributes As suggested in https://github.com/NixOS/nixpkgs/pull/39416#discussion_r183845745 the versioning attributes in `lib` should be consistent to `nixos/version` which implicates the following changes: * `lib.trivial.version` -> `lib.trivial.release` * `lib.trivial.suffix` -> `lib.trivial.versionSuffix` * `lib.nixpkgsVersion` -> `lib.version` As `lib.nixpkgsVersion` is referenced several times in `NixOS/nixpkgs`, `NixOS/nix` and probably several user's setups. As the rename will cause a notable impact it's better to keep `lib.nixpkgsVersion` as alias with a warning yielded by `builtins.trace`. --- doc/Makefile | 2 +- doc/default.nix | 2 +- lib/default.nix | 2 +- lib/trivial.nix | 8 +++++--- nixos/doc/manual/release-notes/rl-1809.xml | 5 +++++ nixos/maintainers/scripts/ec2/create-amis.sh | 2 +- nixos/modules/misc/version.nix | 4 ++-- pkgs/tools/system/osquery/default.nix | 2 +- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 0ddae8631f3c..952ef4bfcbb9 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -64,7 +64,7 @@ manual-full.xml: ${MD_TARGETS} .version *.xml .version: nix-instantiate --eval \ - -E '(import ../lib).nixpkgsVersion' > .version + -E '(import ../lib).version' > .version %.section.xml: %.section.md pandoc $^ -w docbook+smart \ diff --git a/doc/default.nix b/doc/default.nix index 8abde58bb114..e5be364506ff 100644 --- a/doc/default.nix +++ b/doc/default.nix @@ -30,7 +30,7 @@ pkgs.stdenv.mkDerivation { ]; postPatch = '' - echo ${lib.nixpkgsVersion} > .version + echo ${lib.version} > .version ''; installPhase = '' diff --git a/lib/default.nix b/lib/default.nix index b3c4fdc0e59a..60ce01a93cd2 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -58,7 +58,7 @@ let replaceStrings seq stringLength sub substring tail; inherit (trivial) id const concat or and boolToString mergeAttrs flip mapNullable inNixShell min max importJSON warn info - nixpkgsVersion mod compare splitByAndCompare + nixpkgsVersion version mod compare splitByAndCompare functionArgs setFunctionArgs isFunction; inherit (fixedPoints) fix fix' extends composeExtensions diff --git a/lib/trivial.nix b/lib/trivial.nix index a6a4abba1189..251cb796db0e 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -58,12 +58,14 @@ rec { inherit (lib.strings) fileContents; - version = fileContents ../.version; - suffix = let suffixFile = ../.version-suffix; in + release = fileContents ../.version; + versionSuffix = let suffixFile = ../.version-suffix; in if pathExists suffixFile then fileContents suffixFile else "pre-git"; # Return the Nixpkgs version number. - nixpkgsVersion = version + suffix; + version = release + versionSuffix; + + nixpkgsVersion = builtins.trace "`lib.nixpkgsVersion` is deprecated, use `lib.version` instead!" version; # Whether we're being called by nix-shell. inNixShell = builtins.getEnv "IN_NIX_SHELL" != ""; diff --git a/nixos/doc/manual/release-notes/rl-1809.xml b/nixos/doc/manual/release-notes/rl-1809.xml index 2e53f0563baf..949dbf0e0c1e 100644 --- a/nixos/doc/manual/release-notes/rl-1809.xml +++ b/nixos/doc/manual/release-notes/rl-1809.xml @@ -123,6 +123,11 @@ following incompatible changes: lib.traceCallXml has been deprecated. Please complain if you use the function regularly. + + The attribute lib.nixpkgsVersion has been deprecated in favor of + lib.version. Please refer to the discussion in + NixOS/nixpkgs#39416 for further reference. + diff --git a/nixos/maintainers/scripts/ec2/create-amis.sh b/nixos/maintainers/scripts/ec2/create-amis.sh index 347e6b9c6e0d..9461144fad5a 100755 --- a/nixos/maintainers/scripts/ec2/create-amis.sh +++ b/nixos/maintainers/scripts/ec2/create-amis.sh @@ -6,7 +6,7 @@ set -e set -o pipefail -version=$(nix-instantiate --eval --strict '' -A lib.nixpkgsVersion | sed s/'"'//g) +version=$(nix-instantiate --eval --strict '' -A lib.version | sed s/'"'//g) major=${version:0:5} echo "NixOS version is $version ($major)" diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index d9d60b725093..74c86443ab90 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -23,14 +23,14 @@ in nixos.release = mkOption { readOnly = true; type = types.str; - default = trivial.version; + default = trivial.release; description = "The NixOS release (e.g. 16.03)."; }; nixos.versionSuffix = mkOption { internal = true; type = types.str; - default = trivial.suffix; + default = trivial.versionSuffix; description = "The NixOS version suffix (e.g. 1160.f2d4ee1)."; }; diff --git a/pkgs/tools/system/osquery/default.nix b/pkgs/tools/system/osquery/default.nix index b88186a610bf..a0aaa846bc73 100644 --- a/pkgs/tools/system/osquery/default.nix +++ b/pkgs/tools/system/osquery/default.nix @@ -24,7 +24,7 @@ stdenv.mkDerivation rec { # this is what `osquery --help` will show as the version. OSQUERY_BUILD_VERSION = version; - OSQUERY_PLATFORM = "nixos;${stdenv.lib.nixpkgsVersion}"; + OSQUERY_PLATFORM = "nixos;${stdenv.lib.version}"; src = fetchFromGitHub { owner = "facebook";