2020-09-28 14:09:03 +03:00
|
|
|
# Define an operator user for convenient interactive access to nix-bitcoin
|
|
|
|
# features and services.
|
|
|
|
#
|
|
|
|
# When using nix-bitcoin as part of a larger system config, set
|
|
|
|
# `nix-bitcoin.operator.name` to your main user name.
|
|
|
|
|
2021-09-13 14:40:46 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
2020-09-28 14:09:03 +03:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
options.nix-bitcoin.operator = {
|
|
|
|
enable = mkEnableOption "operator user";
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "operator";
|
|
|
|
description = "User name.";
|
|
|
|
};
|
|
|
|
groups = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [];
|
|
|
|
description = "Extra groups.";
|
|
|
|
};
|
2021-01-31 01:08:43 +03:00
|
|
|
allowRunAsUsers = mkOption {
|
2020-09-28 14:09:03 +03:00
|
|
|
type = with types; listOf str;
|
|
|
|
default = [];
|
|
|
|
description = "Users as which the operator is allowed to run commands.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-09-13 14:40:47 +03:00
|
|
|
cfg = config.nix-bitcoin.operator;
|
|
|
|
in {
|
|
|
|
inherit options;
|
|
|
|
|
2020-09-28 14:09:03 +03:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
users.users.${cfg.name} = {
|
|
|
|
isNormalUser = true;
|
|
|
|
extraGroups = [
|
|
|
|
"systemd-journal"
|
|
|
|
"proc" # Enable full /proc access and systemd-status
|
|
|
|
] ++ cfg.groups;
|
|
|
|
};
|
|
|
|
|
2021-01-31 01:08:43 +03:00
|
|
|
security = mkIf (cfg.allowRunAsUsers != []) {
|
|
|
|
# Use doas instead of sudo if enabled
|
|
|
|
doas.extraConfig = mkIf config.security.doas.enable ''
|
|
|
|
${lib.concatMapStrings (user: "permit nopass ${cfg.name} as ${user}\n") cfg.allowRunAsUsers}
|
|
|
|
'';
|
|
|
|
sudo.extraConfig = mkIf (!config.security.doas.enable) ''
|
|
|
|
${cfg.name} ALL=(${builtins.concatStringsSep "," cfg.allowRunAsUsers}) NOPASSWD: ALL
|
|
|
|
'';
|
|
|
|
};
|
2020-09-28 14:09:03 +03:00
|
|
|
};
|
|
|
|
}
|