This repository contains my system configuration.
The main objective is to have a portable and reproducible system in order to for example bootstrap a new system in a quick and automated way.
The ideal is to share packages and configuration across different operating systems.
At the moment I only use a macOS
system but I am prepared for the day I will switch to nixOS
Tools:
nix
as a package manager- In particular, an experimental feature called
flake
to achieve complete reproducibility
- In particular, an experimental feature called
home-manager
to configure packages and dotfilesnix-darwin
to configure macOS systems (e.g. it has a greatbrew
module)
This file (readme.org
) is used to generate (the correct term is tangle
) my flake.nix
file, where I specify the inputs and outputs of my system configuration.
The tangled flake.nix
file imports other .nix
files (e.g. darwin/default.nix
).
This file is better viewed in HTML format here or through org-mode
(clone the repo and open in emacs
).
You can visit my blog at the same website.
# NOTE: this file is tangled from readme.org
# DO NOT edit by hand
{
description = "Luca Cambiaghi's darwin configuration";
<<inputs>>
outputs = inputs@{ self, nixpkgs, darwin, home-manager, flake-utils, ... }:
let
<<nixpkgs-config>>
<<home-manager-config>>
<<nix-darwin-config>>
in {
darwinConfigurations = rec {
<<macbook-pro-m1>>
};
<<cloud-vm>>
};
}
inputs = {
# Package sets
nixpkgs-unstable.url = github:NixOS/nixpkgs/nixpkgs-unstable;
nixpkgs-master.url = "github:nixos/nixpkgs/master";
nixpkgs-stable.url = github:NixOS/nixpkgs/nixpkgs-21.11-darwin;
nixos-stable.url = github:NixOS/nixpkgs/nixos-21.11;
# Environment/system management
darwin.url = github:LnL7/nix-darwin;
darwin.inputs.nixpkgs.follows = "nixpkgs-unstable";
home-manager.url = github:nix-community/home-manager;
home-manager.inputs.nixpkgs.follows = "nixpkgs-unstable";
};
nixpkgsConfig = {
config = { allowUnfree = true; allowUnsupportedSystem = true;};
};
homeManagerCommonConfig = {
imports = with self.homeManagerModules; [
./home
{ home.stateVersion = "22.05"; }
# configs.git.aliases
# configs.starship.symbols
# programs.kitty.extras
];
};
nixDarwinCommonModules = [
# Main `nix-darwin` config
./darwin
# `home-manager` module
home-manager.darwinModules.home-manager
(
{ config, lib, pkgs, ... }:
let
primaryUser = "cambiaghiluca";
in
{
nixpkgs = nixpkgsConfig;
# `home-manager` config
users.users.${primaryUser}.home = "/Users/${primaryUser}";
home-manager.useGlobalPkgs = true;
home-manager.users.${primaryUser} = homeManagerCommonConfig;
}
)
];
macbookpro-m1 = darwin.lib.darwinSystem {
system = "aarch64-darwin";
modules = nixDarwinCommonModules ++ [
{
# users.primaryUser = "cambiaghiluca";
networking = {
knownNetworkServices = ["Wi-Fi" "Bluetooth PAN" "Thunderbolt Bridge"];
# hostName = "luca-macbookpro";
# computerName = "luca-macbookpro";
# localHostName = "luca-macbookpro";
};
}
];
specialArgs = { inherit inputs nixpkgs; };
};
Build and activate with nix build .#cloudVM.activationPackage; ./result/activate
cloudVM = home-manager.lib.homeManagerConfiguration {
system = "x86_64-linux";
homeDirectory = "/home/luca";
username = "luca";
configuration = {
imports = [ homeManagerCommonConfig ];
nixpkgs = nixpkgsConfig;
};
};
thanks https://github.com/kclejeune/system
# 1.
if [[ $(uname -s) == 'Darwin' ]]; then
sh <(curl -L https://nixos.org/nix/install) --daemon --darwin-use-unencrypted-nix-store-volume
else
sh <(curl -L https://nixos.org/nix/install) --daemon
fi
# 2.
git clone [email protected]:lccambiaghi/nixpkgs.git ~/git/nixpkgs
# 3.
cd ~/git/nixpkgs && nix --extra-experimental-features "nix-command flakes" build .#darwinConfigurations.macbookpro-m1.system && ./result/sw/bin/darwin-rebuild switch --flake .#macbookpro-m1
Some files to backup:
sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.bak
sudo mv /etc/shells /etc/shells.bak
Misc TODOs:
- To use touch id for sudo (e.g. every time you reload configuration) follow this link: https://www.imore.com/how-use-sudo-your-mac-touch-id (open file with
sudo vim
) - Install FontAwesome
- Configure Amethyst shortcuts (throw windows) and turn off “focus follows mouse”
- Configure macOS ctrl to be caps
darwin-rebuild build --flake .#luca-macbookpro
# nix build ".#darwinConfigurations.luca-macbookpro.system"
darwin-rebuild switch --flake .#luca-macbookpro
# ./result/sw/bin/darwin-rebuild switch --flake .#luca-macbookpro
nix flake update --update-input nixpkgs
Reference: https://sixty-north.com/blog/pyenv-apple-silicon.html
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
alias brew86="arch -x86_64 /usr/local/bin/brew"
# brew86 install openssl readline sqlite3 xz zlib [email protected]
brew86 install [email protected]