Merge pull request #17357 from ericsagnes/feat/fileContents
lib: add fileContents function
This commit is contained in:
commit
f8108c1267
@ -44,12 +44,12 @@ rec {
|
|||||||
packedRefsName = toString path + "/packed-refs";
|
packedRefsName = toString path + "/packed-refs";
|
||||||
in if lib.pathExists fileName
|
in if lib.pathExists fileName
|
||||||
then
|
then
|
||||||
let fileContent = readFile fileName;
|
let fileContent = lib.fileContents fileName;
|
||||||
# Sometimes git stores the commitId directly in the file but
|
# Sometimes git stores the commitId directly in the file but
|
||||||
# sometimes it stores something like: «ref: refs/heads/branch-name»
|
# sometimes it stores something like: «ref: refs/heads/branch-name»
|
||||||
matchRef = match "^ref: (.*)\n$" fileContent;
|
matchRef = match "^ref: (.*)$" fileContent;
|
||||||
in if isNull matchRef
|
in if isNull matchRef
|
||||||
then lib.removeSuffix "\n" fileContent
|
then fileContent
|
||||||
else readCommitFromFile path (lib.head matchRef)
|
else readCommitFromFile path (lib.head matchRef)
|
||||||
# Sometimes, the file isn't there at all and has been packed away in the
|
# Sometimes, the file isn't there at all and has been packed away in the
|
||||||
# packed-refs file, so we have to grep through it:
|
# packed-refs file, so we have to grep through it:
|
||||||
|
@ -479,4 +479,14 @@ rec {
|
|||||||
absolutePaths = builtins.map (path: builtins.toPath (root + "/" + path)) relativePaths;
|
absolutePaths = builtins.map (path: builtins.toPath (root + "/" + path)) relativePaths;
|
||||||
in
|
in
|
||||||
absolutePaths;
|
absolutePaths;
|
||||||
|
|
||||||
|
/* Read the contents of a file removing the trailing \n
|
||||||
|
|
||||||
|
Example:
|
||||||
|
$ echo "1.0" > ./version
|
||||||
|
|
||||||
|
fileContents ./version
|
||||||
|
=> "1.0"
|
||||||
|
*/
|
||||||
|
fileContents = file: removeSuffix "\n" (builtins.readFile file);
|
||||||
}
|
}
|
||||||
|
@ -62,11 +62,13 @@ rec {
|
|||||||
isInt add sub lessThan
|
isInt add sub lessThan
|
||||||
seq deepSeq genericClosure;
|
seq deepSeq genericClosure;
|
||||||
|
|
||||||
|
inherit (import ./strings.nix) fileContents;
|
||||||
|
|
||||||
# Return the Nixpkgs version number.
|
# Return the Nixpkgs version number.
|
||||||
nixpkgsVersion =
|
nixpkgsVersion =
|
||||||
let suffixFile = ../.version-suffix; in
|
let suffixFile = ../.version-suffix; in
|
||||||
readFile ../.version
|
fileContents ../.version
|
||||||
+ (if pathExists suffixFile then readFile suffixFile else "pre-git");
|
+ (if pathExists suffixFile then fileContents suffixFile else "pre-git");
|
||||||
|
|
||||||
# Whether we're being called by nix-shell.
|
# Whether we're being called by nix-shell.
|
||||||
inNixShell = builtins.getEnv "IN_NIX_SHELL" == "1";
|
inNixShell = builtins.getEnv "IN_NIX_SHELL" == "1";
|
||||||
|
@ -49,21 +49,21 @@ in
|
|||||||
nixosRelease = mkOption {
|
nixosRelease = mkOption {
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = readFile releaseFile;
|
default = fileContents releaseFile;
|
||||||
description = "The NixOS release (e.g. <literal>16.03</literal>).";
|
description = "The NixOS release (e.g. <literal>16.03</literal>).";
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosVersionSuffix = mkOption {
|
nixosVersionSuffix = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = if pathExists suffixFile then readFile suffixFile else "pre-git";
|
default = if pathExists suffixFile then fileContents suffixFile else "pre-git";
|
||||||
description = "The NixOS version suffix (e.g. <literal>1160.f2d4ee1</literal>).";
|
description = "The NixOS version suffix (e.g. <literal>1160.f2d4ee1</literal>).";
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosRevision = mkOption {
|
nixosRevision = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = if pathExists revisionFile then readFile revisionFile else "master";
|
default = if pathExists revisionFile then fileContents revisionFile else "master";
|
||||||
description = "The Git revision from which this NixOS configuration was built.";
|
description = "The Git revision from which this NixOS configuration was built.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ with import ../lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
version = builtins.readFile ../.version;
|
version = fileContents ../.version;
|
||||||
versionSuffix =
|
versionSuffix =
|
||||||
(if stableBranch then "." else "pre") + "${toString nixpkgs.revCount}.${nixpkgs.shortRev}";
|
(if stableBranch then "." else "pre") + "${toString nixpkgs.revCount}.${nixpkgs.shortRev}";
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ releaseTools.sourceTarball rec {
|
|||||||
src = nixpkgs;
|
src = nixpkgs;
|
||||||
|
|
||||||
inherit officialRelease;
|
inherit officialRelease;
|
||||||
version = builtins.readFile ../../.version;
|
version = pkgs.lib.fileContents ../../.version;
|
||||||
versionSuffix = "pre${toString nixpkgs.revCount}.${nixpkgs.shortRev}";
|
versionSuffix = "pre${toString nixpkgs.revCount}.${nixpkgs.shortRev}";
|
||||||
|
|
||||||
buildInputs = [ nix.out jq ];
|
buildInputs = [ nix.out jq ];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user