base: move some shared configuration to shared

This commit is contained in:
Charlotte Van Petegem 2024-07-18 16:57:22 +02:00
parent 6fe9af56e7
commit fe306085f4
11 changed files with 273 additions and 227 deletions

View file

@ -0,0 +1,65 @@
{ config, lib, pkgs, ... }:
{
imports = [
./nix
./zsh
];
options.chvp = {
cachePrefix = lib.mkOption {
default = "";
example = "/cache";
};
dataPrefix = lib.mkOption {
default = "";
example = "/data";
};
stateVersion = lib.mkOption {
example = "20.09";
};
homeStateVersion = lib.mkOption {
default = config.chvp.stateVersion;
};
systemStateVersion = lib.mkOption {
default = config.chvp.stateVersion;
};
username = lib.mkOption {
default = "charlotte";
example = "charlotte.vanpetegem";
};
};
config =
let
username = config.chvp.username;
in
{
environment.systemPackages = with pkgs; [
coreutils
git
htop
moreutils
ncdu
ripgrep
unzip
zip
];
home-manager = {
useGlobalPkgs = true;
users = {
"${username}" = { ... }: {
home.stateVersion = config.chvp.homeStateVersion;
};
};
};
system.stateVersion = config.chvp.systemStateVersion;
users.users.${username} = {
description = "Charlotte Van Petegem";
shell = pkgs.zsh;
};
};
}

View file

@ -0,0 +1,73 @@
{ config, lib, pkgs, ... }:
let
baseDirenv = {
programs.direnv = {
enable = true;
enableZshIntegration = true;
nix-direnv.enable = true;
config.global.load_dotenv = true;
};
};
baseNixIndex = {
programs.command-not-found.enable = false;
programs.nix-index = {
enable = true;
package = config.programs.nix-index.package;
};
};
username = config.chvp.username;
in
{
options.chvp.base.nix = {
enableDirenv = lib.mkOption {
default = true;
example = false;
};
slowGc = lib.mkOption {
default = false;
example = true;
};
# Used in /flake.nix, since we have to use it at nixpkgs import time
unfreePackages = lib.mkOption {
default = [ ];
example = [ "teams" ];
};
};
config = {
nix = {
gc = {
automatic = true;
options = "--delete-older-than 7d";
};
settings = {
auto-optimise-store = true;
substituters = [
"https://cache.nixos.org"
"https://accentor.cachix.org"
"https://chvp.cachix.org"
"https://lanzaboote.cachix.org"
"https://nix-community.cachix.org"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"accentor.cachix.org-1:QP+oJwzmeq5Fsyp4Vk501UgUSbl5VIna/ard/XOePH8="
"chvp.cachix.org-1:eIG26KkeA+R3tCpvmaayA9i3KVVL06G+qB5ci4dHBT4="
"lanzaboote.cachix.org-1:Nt9//zGmqkg1k5iu+B3bkj3OmHKjSw9pvf3faffLLNk="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
trusted-users = [ username ];
};
extraOptions = lib.mkIf config.chvp.base.nix.enableDirenv ''
keep-outputs = true
keep-derivations = true
'';
};
home-manager.users.${username} = { ... }:
lib.recursiveUpdate
(lib.optionalAttrs config.chvp.base.nix.enableDirenv baseDirenv)
baseNixIndex;
};
}

View file

@ -0,0 +1,75 @@
{ config, lib, pkgs, ... }:
let
username = config.chvp.username;
base = (home: {
home.packages = [ pkgs.autojump ];
programs.zsh = {
enable = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
autocd = true;
dotDir = ".config/zsh";
history = {
expireDuplicatesFirst = true;
path = "${config.chvp.cachePrefix}${home}/.local/share/zsh/history";
};
initExtra = ''
nshell() {
local -a drvs
for attr in "$@"; do
drvs+=(nixpkgs#$attr)
done
local paths="$(nix build --no-link --print-out-paths $drvs)"
for p in $paths; do
export PATH="$p/bin:$PATH"
done
}
nrun() {
local drv="$1"
shift 1
nix run nixpkgs#$drv $@
}
nsrun() {
local drv="$1"
shift 1
nix shell nixpkgs#$drv -c $@
}
'';
shellAliases = {
gupd = "gfa && gprom";
};
sessionVariables = { DEFAULT_USER = "charlotte"; };
oh-my-zsh = {
enable = true;
plugins = [
"autojump"
"common-aliases"
"extract"
"history-substring-search"
"git"
"systemd"
"tmux"
];
theme = "robbyrussell";
};
};
});
in
{
options.chvp.base.zsh.usersToConfigure = lib.mkOption {
default = [ username ];
};
config = {
programs.zsh.enable = true;
} // {
home-manager.users = builtins.foldl' (a: b: a // b) { } (
builtins.map
(name: { "${name}" = { ... }: (base config.users.users.${name}.home); })
config.chvp.base.zsh.usersToConfigure
);
};
}

View file

@ -1 +1,7 @@
{ ... }: { }
{ ... }:
{
imports = [
./base
];
}