Skip to content

Commit

Permalink
Merge pull request #11 from feel-co/no-extra-special-args
Browse files Browse the repository at this point in the history
modules: rename `hjem.extraSpecialArgs` to `hjem.specialArgs`
  • Loading branch information
eclairevoyant authored Jan 21, 2025
2 parents 2979f66 + e392ffd commit 984e753
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/vm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ jobs:
matrix:
system:
- x86_64-linux
- aarch64-linux
test:
- hjem-basic
- hjem-special-args

runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
};
in {
hjem-basic = import ./tests/basic.nix checkArgs;
hjem-special-args = import ./tests/special-args.nix checkArgs;
});

formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);
Expand Down
5 changes: 3 additions & 2 deletions modules/common.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# The common module that contains Hjem's per-user options. To ensure Hjem remains
# somewhat compliant with cross-platform paradigms (e.g. NixOS or Darwin) distro
# specific options, such as packages, must be avoided here.
# somewhat compliant with cross-platform paradigms (e.g. NixOS or Darwin.) Platform
# specific options such as nixpkgs module system or nix-darwin module system should
# be avoided here.
{
config,
pkgs,
Expand Down
8 changes: 6 additions & 2 deletions modules/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
hjemModule = submoduleWith {
description = "Hjem NixOS module";
class = "hjem";
specialArgs = {inherit pkgs lib;} // cfg.extraSpecialArgs;
specialArgs = {inherit pkgs lib;} // cfg.specialArgs;
modules = concatLists [
[
({name, ...}: {
Expand All @@ -41,6 +41,10 @@ in {
# namespace to occupy. Added 2024-12-27, remove 2025-01-27 to allow
# sufficient time to migrate.
(lib.mkRenamedOptionModule ["homes"] ["hjem" "users"])

# 'extraSpecialArgs' is confusing and obscure. 'hjem.specialArgs' better
# describes what the option is really for.
(lib.mkRenamedOptionModule ["hjem" "extraSpecialArgs"] ["hjem" "specialArgs"])
];

options.hjem = {
Expand Down Expand Up @@ -72,7 +76,7 @@ in {
'';
};

extraSpecialArgs = mkOption {
specialArgs = mkOption {
type = attrs;
default = {};
example = literalExpression "{ inherit inputs; }";
Expand Down
2 changes: 1 addition & 1 deletion tests/basic.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let
userHome = "/home/alice";
in
(import ./lib.nix) {
(import ./lib) {
name = "hjem-basic";
nodes = {
node1 = {
Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions tests/special-args.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let
userHome = "/home/alice";
in
(import ./lib) {
name = "hjem-basic";
nodes = {
node1 = {self, ...}: {
imports = [self.nixosModules.hjem];

users.groups.alice = {};
users.users.alice = {
isNormalUser = true;
home = userHome;
password = "";
};

hjem = {
# Things like username, home directory or credentials should not really
# be put into specialArgs, but users do it anyway. Lets test for a very
# basic case of 'username' being passed to specialArgs as a string and
# is consumed in a file later on.
specialArgs = {username = "alice";};
users.alice = {
pkgs,
username,
...
}: {
enable = true;
packages = [pkgs.hello];
files.".config/fooconfig" = {
text = "My username is ${username}";
};
};
};
};
};

testScript = ''
machine.succeed("loginctl enable-linger alice")
machine.wait_until_succeeds("systemctl --user --machine=alice@ is-active systemd-tmpfiles-setup.service")
# Test if the config file is properly generated, and contains the desired string1
machine.succeed("grep alice ~alice/.config/fooconfig")
'';
}

0 comments on commit 984e753

Please sign in to comment.