Code Monkey home page Code Monkey logo

nix-config's Introduction

Nix configuration

Inspired by Leon Breedt's repo.

Bootstrapping

macOS

  1. Install Nix using the Determinate Systems Nix installer.

  2. Install Homebrew (it's only used to install Casks and Mac App Store apps, its not in the $PATH).

  3. Ensure that the current user is able to clone the private secrets repo before proceeding to the next step, by putting the SSH private key needed to clone the repo into $HOME/.ssh/id_rsa.

  4. Run env FLAKE=<NAME> ./bootstrap. After a successful bootstrap, the hostname will be updated to match the flake.

  5. Whenever you make configuration changes, run ./rebuild. If any files are reported as being in the way, move them out of the way and re-run.

NixOS

TODO: Below instructions are outdated and not adapted for complete flake rewrite.

  1. Download the latest NixOS stable distribution, these instructions were tested with 22.11. Download the minimal distribution, not graphical.

  2. Create a bootable USB.

  3. Boot from the USB device.

  4. Create root and boot partitions and format them with the file system of your choice, use the nixos and swap labels, as our configuration depends on these labels, and mount the file systems in /mnt and /mnt/boot, respectively.

  5. Run nixos-generate-config --root /mnt

  6. Clone this repository to /mnt/etc/nixos/nixos-config:

    nix-shell -p git
    echo https://<USER>:<GITHUB-TOKEN>@github.com > $HOME/.git-credentials
    git clone https://github.com/leonbreedt/nixos-config.git /mnt/etc/nixos/nixos-config
  7. Ensure the root user has the SSH public key for cloning the secret repository referenced by the flake.nix, it should be put in /root/.ssh with appropriate permissions. Run ssh [email protected] at least once, and save the GitHub SSH key (needed to avoid the nixos-install command hanging waiting for user input when cloning the secrets repo).

  8. Run the installer, where <SYSTEM> is the name of the system in flake.nix:

    nixos-install --flake "/mnt/etc/nixos/nixos-config#<SYSTEM>" -v

    You will be prompted for a root password, which you can use after reboot to give the normal user a password to log in if you want to use X11. Only the normal user will be able to SSH in.

  9. Whenever you make changes to the configuration, you can Run env FLAKE=<SYSTEM> ./rebuild in /etc/nixos/nixos-config, where <SYSTEM> is the name of the system in flake.nix. This will run nixos-rebuild in flake mode, and switch to the built configuration afterwards.

WSL

TODO: Below instructions are outdated and not adapted for complete flake rewrite.

  1. Clone this repository on an existing NixOS system, and ensure nativeSystemd is set to false in wsl/default.nix.

  2. Build the latest main branch on an existing NixOS system:

    nix build .#nixosConfigurations.<WSL-CONFIG-NAME>.config.system.build.installer
  3. This will produce a tarball in ./result/tarball/nixos-wsl-installer.tar.gz, copy it somewhere (e.g USB).

  4. Import the NixOS distribution tarball into the appropriate location (where you want .\NixOS\ to be located, e.g. on a data drive:

    wsl --import NixOS .\NixOS\ nixos-wsl-installer.tar.gz --version 2
  5. Launch the distribution, after it is finished it should launch the shell for the user in your configuration:

    wsl -d NixOS
  6. Clone this repository to /etc/nixos/nixos-config:

    sudo mkdir /etc/nixos
    sudo git clone https://github.com/leonbreedt/nixos-config.git /etc/nixos/nixos-config
  7. Change to /etc/nixos/nixos-config and run ./rebuild to do the initial build.

Using

Whenever you make changes to the configuration, just run ./rebuild in the cloned flake directory to apply it to your system. Since the value of FLAKE defaults to the current hostname, you don't have to pass a hostname for subsequent builds, once it has been built once.

Troubleshooting

There are still some rough edges with this configuration. Mainly around first-time setup/retrieval of credentials from my private repo, you won't get access to it :)

If you remove the private repo input in flake.nix and the secrets references you can likely get it going.

Missing commands do not print derivations that resolve it

If you run a command that is not installed, and you get an error like this:

DBI connect('dbname=/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite','',...) failed:
unable to open database file at /run/current-system/sw/bin/command-not-found line 13.

Then you can likely resolve it by updating your Nix channels for the root user.

sudo nix-channel --update

Rust completion doesn't work in VIM

Since are using rustup instead of global native Nix Rust packages, make sure rust-analyzer is installed:

rustup component add rust-analyzer

nix-config's People

Contributors

leonbreedt avatar leonbreedt-sap avatar reubendaniels avatar

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.