Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nixpkgs input #6

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions flake.lock

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

143 changes: 75 additions & 68 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,88 @@
[Documentation](https://garnix.io/docs/modules/user) - [Source](https://github.com/garnix-io/user-module).
'';

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";

outputs =
{ self
, nixpkgs
,
}:
let
lib = nixpkgs.lib;

userSubmodule.options = {
user = lib.mkOption
{
type = lib.types.nonEmptyStr;
description = "The Linux username.";
example = "alice";
} // { name = "user name"; };
{ self }:
{
garnixModules.default =
{
pkgs,
lib,
config,
...
}:
let
userSubmodule.options = {
user =
lib.mkOption {
type = lib.types.nonEmptyStr;
description = "The Linux username.";
example = "alice";
}
// {
name = "user name";
};

groups = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "The groups the user belongs to.";
example = [ "wheel" ];
default = [ ];
};
groups = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "The groups the user belongs to.";
example = [ "wheel" ];
default = [ ];
};

shell = lib.mkOption {
type = lib.types.enum [ "bash" "zsh" "fish" ];
default = "bash";
description = "The users login shell.";
};
shell = lib.mkOption {
type = lib.types.enum [
"bash"
"zsh"
"fish"
];
default = "bash";
description = "The users login shell.";
};

authorizedSshKeys = lib.mkOption
{
type = lib.types.listOf lib.types.nonEmptyStr;
description =
''The public SSH keys that can be used to log in as this user. (Note that you must
use the IP address rather than domain for SSH.)'';
} // { name = "SSH keys"; };
};
in
{
garnixModules.default = { pkgs, config, ... }: {
options = {
user = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule userSubmodule);
description = "An attrset of users.";
authorizedSshKeys =
lib.mkOption {
type = lib.types.listOf lib.types.nonEmptyStr;
description = ''
The public SSH keys that can be used to log in as this user. (Note that you must
use the IP address rather than domain for SSH.)'';
}
// {
name = "SSH keys";
};
};
in
{
options = {
user = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule userSubmodule);
description = "An attrset of users.";
};
};
};

config =
{
nixosConfigurations.default =
builtins.attrValues (builtins.mapAttrs
(name: projectConfig: {
users.users.${projectConfig.user} = {
extraGroups = projectConfig.groups;
isNormalUser = true;
shell = pkgs.${projectConfig.shell};
openssh.authorizedKeys.keys = projectConfig.authorizedSshKeys;
};
programs.zsh.enable = projectConfig.shell == "zsh";
programs.fish.enable = projectConfig.shell == "fish";
services.openssh = {
enable = true;
settings = {
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
AuthenticationMethods = "publickey";
PermitRootLogin = "prohibit-password";
};
config = {
nixosConfigurations.default = builtins.attrValues (
builtins.mapAttrs (name: projectConfig: {
users.users.${projectConfig.user} = {
extraGroups = projectConfig.groups;
isNormalUser = true;
shell = pkgs.${projectConfig.shell};
openssh.authorizedKeys.keys = projectConfig.authorizedSshKeys;
};
programs.zsh.enable = projectConfig.shell == "zsh";
programs.fish.enable = projectConfig.shell == "fish";
services.openssh = {
enable = true;
settings = {
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
AuthenticationMethods = "publickey";
PermitRootLogin = "prohibit-password";
};
})
config.user);
};
}) config.user
);
};
};
};
};
}