Skip to content

Commit 006f6a7

Browse files
committed
Parameterized build script
1 parent b0c80c1 commit 006f6a7

File tree

5 files changed

+82
-44
lines changed

5 files changed

+82
-44
lines changed

.config/home-manager/home.nix

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ config, pkgs, ... }:
1+
{ config, userConfig, pkgs, ... }:
22

33
{
44
home.username = builtins.getEnv "USER";
@@ -11,35 +11,24 @@
1111
# You should not change this value, even if you update Home Manager. If you do
1212
# want to update the value, then make sure to first check the Home Manager
1313
# release notes.
14-
home.stateVersion = "23.11"; # Please read the comment before changing.
14+
home.stateVersion = "24.05"; # Please read the comment before changing.
1515

1616
# The home.packages option allows you to install Nix packages into your
1717
# environment.
18-
home.packages = with pkgs; [
19-
asdf-vm
20-
pass
21-
tldr
22-
tree
23-
];
18+
home.packages = map (name: pkgs.${name}) userConfig.nix.packages;
2419

25-
home.file = {
26-
".asdf/lib".source = "${pkgs.asdf-vm}/share/asdf-vm/lib";
27-
".asdf/completions".source = "${pkgs.asdf-vm}/share/asdf-vm/completions";
28-
".asdf/asdf.sh".source = "${pkgs.asdf-vm}/share/asdf-vm/asdf.sh";
29-
};
20+
home.file = userConfig.home.file;
3021

31-
home.sessionVariables = {
32-
DISABLE_MAGIC_FUNCTIONS = "true";
33-
};
22+
home.sessionVariables = userConfig.envs;
3423

3524
# Let Home Manager install and manage itself.
3625
programs.home-manager.enable = true;
3726

3827
# Git
3928
programs.git = {
4029
enable = true;
41-
userName = "arctan95";
42-
userEmail = "[email protected]";
30+
userName = userConfig.git.username;
31+
userEmail = userConfig.git.email;
4332
};
4433

4534
# Zsh
@@ -49,16 +38,16 @@
4938
enableAutosuggestions = true;
5039
syntaxHighlighting.enable = true;
5140
historySubstringSearch.enable = true;
52-
53-
shellAliases = {
54-
hm = "home-manager";
55-
hms = "home-manager switch --impure";
56-
};
41+
shellAliases = userConfig.aliases;
42+
initExtra = ''
43+
. "${pkgs.asdf-vm}/share/asdf-vm/asdf.sh"
44+
. "${pkgs.asdf-vm}/share/asdf-vm/completions/asdf.bash"
45+
'';
5746

5847
oh-my-zsh = {
5948
enable = true;
60-
plugins = [ "asdf" "git" "pass" "z" ];
61-
theme = "bira";
49+
plugins = userConfig.omz.plugins;
50+
theme = userConfig.omz.theme;
6251
};
6352
};
6453
}

.devcontainer/first-run-setup.sh

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ Usage: "$0" [OPTIONS]
1010
Options:
1111
--help Display this help message
1212
--version Display version information
13-
--restore_passwd Sync private passwords into system
14-
--restore_homebrew Restore homebrew softwares into macOS system
15-
--enable_tunnel Enable vscode tunnel for remote development
13+
--restore_passwd (Optional) Sync private passwords into system
14+
--restore_homebrew (Optional) Restore homebrew softwares into macOS system
15+
--enable_tunnel (Optional) Enable vscode tunnel for remote development
16+
--password_store (Optional) Your private password store git repository. Default is 'https://github.com/arctan95/password-store.git'
17+
--repository Your codespaces git repository to clone. Default is 'https://github.com/arctan95/codespaces.git'
18+
--flake_uri Use your Home Manager configuration at flake-uri. Default is 'github:arctan95/codespaces'
1619
"
1720

1821
version="v0.1.0"
1922
restore_homebrew=false
2023
restore_passwd=false
2124
enable_tunnel=false
25+
password_store="https://github.com/arctan95/password-store.git"
26+
repository="https://github.com/arctan95/codespaces.git"
27+
flake_uri="github:arctan95/codespaces"
2228

2329
while [[ "$#" -gt 0 ]]; do
2430
case "$1" in
@@ -32,19 +38,33 @@ while [[ "$#" -gt 0 ]]; do
3238
;;
3339
--restore_homebrew)
3440
restore_homebrew=true
41+
shift
3542
;;
3643
--restore_passwd)
3744
restore_passwd=true
45+
shift
3846
;;
3947
--enable_tunnel)
4048
enable_tunnel=true
49+
shift
50+
;;
51+
--password_store)
52+
password_store="$2"
53+
shift 2
54+
;;
55+
--repository)
56+
repository="$2"
57+
shift 2
58+
;;
59+
--flake_uri)
60+
flake_uri="$2"
61+
shift 2
4162
;;
4263
*)
4364
echo "Unknown option: $1"
4465
exit 1
4566
;;
4667
esac
47-
shift
4868
done
4969

5070
# Get system information
@@ -66,7 +86,7 @@ clone_repo() {
6686
fi
6787
}
6888

