Giter Site home page Giter Site logo

nix-config's Introduction

nix-dev-home

A home-manager template providing useful tools & settings for Nix-based development. Neovim pre-configured for Haskell Language Server is included as a key demonstration (try it with haskell-template).

Usage

Before proceeding, install Nix first.

  1. Create a local repository mirroring this template. There are two ways to do this; the first one is favoured over the rest; pick your choice:
    1. Click the green "Use this template" button above on Github, and then clone your repo locally:
      # Replace this URL with your repo URL
      git clone https://github.com/user/nixconfig.git
      cd nixconfig
      # Update to latest software
      nix flake update
    2. Or, run nix flake init on an empty directory
      mkdir nixconfig 
      cd nixconfig
      nix flake init -t github:juspay/nix-dev-home
  2. Open flake.nix and set myUserName to your user name. You can use echo $USER to get your user name.1
    • Optionally, you may edit ./home/default.nix to your liking.
  3. Run either nix run or nix develop -c just run to active your configuration.
  4. Restart your terminal.
    • Expect to see the starship prompt. When you cd into a project containing .envrc configured for flakes (such as this very repository), you should automatically be put in the nix develop shell along with a change to the starship prompt indicating the same. If not, run direnv allow once.

Note

Executing step 4 above will modify the contents of your $HOME directory. You will be warned before overwriting, but not before creating links to newly created configuration files in the nix store. Since home-manager does not currently provide an integrated and automated feature to eliminate the links it creates, be aware that if you would like to reverse this operation, you will need to curate your home directory manually.

Details

The configuration repo has flake.nix file in the current directory and a ./home directory containing the home-manager configuration that you can review starting with ./home/default.nix. It also has a justfile, which provides a set of recipes analogous to Make targets to interact with the nix flake.

You can then execute nix develop, to ensure you are in the development shell with just installed, followed by just run to activate this configuration in your $HOME. On most systems you are likely to experience at least one of the issues mentioned below in Troubleshooting. A more complete sequence might be

nix-dev-env setup
> nix develop
(nix:nix-dev-home-env) > rm ~/.bashrc ~/.profile && just run && direnv allow
(nix:nix-dev-home-env) > exit
> bash
runner on 12ca6a64c923 work on  feature/branch via ❄️  impure (nix-dev-home-env) 
⬢ [Docker] ❯ 

If you prefer, you can simply execute nix run, but using just will perform some additional validation and ensure you are able to use the other commands in the justfile.

To browse the capabilities of home-manager (and to see what else can go in your ./home -- such as shell aliases), consult https://nix-community.github.io/home-manager/options.html. You can also run man home-configuration.nix in the terminal.

Demo

A sample demo of the setup process is shown below:

asciicast

Troubleshooting

  • nix run shows an error like: error: opening lock file '/nix/var/nix/profiles/per-user/utkarsh.pandey1/profile.lock': No such file or directory
    • This is an instance of nix-community/home-manager#4611. Run sudo mkdir /nix/var/nix/profiles/per-user/$USER/ && sudo chown $USER /nix/var/nix/profiles/per-user/$USER and try again.
  • Running nix run (home-manager) complains "Existing file ... is in the way of ..."
    • Delete those existing dotfiles, and try again. In home-manager, you can configure your shell directly in Nix (for macOS zsh, this is programs.zsh.envExtra).
  • Cannot use cachix: Running nix run nixpkgs#cachix use nammayatri (for example) does not succeed.
    • Add yourself to the trusted-users list and restart your macOS machine.

      mkdir -p ~/.config/nix
      echo "trusted-users = root $USER" > $HOME/.config/nix/nix.conf

FAQ

But I use NixOS

You can embed this configuration inside your NixOS configuration, and thus share it with non-NixOS systems (like macOS and Ubuntu). See the "both" template of https://github.com/srid/nixos-flake for an example. If you don't want to share the configuration with macOS (ie., you use only Linux for development), see the "linux" template instead.

Footnotes

  1. runner is used by default for compatibility with github actions.

nix-config's People

Contributors

neeraj97 avatar

Watchers

 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.