Ion Mudreac
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: Publication --- # NixOS Home Manager on native NIX flake installation and Configuration In the 1st article, we covered in detail [NixOs native flake deployment](https://mudrii.medium.com/nixos-native-flake-deployment-with-luks-drive-encryption-and-lvm-b7f3738b71ca) Once you have your system up and running in a purely declarative way next step, it to manage your personal configuration files located in `$HOME` /home folder. NixOs do not have any native implementation to manage user's `$HOME` configuration folders and files. Few projects stepped in to help and manage users specific environments, and the most successful one in [Home Manager](https://github.com/nix-community/home-manager) From the Home Manager site; "This project provides a basic system for managing a user environment using the [Nix](https://nixos.org/nix/) package manager together with the Nix libraries found in [Nixpkgs](https://nixos.org/nixpkgs/). It allows declarative configuration of user specific (non global) packages and dotfiles." A god start is [Home Manager Manual](https://nix-community.github.io/home-manager/) This article will cover Home Manager deployment in NixOS, With an example of configuration like configuring fish and bash shells, configuring tmux, neovim, and git with NIX native declarative configuration managed by Home Manager. A good practice, we will store our Home Manager configuration files in the git repository similarly to what we did for the NixOs configuration. ## Installation Installation is very straightforward. 1. Add home manager nix channel to users channel. _Note: make sure you are logged in as normal users and not as a root._ _Note: Pay attention to the release version that should be the same as your NixOs version. In the below example, we use the latest NixOs and Home Manager release._ ```sh nix-channel --add https://github.com/nix-community/home-manager/archive/release-21.05.tar.gz home-manager ``` 2. Update newly added channel ```sh nix-channel --update ``` 3. Home Manager installation _Note: Before installation is a good idea to logoff and login again before continuing with installation to avoid any potential issues with the missing path to the newly updated channel._ ```sh nix-shell '<home-manager>' -A install ``` ## Post Installation Once home-manager and dependencies are installed, create a folder and file `~/.config/nixpkgs/home.nix`. This file we will need to delete and replaced with preconfigured Home Manager from GitHub. ```sh rm -rf ~/.config/nixpkgs/home.nix git clone https://github.com/mudrii/hmtst.git ~/.config/nixpkgs --depth 1 ``` Post GitHub repository syncup good practice it to update flake.lock file to have the latest commits ```sh nix flake update ~/.config/nixpkgs ``` ## Home Manager `$USER` environment deployment Install all dependencies for the `$USER`. ```sh home-manager switch --flake ~/.config/nixpkgs/#$USER -v ``` ## Deep Dive into Home Manager users configuration ### flake.nix Home Manager has full support for nix flake below if the flake I use to test and deploy my configuration. ```nix { description = "Home Manager NixOS configuration"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-21.05"; nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; home-manager.url = "github:nix-community/home-manager/release-21.05"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = inputs@{ self, nixpkgs, nixpkgs-unstable, home-manager, ... }: { homeConfigurations = { mudrii = inputs.home-manager.lib.homeManagerConfiguration { system = "x86_64-linux"; homeDirectory = "/home/mudrii"; username = "mudrii"; stateVersion = "21.05"; configuration = { config, pkgs, ... }: let overlay-unstable = final: prev: { unstable = inputs.nixpkgs-unstable.legacyPackages.x86_64-linux; }; in { nixpkgs.overlays = [ overlay-unstable ]; nixpkgs.config = { allowUnfree = true; allowBroken = true; }; imports = [ ./users/mudrii/home.nix ]; }; }; }; mudrii = self.homeConfigurations.mudrii.activationPackage; defaultPackage.x86_64-linux = self.mudrii; }; } ``` _Note: First Thing to note, we added to inputs home manager remote Github repo._ _Note: In section `homeConfigurations` you will need to replace with your `$USER` name._ _Note: In addition, I added `overlay-unstable` to be able to install packages from the unstable channel/Github repo._ ### home.nix #### Imports ```nix imports = [ ./dotfiles/bashrc.nix ./dotfiles/fish.nix ./dotfiles/git.nix ./dotfiles/tmux.nix ./dotfiles/neovim.nix ]; ``` _Note: home.nix allows us to import multiple configuration files and not to clutter everything in a single file._ _Note: Check `./dotfiles/git.nix` and update with your details the below fields._ _Note: Fish shell is configured to use [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish) one of the templates that I find it simple and useful._ _Note: neovim is configured with few vim plugins in the stable and unstable branch that you may find it useful._ ```nix programs.git.userName = "Your Name here"; programs.git.userEmail = "your.email@domain.dom"; ``` _Note: you can change any configuration files that work best for you._ #### Packages In home.nix, we provide a list of the packages that will be visible only for the user. ```nix home = { packages = with pkgs; [ sshfs asciinema aspell aspellDicts.en tldr procs gitAndTools.gh git-crypt git-lfs gtop bpytop tree ripgrep file binutils fd trash-cli mosh highlight nix-index yarn nixpkgs-fmt nixpkgs-review pypi2nix nodePackages.node2nix unstable.python39Packages.poetry (python39.withPackages (ps: with ps; [ pip powerline pygments pynvim ])) ]; }; ``` #### Programs _Note: For Some packages, Home Manager allows a different way to declare in home-manager style._ ```nix programs = { home-manager.enable = true; gpg.enable = true; fzf.enable = true; jq.enable = true; bat.enable = true; command-not-found.enable = true; dircolors.enable = true; htop.enable = true; info.enable = true; exa.enable = true; direnv = { enable = true; nix-direnv = { enable = true; enableFlakes = true; }; }; ``` #### Services In this section, we declare the services that will be available only for this user. ```nix services = { lorri.enable = true; gpg-agent = { enable = true; enableSshSupport = true; }; }; ``` ## Fin You can find tons of options to configure Home Manager in [HM Manual](https://nix-community.github.io/home-manager/options.html) Additional information can be found in [NixOs Wiki HM Page](https://nixos.wiki/wiki/Home_Manager)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully