Skip to content

Commit

Permalink
Refine home-manager and channels installation steps with nix flake (#261
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kachick authored Aug 24, 2023
1 parent f29dc9c commit e2ad4bc
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 57 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/ci-home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,15 @@ jobs:
os:
- ubuntu-22.04
- macos-13
home-manager-channel-ref:
- a8f8f48320c64bd4e3a266a850bbfde2c6fe3a04 # Pinned for current use
- master # unstable nixpkgs

runs-on: ${{ matrix.os }}
steps:
- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Register Nix Channels
run: |
nix-channel --add https://releases.nixos.org/nixpkgs/nixpkgs-23.11pre511546.844ffa82bbe2/nixexprs.tar.xz nixpkgs
nix-channel --add https://github.com/nix-community/home-manager/archive/${{ matrix.home-manager-channel-ref }}.tar.gz home-manager
nix-channel --update
nix-channel --list
- name: Print nixpkgs version after updating channels
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
- run: nix-shell '<home-manager>' -A install
- uses: actions/checkout@v3
- run: home-manager switch -b backup -f ./home-manager/user-github-actions.nix
# https://www.reddit.com/r/Nix/comments/1443k3o/comment/jr9ht5g/?utm_source=reddit&utm_medium=web2x&context=3
- run: mkdir -p ~/.local/state/nix/profiles
- run: nix run .#home-manager -- switch -b backup --flake .#github-actions
- name: Print some paths and versions
run: |
which fish
Expand Down
18 changes: 12 additions & 6 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,30 @@ args = [
]

[tasks.test]
command = 'home-manager'
command = 'nix'
args = [
'run',
'.#home-manager',
'--',
'switch',
'-n', # dry-run
'-b',
'backup',
'-f',
'./home-manager/home.nix',
'--flake',
'.#kachick',
]

[tasks.apply]
command = 'home-manager'
command = 'nix'
args = [
'run',
'.#home-manager',
'--',
'switch',
'-b',
'backup',
'-f',
'./home-manager/home.nix',
'--flake',
'.#kachick',
]

[tasks.enable_login_shells]
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ Also known as [盆栽(bonsai)](https://en.wikipedia.org/wiki/Bonsai) 🌳

## Installation

- To reactivate, you only need to run `makers apply`.
- For the first installation of your operating system, it may require more steps. Check the [wiki](https://github.com/kachick/dotfiles/wiki/Installation) for more details.
1. If you are installing a Unix-like operating system, install the [Nix](https://nixos.org/) package manager first.
\
Typically, this should be done in **one of** the following ways.
- `sh <(curl -L https://nixos.org/nix/install) --daemon`
- `curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install`
1. This repository is a flake, that includes installation steps of [home-manager](https://github.com/nix-community/home-manager) and dotfiles, you can run as follows
- `nix run github:kachick/dotfiles#home-manager -- switch -b backup --flake github:kachick/dotfiles#kachick`
1. If you experience any problems with the installation, See https://github.com/kachick/dotfiles/wiki/Installation for more details.
1. If you are on the development of this repository, the simple reactivation just needs to run as follows.
- `makers apply`
27 changes: 0 additions & 27 deletions cmd/add_nix_channels/main.go

This file was deleted.

22 changes: 22 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 34 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
# - `nix flake update --commit-lock-file` # https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-update.html
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# https://github.com/nix-community/home-manager/blob/master/docs/nix-flakes.adoc
home-manager = {
# candidates: "github:nix-community/home-manager/release-23.05";
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils }:
outputs = { self, nixpkgs, home-manager, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
Expand Down Expand Up @@ -37,6 +43,26 @@
];
};

packages.homeConfigurations =
{
kachick = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home-manager/home.nix
];
};

github-actions = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home-manager/home.nix
{
home.username = "runner";
}
];
};
};

# https://gist.github.com/Scoder12/0538252ed4b82d65e59115075369d34d?permalink_comment_id=4650816#gistcomment-4650816
packages.json2nix = pkgs.writeScriptBin "json2nix" ''
${pkgs.python3}/bin/python ${pkgs.fetchurl {
Expand All @@ -46,7 +72,13 @@
'';

apps = {
# nix run .#json2nix
# example: `nix run .#home-manager -- switch -n -b backup --flake .#kachick`
# https://github.com/NixOS/nix/issues/6448#issuecomment-1132855605
home-manager = flake-utils.lib.mkApp {
drv = home-manager.defaultPackage.${system};
};

# example: `nix run .#json2nix gitconfig.json`
json2nix = {
type = "app";
program = "${packages.json2nix}/bin/json2nix";
Expand Down
2 changes: 1 addition & 1 deletion home-manager/git.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, pkgs, ... }:
{ config, ... }:

{
# https://github.com/nix-community/home-manager/blob/master/modules/programs/git.nix
Expand Down
6 changes: 0 additions & 6 deletions home-manager/user-github-actions.nix

This file was deleted.

0 comments on commit e2ad4bc

Please sign in to comment.