Skip to content

Commit

Permalink
Merge pull request #13 from jwillikers/update-home-manager
Browse files Browse the repository at this point in the history
Update Home Manager release as part of updating the NixOS release
  • Loading branch information
jwillikers authored Nov 19, 2024
2 parents 8bfb11f + d4e2799 commit a546901
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 13 deletions.
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
"adoc",
"Asciidoctor",
"autofix",
"cachix",
"deadnix",
"direnv",
"envrc",
"ifdef",
"ifndef",
"jsonfmt",
"justfile",
"jwillikers",
"nixfmt",
"nixos",
"nixpkgs",
"numtide",
"nushell",
"ostree",
"reviewdog",
"treefmt"
"statix",
"taplo",
"treefmt",
"webp",
"yamlfmt"
],
"files.watcherExclude": {
".direnv/**": true,
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif::[]
:Nix: https://nixos.org/[Nix]
:nix-direnv: https://github.com/nix-community/nix-direnv[nix-direnv]

Scripts to automatically update a few Nix-related things, like the version of `nix-direnv` in `.envrc` files and the NixOS release in of the `nixpkgs` flake input.
Scripts to automatically update a few Nix-related things, like the version of `nix-direnv` in `.envrc` files and the NixOS release in the `nixpkgs` and `home-manager` flake inputs.

== Usage

Expand Down
7 changes: 2 additions & 5 deletions packages/update-nix-direnv/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
nushell,
stdenvNoCC,
}:
let
pname = "update-nix-direnv";
in
if lib.versionOlder nushell.version "0.99" then
throw "${pname} is not available for Nushell ${nushell.version}"
throw "update-nix-direnv is not available for Nushell ${nushell.version}"
else
stdenvNoCC.mkDerivation {
inherit pname;
pname = "update-nix-direnv";
version = "0.1.0";

src = ./.;
Expand Down
5 changes: 1 addition & 4 deletions packages/update-nixos-release/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
nushell,
stdenvNoCC,
}:
let
pname = "update-nixos-release";
in
if lib.versionOlder nushell.version "0.94" then
throw "${pname} is not available for Nushell ${nushell.version}"
throw "update-nixos-release is not available for Nushell ${nushell.version}"
else
stdenvNoCC.mkDerivation {
pname = "update-nixos-release";
Expand Down
63 changes: 63 additions & 0 deletions packages/update-nixos-release/update-nixos-release-tests.nu
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env nu
use update-nixos-release.nu get_latest_nixos_release
use update-nixos-release.nu update_nixos_release_in_flake
use update-nixos-release.nu update_home_manager_release_in_flake

use std assert

Expand Down Expand Up @@ -82,8 +83,70 @@ def test_update_nixos_release_in_flake [] {
}
}

def test_update_home_manager_release_in_flake [] {
for t in [
[flake release expected];
['
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
flake-utils.url = "github:numtide/flake-utils";
home-manager.url = "github:nix-community/home-manager/release-22.11";
};
outputs = { self, nixpkgs, flake-utils, home-manager, }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [
];
pkgs = import nixpkgs {
inherit system overlays;
};
nativeBuildInputs = with pkgs; [
];
buildInputs = with pkgs; [
];
in
with pkgs;
{
devShells.default = mkShell {
inherit buildInputs nativeBuildInputs;
};
}
);' "24.11" '
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
flake-utils.url = "github:numtide/flake-utils";
home-manager.url = "github:nix-community/home-manager/release-24.11";
};
outputs = { self, nixpkgs, flake-utils, home-manager, }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [
];
pkgs = import nixpkgs {
inherit system overlays;
};
nativeBuildInputs = with pkgs; [
];
buildInputs = with pkgs; [
];
in
with pkgs;
{
devShells.default = mkShell {
inherit buildInputs nativeBuildInputs;
};
}
);']
] {
assert equal ($t.flake | update_home_manager_release_in_flake $t.release) $t.expected
}
}

def main [] [] {
test_get_latest_nixos_release
test_update_nixos_release_in_flake
test_update_home_manager_release_in_flake
echo "All tests passed!"
}
17 changes: 16 additions & 1 deletion packages/update-nixos-release/update-nixos-release.nu
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,25 @@ export def update_nixos_release_in_flake [
)
}

export def update_home_manager_release_in_flake [
release: string # Home Manager release, i.e. 24.05
] [ string -> string ] {
(
$in | str replace --regex "github:nix-community/home-manager/release-[0-9][0-9]\\.[0-9][0-9]"
$"github:nix-community/home-manager/release-($release)"
)
}

def main [
flake_file: string = "flake.nix" # Path to the flake.nix file to update
] {
let release = get_latest_nixos_release (date now)
open $flake_file | update_nixos_release_in_flake $release | $"($in)\n" | save --force $flake_file
(
open $flake_file |
update_nixos_release_in_flake $release |
update_home_manager_release_in_flake $release |
$"($in)\n" |
save --force $flake_file
)
exit 0
}
2 changes: 1 addition & 1 deletion pre-commit-hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
editorconfig-checker.enable = true;
end-of-file-fixer.enable = true;
fix-byte-order-marker.enable = true;
flake-checker.enable = true;
# flake-checker.enable = true;
forbid-new-submodules.enable = true;
# todo Enable lychee when asciidoc is supported.
# See https://github.com/lycheeverse/lychee/issues/291
Expand Down

0 comments on commit a546901

Please sign in to comment.