Skip to content

Commit 83261e9

Browse files
committed
use local dotfiles repo
this allows customization and overriding
1 parent 6cd03d3 commit 83261e9

10 files changed

+227
-152
lines changed

Readme.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
# StratoKit dotfiles via home-manager
22

3-
This manages our dotfiles and enables direnv
3+
This manages our dotfiles and enables direnv.
44

5-
## Installation or upgrades
5+
## Installation
66

7-
Run `./switch.sh`
7+
If you don't have Nix installed yet or you're not sure about it supporting flakes, run
8+
9+
```sh
10+
NIX_EXTRA_CONF='experimental-features = nix-command flakes' sh <(curl -L https://nixos.org/nix/install) --daemon
11+
```
12+
13+
Once it's installed, open a new terminal.
14+
15+
Add this repo to your flake registry by running:
16+
17+
```sh
18+
nix registry add dotfiles github:StratoKit/dotfiles
19+
```
20+
21+
Then to install or to update, just run it:
22+
23+
```nix
24+
nix run dotfies
25+
```
26+
27+
## Details
28+
29+
This will create a local dotfiles repo that stores your configuration and is editable.
30+
31+
On macOS, it is stored under `~/Library/dotfiles`, and on Linux, `~/.config/dotfiles`.
32+
33+
This allows you to override everything, including the version of nixpkgs that is used.

default-flake.nix

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
description = "StratoKit dotfiles flake, see https://github.com/StratoKit/dotfiles";
3+
4+
inputs = {
5+
# You can choose a different flake here
6+
dotfiles.url = "github:StratoKit/dotfiles";
7+
8+
# With this you can override nixpkgs or similarly home-manager
9+
# nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
10+
# dotfiles.inputs.nixpkgs.follows = "nixpkgs";
11+
};
12+
13+
outputs = inputs:
14+
let
15+
# The auto-generated settings
16+
settings = import ./settings.nix;
17+
inherit (settings) username homeDirectory hostname system configDirectory;
18+
# The inputs provided by the dotfiles repo
19+
inherit (inputs.dotfiles) nixpkgs home-manager;
20+
21+
pkgs = inputs.dotfiles.pkgs.${system};
22+
in
23+
{
24+
# The commands you can run
25+
apps.${system} = {
26+
# Just use the apps from the main repo
27+
inherit (inputs.dotfiles.apps.${system}) default update;
28+
};
29+
30+
# The home-manager configuration
31+
homeConfigurations = {
32+
${username} = home-manager.lib.homeManagerConfiguration rec {
33+
inherit pkgs;
34+
modules = [
35+
# This provides the default StratoKit configuration
36+
(inputs.dotfiles.makeDefaults settings)
37+
38+
# Here you can add your own extra module files to import
39+
# ./home.nix
40+
41+
# or specify them inline
42+
# ({ config, pkgs, lib, ... }: {
43+
# nixpkgs.config = {
44+
# # allowUnfree = true;
45+
# # allowUnsupportedSystem = true;
46+
# };
47+
# })
48+
49+
# Update this only when you know what you are doing
50+
{ home.stateVersion = "22.05"; }
51+
];
52+
};
53+
};
54+
};
55+
}

default-readme.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Local dotfiles
2+
3+
This repo contains the local configuration for https://github.com/StratoKit/dotfiles.
4+
5+
It is a git repository so you can create your own customizations.
6+
7+
To update your dotfiles, run
8+
9+
```sh
10+
nix run dotfiles
11+
```
12+
13+
provided you have the correct registry setting, see the main repo for more information.

flake.lock

+19-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+35-38
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,48 @@
22
description = "A Home Manager flake";
33

44
inputs = {
5+
flake-utils.url = "github:numtide/flake-utils";
6+
7+
# our default nixpkgs
58
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
6-
home-manager.url = "github:nix-community/home-manager";
9+
10+
home-manager.url = "github:nix-community/home-manager/master";
711
home-manager.inputs.nixpkgs.follows = "nixpkgs";
812
};
913

10-
outputs = inputs:
14+
outputs = { self, nixpkgs, flake-utils, home-manager }: {
15+
inherit home-manager;
16+
makeDefaults = import ./home.nix;
17+
} //
18+
flake-utils.lib.eachDefaultSystem (system:
1119
let
12-
inherit (builtins) stringLength substring;
13-
14-
local = import ./local_auto.nix;
15-
16-
hasSuffix =
17-
# Suffix to check for
18-
suffix:
19-
# Input string
20-
content:
21-
let
22-
lenContent = stringLength content;
23-
lenSuffix = stringLength suffix;
24-
in
25-
lenContent >= lenSuffix &&
26-
substring (lenContent - lenSuffix) lenContent content == suffix;
27-
28-
username = local.username;
29-
system = local.system;
30-
homeDirectory = if (hasSuffix "darwin" system) then "/Users/${username}" else "/home/${username}";
31-
extra = if (builtins.hasAttr "extra" local) then local.extra else null;
20+
pkgs = nixpkgs.legacyPackages.${system};
21+
thisHM = home-manager.packages.${system}.default;
22+
install = pkgs.substituteAll {
23+
src = ./install.sh;
24+
isExecutable = true;
25+
inherit (pkgs) bash git;
26+
defaultFlake = ./default-flake.nix;
27+
defaultReadme = ./default-readme.md;
28+
};
29+
update = pkgs.substituteAll {
30+
src = ./update.sh;
31+
isExecutable = true;
32+
inherit (pkgs) bash;
33+
homeManager = thisHM;
34+
};
3235
in
3336
{
34-
defaultPackage = inputs.home-manager.defaultPackage;
35-
homeConfigurations = {
36-
${username} = inputs.home-manager.lib.homeManagerConfiguration rec {
37-
inherit username homeDirectory system;
38-
pkgs = inputs.nixpkgs.outputs.legacyPackages.${system};
39-
configuration.imports = [
40-
({ config, pkgs, lib, ... }: {
41-
nixpkgs.config = {
42-
allowUnfree = true;
43-
allowUnsupportedSystem = true;
44-
};
45-
})
37+
inherit pkgs;
4638

47-
./home.nix
48-
];
49-
};
39+
apps.default = {
40+
type = "app";
41+
program = "${install}";
42+
};
43+
apps.update = {
44+
type = "app";
45+
program = "${update}";
5046
};
51-
};
47+
}
48+
);
5249
}

home.nix

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1+
# The settings that are auto-generated by the installer
2+
settings:
3+
# Returns a normal module
14
{ pkgs, lib, ... }:
2-
3-
let
4-
local = import ./local_auto.nix;
5-
username = local.username;
6-
in
75
{
86
programs.nix-index.enable = true;
97
programs.command-not-found.enable = false;
@@ -18,14 +16,17 @@ in
1816
programs.zsh.enable = true;
1917
programs.bash.enable = true;
2018

21-
home.packages = with pkgs; [
22-
nixpkgs-fmt
19+
home = {
20+
inherit (settings) username homeDirectory;
21+
packages = with pkgs; [
22+
nixpkgs-fmt
2323

24-
nodejs
24+
nodejs
2525

26-
pstree
27-
rsync
28-
sqlite-interactive
29-
tree
30-
];
26+
pstree
27+
rsync
28+
sqlite-interactive
29+
tree
30+
];
31+
};
3132
}

0 commit comments

Comments
 (0)