-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·155 lines (127 loc) · 4.56 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·155 lines (127 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
# my-dotfiles | Copyright (C) 2025 eth-p
# Repository: https://github.com/eth-p/my-dotfiles
# ==============================================================================
set -euo pipefail
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
REPO_DIR="$(pwd)"
LIB_DIR="${REPO_DIR}/management/lib"
# ==============================================================================
source "management/lib/nix.sh"
source "management/lib/files.sh"
source "management/lib/print.sh"
source "management/lib/system.sh"
# ------------------------------------------------------------------------------
show_section "Installing Nix package manager"
# ------------------------------------------------------------------------------
nix_install_script_url="https://nixos.org/nix/install"
nix_conf_file="/etc/nix/nix.conf"
nix_experimental_features="experimental-features = nix-command flakes"
if nix_installed &>/dev/null; then
show_notice "nix is already installed"
else
tempdir="$(mktemp -d)"
_cleanup_file "$tempdir"
curl -sSfL "$nix_install_script_url" -o "$tempdir/nix-install.sh"
"$tempdir/nix-install.sh" --daemon
PATH="$(nix_install_dir):${PATH}"
fi
# Ensure nix-command and flakes are enabled.
if grep -Fx "$nix_experimental_features" "$nix_conf_file" &>/dev/null; then
show_notice "nix is already configured"
else
show_notice "nix experimental features need enabling"
sudo mkdir -p "$(dirname -- "$nix_conf_file")"
sudo bash -c "$(printf 'printf "%%s\n" %q >>%q' "$nix_experimental_features" "$nix_conf_file")"
if is_steamos; then
sudo bash -c "$(printf 'printf "%%s\n" %q >>%q' "$nix_conf_file" "/etc/atomic-update.conf.d/nix.conf")"
fi
fi
# ------------------------------------------------------------------------------
show_section "Bootstrapping system configuration"
# ------------------------------------------------------------------------------
BOOTSTRAPPED_FLAKE_DIR="$(mydotfiles_configdir)"
create_and_overwrite "${BOOTSTRAPPED_FLAKE_DIR}/flake.nix" <<EOF
# -- DO NOT EDIT --
# Autogenerated bootstrap.
{
description = "Generated bootstrap for my-dotfiles.";
inputs = {
my-dotfiles = {
url = "git+file:${REPO_DIR}";
};
};
outputs = { self, my-dotfiles, ... }:
let
profile = builtins.fromJSON (builtins.readFile ./profile.json);
bootstrap = {
system = "$(nix_platform)";
username = "$(user_username)";
homeDirectory = "$(user_homedir)";
repoDirectory = "${REPO_DIR}";
bootstrapDirectory = "${BOOTSTRAPPED_FLAKE_DIR}";
};
in {
homeConfigurations."\${bootstrap.username}" = my-dotfiles.lib.home.mkHomeConfiguration {
inherit profile;
system = bootstrap.system;
modules = [
({pkgs, ...}: {
home.username = bootstrap.username;
home.homeDirectory = bootstrap.homeDirectory;
home.stateVersion = "24.11";
# Have home-manager install itself.
home.packages = [
pkgs.home-manager
(import (my-dotfiles + "/management/package.nix") {
inherit bootstrap pkgs;
})
];
})
./config.nix
];
};
};
}
EOF
create_if_missing "${BOOTSTRAPPED_FLAKE_DIR}/profile.json" <<EOF
"minimal"
EOF
create_if_missing "${BOOTSTRAPPED_FLAKE_DIR}/config.nix" <<EOF
{ lib, pkgs, config, ... }:
{
# Hide home-manager news.
news.display = "silent";
# Fix locale errors when using programs installed through Nix.
# home.language.base = "C.UTF-8";
# home.sessionVariables.LANG = "C.UTF-8";
# --------------------------------------------------------------------------
# Extra packages:
# --------------------------------------------------------------------------
home.packages = [
# pkgs.nixfmt-rfc-style
];
# --------------------------------------------------------------------------
# Global configuration:
# --------------------------------------------------------------------------
my-dotfiles.global = {
# nerdfonts = true;
};
# --------------------------------------------------------------------------
# Program configuration:
# --------------------------------------------------------------------------
# my-dotfiles.oh-my-posh = {
# enable = true;
# };
programs.git = {
settings = {
user.name = "$(user_username)";
user.email = "$(user_username)@$(system_hostname)";
}
};
}
EOF
# ------------------------------------------------------------------------------
show_section "Applying configuration"
# ------------------------------------------------------------------------------
source "${REPO_DIR}/management/bin/my-dotfiles-apply"