Coder Social home page Coder Social logo

nix-setup's Introduction

Getting started

Clone this repo to ~/.nixpkgs and run the setup script:

git clone [email protected]:treffynnon/nix-setup.git ~/.nixpkgs && ~/.nixpkgs/scripts/setup.sh

which will perform the following actions for you:

  1. Install nix
  2. if on a Mac install nix-darwin
  3. install home-manager
  4. back-up /etc/shells
  5. moves default ZSH zprofile and zshrc to *.local (they still get loaded!)
  6. runs darwin-rebuild switch to install all the dependencies with nix

Rebuilding the configuration when you change the files

TERM=xterm-256color darwin-rebuild switch

The TERM environment var is changed here because modern term emulators like kitty confuse the darwin-rebuild util.

Setup cachix

Install to benefit from the binary cache

Install the cachix package to the environment

nix-env -iA cachix -f https://cachix.org/api/v1/install

Configure cachix to be used

cachix use treffynnon

This will use the binaries I have cached there were it can instead of spending time recompiling them on your machine. It is also used by GitHub Actions to speed up the linting/formatting/testing builds.

Pushing to the binary cache

Setup the necessary keys

cachix generate-keypair treffynnon

Set the signing key in ~/.config/cachix/cachix.dhall where it should be set against the secretKey property. If you’re not me then you’ll need to create your own cache on https://cachix.org first as you cannot push to my cache - yoo can read from it, but not push to it.

You can now push binary builds to the cachix repository.

cachix push treffynnon <path to some package in /nix/store>

Setup bash completions

For bash completions to work properly the system must use the nix supplied version of bash as the MacOS version is ancient.

chsh -s /run/current-system/sw/bin/bash

If you want to use Fish shell then:

chsh -s /run/current-system/sw/bin/fish

See https://discourse.nixos.org/t/using-nix-to-install-login-shell-on-non-nixos-platform/2807/3

GPG setup

For the SSH agent and git commits to work the GPG signing key must be present. If you have already got one then import it:

gpg --import /path/to/your.key

Otherwise you can create one using this comprehensive guide - https://blog.tinned-software.net/create-gnupg-key-with-sub-keys-to-sign-encrypt-authenticate/

Setting up hammerspoon

Install Hammerspoon from https://www.hammerspoon.org/

Hammerspoon provides:

  • Window management via the keyboard
  • kbd:[Caps lock] as kbd:[Esc] when tapped and kbd:[Ctrl] when held

Run Hammerspoon (use Spotlight with kbd:[Command] + kbd:[Space]) - note that it can take sometime to start initially - be patient - and configure it to:

  • Run at login
  • Enable Accessibility
  • (optionally) untick "Show dock icon"

The configuration is in ./home-configs/hammerspoon.nix and ./home-configs/hammerspoon.

Environment variables

Private or secret environment vars you don’t want to commit into a repository can be stored in ~/.env with the following format.

MY_VAR=MY_VALUE

Uninstalling

You can reverse the setup process by running the remove script:

./scripts/remove.sh

Making changes

Building the code

If you modify any of the configurations in the nix configuration then you need to rebuild the environment.

darwin-rebuild switch

It will probably ask you to enter a password, which can get annoying so you can modify the sudoers file to allow passwordless invocation of darwin-rebuild for your user. Create a /etc/sudoers.d/nix-darwin file with this content:

<home-user> ALL=(ALL:ALL) NOPASSWD: /run/current-system/sw/bin/darwin-rebuild (where home-user is name of home directory)

Formatting code

This project uses:

to keep the code and configurations in a consistent state. They are also applied as a github action to test the setup in CI too.

To easily run the formatters locally you can use the supplied nix-shell:

nix-shell
format

Managing development environments

Direnv and Lorri

I no longer use lorri because I am using nix-direnv instead.

Install Lorri (not currently a Nix package due to their rapid development cycles while in beta).

Put a .envrc file inside your project with:

.envrc

eval "$(lorri direnv)"

and a file for the nix-shell (shell.nix):

let
  # nix1809 = import (builtins.fetchGit {
  #   name = "nixos-18_09";
  #   url = https://github.com/NixOS/nixpkgs.git;
  #   ref = "refs/tags/18.09";
  # }) {};
  nix1809 = import (
    builtins.fetchTarball {
      name = "nixos-18_09";
      url = "https://github.com/NixOS/nixpkgs/archive/18.09.tar.gz";
      sha256 = "1ib96has10v5nr6bzf7v8kw7yzww8zanxgw2qi1ll1sbv6kj6zpd";
    }
  ) {};
in
  with import <nixpkgs> {};
    stdenv.mkDerivation {
      name = "ftr-beast";
      buildInputs = [
        bashInteractive
        nix1809.nodejs-8_x
      ];
    }

Start lorri with lorri daemon and leave it running in a shell.

Now when you cd into the projects directory Lorri/direnv will install the dependencies and drop you into a Nix shell.

MacOS Catalina

Before upgrading to Catalina:

Useful links

Nix

Flakes

Lua and nix

Dot files managed by nix

Building C/C++ projects with nix

OSX

OSX settings values

OSX security settings

OSX screen management woes

OSX multiple monitors losing position and rotation settings

Spaces merging together on disconnecting additional monitors

Todo

install confs for

  • Karabiner-Elements
  • Lulu - this has an interactive installer so probably too hard to do with nix
  • Netiquette - this has an interactive installer so probably too hard to do with nix

nix-setup's People

Contributors

treffynnon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.