69-
clone_repo "https://github.com/arctan95/codespaces.git" "$HOME/.codespaces"
89+
clone_repo "$repository" "$HOME/.codespaces"
7090

7191
# Fix up github codespaces
7292
if [ "${CODESPACES}" = true ]; then
@@ -107,7 +127,7 @@ fi
107127

108128
echo "Installing home-manager and switching into a new generation..."
109129
# Run Home Manager with experimental features
110-
nix run nixpkgs#home-manager -- switch --impure --flake github:arctan95/codespaces
130+
nix run nixpkgs#home-manager -- switch --impure --flake $flake_uri
111131

112132
# Check if it's a macOS system
113133
if [ "$platform" = "Darwin" ]; then
@@ -144,7 +164,8 @@ if [ "$platform" = "Darwin" ]; then
144164
# Restore softwares from brewfile
145165
if [ "$restore_homebrew" = "true" ]; then
146166
echo "Restoring softwares from Brewfile..."
147-
brew bundle install --file="$HOME/.codespaces/.config/homebrew/Brewfile"
167+
ln -s "$HOME/.codespaces/.config/homebrew/Brewfile" "$HOME/.config/homebrew/Brewfile"
168+
brew bundle install --file="$HOME/.config/homebrew/Brewfile"
148169
fi
149170
fi
150171

@@ -157,7 +178,7 @@ fi
157178
# Restore private passwords
158179
if [ "$restore_passwd" = "true" ]; then
159180
echo "Configurating passwords..."
160-
clone_repo "https://github.com/arctan95/password-store.git" "$HOME/.password-store"
181+
clone_repo "$password_store" "$HOME/.password-store"
161182
/bin/bash "$HOME/.password-store/setup.sh"
162183
fi
163184

@@ -168,5 +189,5 @@ fi
168189

169190
echo "Installing asdf plugins and packages..."
170191
# Install asdf plugins and packages from .tool-versions file
171-
mv "$HOME/.codespaces/.tool-versions" "$HOME"
172-
cut -d ' ' -f1 "$HOME/.tool-versions" | xargs -I {} sh -c 'echo "Installing {}..."; asdf plugin add {} && asdf install {}'
192+
ln -s "$HOME/.codespaces/.tool-versions" "$HOME/.tool-versions"
193+
cut -d ' ' -f1 "$HOME/.tool-versions" | xargs -I {} sh -c 'echo "Installing {}..."; asdf plugin add {} && asdf install {}'

.tool-versions

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
java adoptopenjdk-8.0.372+7 adoptopenjdk-17.0.10+7
2-
maven 3.5.4
1+
java adoptopenjdk-17.0.10+7
2+
maven 3.5.4
33
gradle 8.6
44
golang 1.21.6
5-
nodejs 16.14.2 18.19.0
6-
rust 1.75.0
5+
nodejs 18.19.0
6+
rust 1.75.0

config.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[git]
2+
username = "your name"
3+
4+
5+
[omz]
6+
# https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
7+
theme = "robbyrussell"
8+
# https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins
9+
plugins = ["git", "z"]
10+
11+
[envs]
12+
# Keep these envs unchanged!
13+
DISABLE_MAGIC_FUNCTIONS = "true"
14+
HOMEBREW_BUNDLE_FILE = "~/.config/homebrew/Brewfile"
15+
16+
[aliases]
17+
hm = "home-manager"
18+
hms = "home-manager switch --impure"
19+
brewdump = "brew bundle dump --describe --force"
20+
brewup = "brew bundle install"
21+
22+
[home.file]
23+
".ssh/ssh-ed25519.pub" = { text = "your ssh pubic key" }
24+
25+
[nix]
26+
# https://search.nixos.org/packages
27+
packages = ["asdf-vm", "tree", "neofetch"]

flake.nix

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@
1414
outputs = { self, nixpkgs, home-manager, systems, ... }:
1515
let
1616
eachSystem = nixpkgs.lib.genAttrs (import systems);
17-
user = builtins.getEnv "USER";
18-
# specialArgs = {};
17+
userConfig = builtins.fromTOML (builtins.readFile "${builtins.getEnv "HOME"}/.codespaces/config.toml");
18+
specialArgs = {
19+
inherit userConfig;
20+
};
1921
in
2022
{
2123
packages = eachSystem (system: {
2224
homeConfigurations = {
23-
"${user}" = home-manager.lib.homeManagerConfiguration {
25+
"${builtins.getEnv "USER"}" = home-manager.lib.homeManagerConfiguration {
2426
pkgs = nixpkgs.legacyPackages.${system};
25-
2627
# Specify your home configuration modules here, for example,
2728
# the path to your home.nix.
2829
modules = [ .config/home-manager/home.nix ];
2930

3031
# Optionally use extraSpecialArgs
3132
# to pass through arguments to home.nix
32-
# extraSpecialArgs = specialArgs;
33+
extraSpecialArgs = specialArgs;
3334
};
3435
};
3536
});

0 commit comments

Comments
 (0)