1
1
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-08-16 08:00:34 +03:00

Merge pull request #733 from Enzime/version

Add `darwin-version` command
This commit is contained in:
Michael Hoang 2023-07-23 18:16:13 +10:00 committed by GitHub
commit 0f9058e739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 86 additions and 11 deletions

View File

@ -30,14 +30,17 @@
system.checks.verifyNixPath = lib.mkDefault false;
system.darwinVersionSuffix = ".${self.shortRev or "dirty"}";
system.darwinRevision = lib.mkIf (self ? rev) self.rev;
system.darwinVersionSuffix = ".${self.shortRev or self.dirtyShortRev or "dirty"}";
system.darwinRevision = let
rev = self.rev or self.dirtyRev or null;
in
lib.mkIf (rev != null) rev;
}) ];
});
};
overlays.default = final: prev: {
inherit (prev.callPackage ./pkgs/nix-tools { }) darwin-rebuild darwin-option;
inherit (prev.callPackage ./pkgs/nix-tools { }) darwin-rebuild darwin-option darwin-version;
darwin-uninstaller = prev.callPackage ./pkgs/darwin-uninstaller { nix-darwin = self; };
};
@ -76,7 +79,7 @@
in {
default = self.packages.${system}.darwin-rebuild;
inherit (pkgs) darwin-option darwin-rebuild darwin-uninstaller;
inherit (pkgs) darwin-option darwin-rebuild darwin-version darwin-uninstaller;
});
};
}

View File

@ -27,6 +27,9 @@
programs.zsh.enable = true; # default shell on catalina
# programs.fish.enable = true;
# Set Git commit hash for darwin-version.
system.configurationRevision = self.rev or self.dirtyRev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;

View File

@ -125,7 +125,7 @@
set -g pane-border-style fg=black
set -g status-bg black
set -g status-fg white
set -g status-right '#[fg=white]#(id -un)@#(hostname) #(cat /run/current-system/darwin-version)'
set -g status-right '#[fg=white]#(id -un)@#(hostname) #(jq --raw-output '.darwinLabel' /run/current-system/darwin-version.json)'
'';
environment.etc."nix/user-sandbox.sb".text = ''

View File

@ -7,7 +7,7 @@ let
nixPackage = config.nix.package;
};
inherit (nix-tools) darwin-option darwin-rebuild;
inherit (nix-tools) darwin-option darwin-rebuild darwin-version;
in
{
@ -17,10 +17,11 @@ in
[ # Include nix-tools by default
darwin-option
darwin-rebuild
darwin-version
];
system.build = {
inherit darwin-option darwin-rebuild;
inherit darwin-option darwin-rebuild darwin-version;
};
};

View File

@ -96,6 +96,12 @@ in
activationUserScript = cfg.activationScripts.userScript.text;
inherit (cfg) darwinLabel;
darwinVersionJson = (pkgs.formats.json {}).generate "darwin-version.json" (
filterAttrs (k: v: v != null) {
inherit (config.system) darwinRevision nixpkgsRevision configurationRevision darwinLabel;
}
);
buildCommand = ''
mkdir $out
@ -129,7 +135,7 @@ in
echo -n "$systemConfig" > $out/systemConfig
echo -n "$darwinLabel" > $out/darwin-version
ln -s $darwinVersionJson $out/darwin-version.json
echo -n "$system" > $out/system
${cfg.systemBuilderCommands}

View File

@ -108,6 +108,12 @@ in
else lib.trivial.revisionWithDefault null;
description = lib.mdDoc "The nixpkgs git revision from which this configuration was built.";
};
system.configurationRevision = mkOption {
type = types.nullOr types.str;
default = null;
description = lib.mdDoc "The Git revision of the top-level flake from which this configuration was built.";
};
};
config = {

View File

@ -8,12 +8,11 @@ showSyntax() {
echo "darwin-rebuild [--help] {edit | switch | activate | build | check | changelog}" >&2
echo " [--list-generations] [{--profile-name | -p} name] [--rollback]" >&2
echo " [{--switch-generation | -G} generation] [--verbose...] [-v...]" >&2
echo " [-Q] [{--max-jobs | -j} number] [--cores number] [--dry-run]" >&1
echo " [-Q] [{--max-jobs | -j} number] [--cores number] [--dry-run]" >&2
echo " [--keep-going] [-k] [--keep-failed] [-K] [--fallback] [--show-trace]" >&2
echo " [-I path] [--option name value] [--arg name value] [--argstr name value]" >&2
echo " [--flake flake] [--update-input input flake] [--impure] [--recreate-lock-file]"
echo " [--flake flake] [--update-input input flake] [--impure] [--recreate-lock-file]" >&2
echo " [--no-update-lock-file] [--refresh] ..." >&2
exec man darwin-rebuild
exit 1
}

View File

@ -0,0 +1,50 @@
#! @shell@
set -e
set -o pipefail
export PATH=@path@:$PATH
showSyntax() {
echo "darwin-version [--help|--darwin-revision|--nixpkgs-revision|--configuration-revision|--json]" >&2
}
case "$1" in
--help)
showSyntax
;;
--darwin-revision)
revision="$(jq --raw-output '.darwinRevision // "null"' < /run/current-system/darwin-version.json)"
if [[ "$revision" == "null" ]]; then
echo "$0: nix-darwin commit hash is unknown" >&2
exit 1
fi
echo "$revision"
;;
--nixpkgs-revision)
revision="$(jq --raw-output '.nixpkgsRevision // "null"' < /run/current-system/darwin-version.json)"
if [[ "$revision" == "null" ]]; then
echo "$0: Nixpkgs commit hash is unknown" >&2
exit 1
fi
echo "$revision"
;;
--configuration-revision)
revision="$(jq --raw-output '.configurationRevision // "null"' < /run/current-system/darwin-version.json)"
if [[ "$revision" == "null" ]]; then
echo "$0: configuration commit hash is unknown" >&2
exit 1
fi
echo "$revision"
;;
--json)
cat /run/current-system/darwin-version.json
;;
*)
label="$(jq --raw-output '.darwinLabel // "null"' < /run/current-system/darwin-version.json)"
if [[ "$label" == "null" ]]; then
showSyntax
exit 1
fi
echo "$label"
;;
esac

View File

@ -35,4 +35,11 @@ in
inherit (stdenv) shell;
}
./darwin-rebuild.sh;
darwin-version = writeProgram "darwin-version"
{
inherit (stdenv) shell;
path = lib.makeBinPath [ jq ];
}
./darwin-version.sh;
}