141 lines
4.6 KiB
Nix
141 lines
4.6 KiB
Nix
{ pkgs, inputs, config, lib, ... }:
|
|
let
|
|
hostname = config.networking.hostName;
|
|
pubKeys = lib.filesystem.listFilesRecursive (../keys);
|
|
sopsHashedPasswordFile = lib.optionalString (lib.hasAttr "sops-nix" inputs) config.sops.secrets."passwords/sam".path;
|
|
secretsDirectory = builtins.toString inputs.nix-secrets;
|
|
secretsFile = "${secretsDirectory}/secrets.yaml";
|
|
username = "sam";
|
|
in
|
|
{
|
|
users.users.${username} = {
|
|
isNormalUser = true;
|
|
shell = pkgs.zsh; # default shell
|
|
hashedPasswordFile = sopsHashedPasswordFile;
|
|
openssh.authorizedKeys.keys = lib.lists.forEach pubKeys (key: builtins.readFile key);
|
|
|
|
extraGroups = [
|
|
"wheel"
|
|
"networkmanager"
|
|
];
|
|
|
|
};
|
|
|
|
sops.secrets = {
|
|
"passwords/${username}" = {
|
|
sopsFile = "${secretsFile}";
|
|
neededForUsers = true;
|
|
};
|
|
"ssh_keys/${username}/id_ed25519" = {
|
|
path = "/home/${username}/.ssh/id_ed25519";
|
|
mode = "0600";
|
|
owner = "${username}";
|
|
};
|
|
"ssh_keys/${username}/id_ed25519.pub" = {
|
|
path = "/home/${username}/.ssh/id_ed25519.pub";
|
|
mode = "0644";
|
|
owner = "${username}";
|
|
};
|
|
"github-access-token" = {
|
|
mode = "0655";
|
|
};
|
|
"software/postgres/btc_models/password" = { };
|
|
"software/postgres/btc_models/ip" = { };
|
|
"software/postgres/btc_models/username" = { };
|
|
"software/zotero/username" = { };
|
|
"software/zotero/password" = { };
|
|
"software/zotero/guid" = { };
|
|
};
|
|
|
|
# Setup software specific templates for user
|
|
# Should be part of home-manager - waiting for templates functionality
|
|
# See here https://github.com/Mic92/sops-nix/issues/423 and here https://github.com/Mic92/sops-nix/issues/498
|
|
# TODO: migrate db_ui connection to home-manager when issue 423 and 498 are resolved in github:Mic92/sops-nix
|
|
sops.templates."dbui_connections.json" = {
|
|
path = "/home/${username}/.local/share/db_ui/connections.json";
|
|
owner = "${username}";
|
|
mode = "0600";
|
|
content = ''
|
|
[
|
|
{
|
|
"url": "postgresql://${config.sops.placeholder."software/postgres/btc_models/username"}:${config.sops.placeholder."software/postgres/btc_models/password"}@${config.sops.placeholder."software/postgres/btc_models/ip"}/btc_models",
|
|
"name": "btc_models"
|
|
},
|
|
{
|
|
"url": "postgresql://${config.sops.placeholder."software/postgres/btc_models/username"}:${config.sops.placeholder."software/postgres/btc_models/password"}@${config.sops.placeholder."software/postgres/btc_models/ip"}/dev_btc_models",
|
|
"name": "dev_btc_models"
|
|
}
|
|
]
|
|
'';
|
|
};
|
|
|
|
sops.templates."dbt_profiles.yml" = {
|
|
path = "/home/${username}/.config/dbt/profiles.yml";
|
|
owner = "${username}";
|
|
mode = "0600";
|
|
content = ''
|
|
bitcoin:
|
|
target: dev
|
|
outputs:
|
|
dev:
|
|
dbname: dev_btc_models
|
|
host: ${config.sops.placeholder."software/postgres/btc_models/ip"}
|
|
pass: '${config.sops.placeholder."software/postgres/btc_models/password"}'
|
|
port: 5432
|
|
schema: models
|
|
threads: 6
|
|
type: postgres
|
|
user: ${config.sops.placeholder."software/postgres/btc_models/username"}
|
|
prod:
|
|
dbname: btc_models
|
|
host: ${config.sops.placeholder."software/postgres/btc_models/ip"}
|
|
pass: '${config.sops.placeholder."software/postgres/btc_models/password"}'
|
|
port: 5432
|
|
schema: models
|
|
threads: 6
|
|
type: postgres
|
|
user: ${config.sops.placeholder."software/postgres/btc_models/username"}
|
|
|
|
'';
|
|
};
|
|
|
|
nix = {
|
|
extraOptions = ''
|
|
experimental-features = nix-command flakes
|
|
!include ${config.sops.secrets.github-access-token.path}
|
|
'';
|
|
};
|
|
# The containing folders are created as root and if this is the first entry when writing files,
|
|
# the ownership is busted and home-manager can't target because it can't write to these dirs...
|
|
# FIXME: We might not need this depending on how https://github.com/Mic92/sops-nix/issues/381 is fixed
|
|
system.activationScripts.sopsSetOwnwership =
|
|
let
|
|
sshFolder = "/home/${username}/.ssh";
|
|
user = config.users.users.${username}.name;
|
|
group = config.users.users.${username}.group;
|
|
in
|
|
''
|
|
mkdir -p ${sshFolder} || true
|
|
chown -R ${user}:${group} /home/${username}/.ssh
|
|
'';
|
|
|
|
environment.persistence."/persist" = {
|
|
directories = [
|
|
"/home/${username}"
|
|
];
|
|
};
|
|
|
|
programs.zsh.enable = true;
|
|
|
|
home-manager = {
|
|
extraSpecialArgs = { inherit inputs; };
|
|
users = {
|
|
${username} = import ../../../../home/${hostname}.nix;
|
|
};
|
|
};
|
|
|
|
environment.systemPackages = [
|
|
#inputs.sqlfmt.packages.x86_64-linux.sqlfmt
|
|
];
|
|
}
|