Giter Site home page Giter Site logo

nix-config's Introduction

nix-config

Infrastructure as Code (IaC)

After using a shell script to automate my desktop Ubuntu installation from 2011 to 2023, I finally migrated the 2646 lines of code to Ansible, see https://github.com/JakobLichterfeld/infra-playbook

End of 2023 I migrated to Nix.

MainServer (Intel N100)

Installation process

Create a root password using the TTY

sudo su
passwd

From your host, copy the public SSH key to the server

ssh-add ~/.ssh/jakob
ssh-copy-id -i ~/.ssh/jakob root@nixos_installation_ip
ssh root@nixos_installation_ip

Enable Nix Flakes functionality

mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf

Partition and mount the drives using disko (declarative disk partitioning and formatting using nix)

curl https://raw.githubusercontent.com/JakobLichterfeld/nix-config/main/machines/nixos/MainServer/filesystems/disko.nix \
    -o /tmp/disko.nix
nix --experimental-features "nix-command flakes" run github:nix-community/disko \
    -- --mode disko /tmp/disko.nix

Install programs needed for system installation

if ! command -v git; then nix-env -f '<nixpkgs>' -iA git; fi
if ! command -v git-crypt;  then nix-env -f '<nixpkgs>' -iA git-crypt; fi

Clone this repository

mkdir -p /mnt/etc/nixos
git clone https://github.com/JakobLichterfeld/nix-config.git /mnt/etc/nixos

Put the private and GPG key into place (required for secret management)

mkdir -p /mnt/persist/ssh
exit
scp ~/.ssh/id_ed25519_main_server root@nixos_installation_ip:/mnt/persist/ssh/id_ed25519_main_server
scp ~/.ssh/nix-config_local.key.asc root@nixos_installation_ip:/mnt/etc/nixos/nix-config_local.key.asc
ssh nixos@nixos_installation_ip
chmod 700 /mnt/persist/ssh
chmod 600 /mnt/persist/ssh/*

Unlock the git-crypt vault

cd /mnt/etc/nixos
git-crypt unlock nix-config_local.key.asc

Install system and apply configuration

nixos-install \
--root "/mnt" \
--no-root-passwd \
--flake "git+file://${MNT}/etc/nixos#MainServer"

Unmount the filesystems

umount "/mnt/boot/esp"
umount -Rl "/mnt"
cd /
zpool export -a

Reboot

reboot

Update to newest config

sudo su
cd /etc/nixos
git pull
nixos-rebuild switch --flake /etc/nixos#MainServer

MainDev (Mac)

Managed by nix-darwin and home-manager. Impure packages and applications are managed by homebrew and mas.

Installation process

Make sure nix is installed

install nix-darwin

install home-manager

Update dependencies: nix --experimental-features 'nix-command flakes' flake update

build: nix --experimental-features 'nix-command flakes' build .#darwinConfigurations."MainDev".system

apply: darwin-rebuild switch --flake .

as macOS does not allow writing to / write to symlink:

printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf
/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t

apply changes: ./result/sw/bin/darwin-rebuild switch --flake .

Contributing

All contributions are welcome and greatly appreciated!

Disclaimer

The Flake is primarily designed for personal use, so it is subject to frequent modifications and glitches. Use it at your own risk and do not anticipate guidance for its installation on your device.

nix-config's People

Contributors

jakoblichterfeld avatar

Stargazers

 avatar

Watchers

 avatar

nix-config's Issues

bug: smb user creation fails

/nix/var/nix/profiles/system/activate: line 293: /run/current-system/sw/bin/smbpasswd: No such file or directory
Activation script snippet 'samba_user_create' failed (127)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.