diff --git a/disko b/disko index cd8fc2e..4ef771a 100755 --- a/disko +++ b/disko @@ -10,6 +10,10 @@ declare disko_config mode=mount nix_args=() +# DISKO_VERSION is set by the wrapper in package.nix +DISKO_VERSION="${DISKO_VERSION:="unknown! This is a bug, please report it!"}" +onlyPrintVersion=false + showUsage() { cat < /dev/null; then nom-build "$@" diff --git a/flake.nix b/flake.nix index e9e57b7..ae51fc5 100644 --- a/flake.nix +++ b/flake.nix @@ -8,13 +8,17 @@ outputs = { self, nixpkgs, ... }: let + lib = nixpkgs.lib; supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" "riscv64-linux" ]; - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + forAllSystems = lib.genAttrs supportedSystems; + + versionInfo = import ./version.nix; + version = versionInfo.version + (lib.optionalString (!versionInfo.released) "-dirty"); in { nixosModules.default = self.nixosModules.disko; # convention @@ -27,12 +31,14 @@ pkgs = nixpkgs.legacyPackages.${system}; in { - disko = pkgs.callPackage ./package.nix { }; + disko = pkgs.callPackage ./package.nix { diskoVersion = version; }; # alias to make `nix run` more convenient disko-install = self.packages.${system}.disko.overrideAttrs (_old: { name = "disko-install"; }); default = self.packages.${system}.disko; + + create-release = pkgs.callPackage ./scripts/create-release.nix { }; } // pkgs.lib.optionalAttrs (!pkgs.buildPlatform.isRiscV64) { disko-doc = pkgs.callPackage ./doc.nix { }; }); @@ -42,7 +48,7 @@ let pkgs = nixpkgs.legacyPackages.${system}; # FIXME: aarch64-linux seems to hang on boot - nixosTests = nixpkgs.lib.optionalAttrs pkgs.hostPlatform.isx86_64 (import ./tests { + nixosTests = lib.optionalAttrs pkgs.hostPlatform.isx86_64 (import ./tests { inherit pkgs; makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix"); eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix"); @@ -50,6 +56,7 @@ disko-install = pkgs.callPackage ./tests/disko-install { inherit self; + diskoVersion = version; }; shellcheck = pkgs.runCommand "shellcheck" { nativeBuildInputs = [ pkgs.shellcheck ]; } '' @@ -59,13 +66,13 @@ ''; in # FIXME: aarch64-linux seems to hang on boot - nixpkgs.lib.optionalAttrs pkgs.hostPlatform.isx86_64 (nixosTests // { inherit disko-install; }) // + lib.optionalAttrs pkgs.hostPlatform.isx86_64 (nixosTests // { inherit disko-install; }) // pkgs.lib.optionalAttrs (!pkgs.buildPlatform.isRiscV64 && !pkgs.hostPlatform.isx86_32) { inherit shellcheck; inherit (self.packages.${system}) disko-doc; }); - nixosConfigurations.testmachine = nixpkgs.lib.nixosSystem { + nixosConfigurations.testmachine = lib.nixosSystem { system = "x86_64-linux"; modules = [ ./tests/disko-install/configuration.nix diff --git a/package.nix b/package.nix index 15db63d..3464854 100644 --- a/package.nix +++ b/package.nix @@ -1,4 +1,4 @@ -{ stdenvNoCC, makeWrapper, lib, path, nix, coreutils, nixos-install-tools, binlore }: +{ stdenvNoCC, makeWrapper, lib, path, nix, coreutils, nixos-install-tools, binlore, diskoVersion }: let self = stdenvNoCC.mkDerivation (finalAttrs: { @@ -15,6 +15,7 @@ let sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i" chmod 755 "$out/bin/$i" wrapProgram "$out/bin/$i" \ + --set DISKO_VERSION "${diskoVersion}" \ --prefix PATH : ${lib.makeBinPath [ nix coreutils nixos-install-tools ]} \ --prefix NIX_PATH : "nixpkgs=${path}" done diff --git a/scripts/create-release.nix b/scripts/create-release.nix new file mode 100644 index 0000000..42f3319 --- /dev/null +++ b/scripts/create-release.nix @@ -0,0 +1,18 @@ +{ + lib, + writeShellApplication, + bash, + coreutils, + git, + nix-fast-build, +}: +writeShellApplication { + name = "create-release"; + runtimeInputs = [ + bash + git + coreutils + nix-fast-build + ]; + text = lib.readFile ./create-release.sh; +} diff --git a/scripts/create-release.sh b/scripts/create-release.sh new file mode 100755 index 0000000..32cdb12 --- /dev/null +++ b/scripts/create-release.sh @@ -0,0 +1,56 @@ +# Don't run directly! Instead, use +# nix run .#create-release + +version=${1:-} +if [[ -z "$version" ]]; then + echo "USAGE: nix run .#create-release -- " >&2 + exit 1 +fi + +# Check if we're running from the root of the repository +if [[ ! -f "flake.nix" || ! -f "version.nix" ]]; then + echo "This script must be run from the root of the repository" >&2 + exit 1 +fi + +# Check if the version matches the semver pattern (without suffixes) +semver_regex="^([0-9]+)\.([0-9]+)\.([0-9]+)$" +if [[ ! "$version" =~ $semver_regex ]]; then + echo "Version must match the semver pattern (e.g., 1.0.0, 2.3.4)" >&2 + exit 1 +fi + +if [[ "$(git symbolic-ref --short HEAD)" != "master" ]]; then + echo "must be on master branch" >&2 + exit 1 +fi + +# Ensure there are no uncommitted or unpushed changes +uncommited_changes=$(git diff --compact-summary) +if [[ -n "$uncommited_changes" ]]; then + echo -e "There are uncommited changes, exiting:\n${uncommited_changes}" >&2 + exit 1 +fi +git pull git@github.com:nix-community/disko master +unpushed_commits=$(git log --format=oneline origin/master..master) +if [[ "$unpushed_commits" != "" ]]; then + echo -e "\nThere are unpushed changes, exiting:\n$unpushed_commits" >&2 + exit 1 +fi + +# Run all tests to ensure we don't release a broken version +# Two workers are safe on systems with at least 16GB of RAM +nix-fast-build --no-link -j 2 --eval-workers 2 --flake .#checks + +# Update the version file +echo "{ version = \"$version\"; released = true; }" > version.nix + +# Commit and tag the release +git commit -am "release: v$version" +git tag -a "v$version" -m "release: v$version" + +# a revsion suffix when run from the tagged release commit +echo "{ version = \"$version\"; released = false; }" > version.nix +git commit -am "release: reset released flag" + +echo "now run 'git push --tags origin master'" diff --git a/tests/disko-install/default.nix b/tests/disko-install/default.nix index be04878..e9a2ed4 100644 --- a/tests/disko-install/default.nix +++ b/tests/disko-install/default.nix @@ -1,6 +1,6 @@ -{ pkgs ? import { }, self }: +{ pkgs ? import { }, self, diskoVersion }: let - disko = pkgs.callPackage ../../package.nix { }; + disko = pkgs.callPackage ../../package.nix { inherit diskoVersion; }; dependencies = [ self.nixosConfigurations.testmachine.pkgs.stdenv.drvPath diff --git a/version.nix b/version.nix new file mode 100644 index 0000000..6cc49f8 --- /dev/null +++ b/version.nix @@ -0,0 +1 @@ +{ version = "1.8.0"; released = false; }