mirror of
https://github.com/cupcakearmy/nix-cli.git
synced 2025-12-07 22:35:03 +00:00
v2
This commit is contained in:
49
README.md
49
README.md
@@ -1,24 +1,37 @@
|
|||||||
# Nix
|
# My Nix Server Configuration
|
||||||
|
|
||||||
Nix setup for server
|
This Nix flake configures a server with common tools and shell aliases.
|
||||||
|
|
||||||
## Install
|
## Prerequisites
|
||||||
|
|
||||||
|
- [Nix](https://nixos.org/download.html) must be installed on the server.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. **Fork this repository on GitHub.**
|
||||||
|
|
||||||
|
2. **Customize your fork:**
|
||||||
|
|
||||||
|
In `flake.nix`, change the `username` variable to your actual username on the server. You can do this directly on GitHub or by cloning your fork locally, making the change, and pushing it.
|
||||||
|
|
||||||
|
3. **Apply the configuration on your server:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nix run home-manager/master -- switch --flake github:<your-github-username>/nix-server#<your-username>
|
||||||
|
```
|
||||||
|
|
||||||
|
For example, if your GitHub username is `johndoe` and your server username is `john`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nix run home-manager/master -- switch --flake github:johndoe/nix-server#john
|
||||||
|
```
|
||||||
|
|
||||||
|
## Updating
|
||||||
|
|
||||||
|
To update the packages and your configuration on the server, simply run the same command again. Nix will automatically fetch the latest version of your flake from your GitHub repository.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# First time install
|
nix run home-manager/master -- switch --flake github:<your-github-username>/nix-server#<your-username>
|
||||||
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
|
|
||||||
|
|
||||||
# Install / Update
|
|
||||||
nix run home-manager -- switch --flake github:cupcakearmy/nix-cli#root -b bkp
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Update
|
To update the flake's dependencies (like `nixpkgs`), you'll need to update the `flake.lock` file in your repository. You can do this by running `nix flake update` in a local clone of your repository and pushing the changes.
|
||||||
|
|
||||||
This can be run on any machine. Just update and then just rerun on the targets
|
|
||||||
|
|
||||||
```bash
|
|
||||||
nix flake update
|
|
||||||
|
|
||||||
# To test
|
|
||||||
nix run home-manager -- build --flake .#root
|
|
||||||
```
|
|
||||||
|
|||||||
46
flake.lock
generated
46
flake.lock
generated
@@ -1,5 +1,23 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"home-manager": {
|
"home-manager": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
@@ -7,11 +25,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1735774425,
|
"lastModified": 1759853171,
|
||||||
"narHash": "sha256-C73gLFnEh8ZI0uDijUgCDWCd21T6I6tsaWgIBHcfAXg=",
|
"narHash": "sha256-uqbhyXtqMbYIiMqVqUhNdSuh9AEEkiasoK3mIPIVRhk=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "5f6aa268e419d053c3d5025da740e390b12ac936",
|
"rev": "1a09eb84fa9e33748432a5253102d01251f72d6d",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -22,11 +40,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1735471104,
|
"lastModified": 1759733170,
|
||||||
"narHash": "sha256-0q9NGQySwDQc7RhAV2ukfnu7Gxa5/ybJ2ANT8DQrQrs=",
|
"narHash": "sha256-TXnlsVb5Z8HXZ6mZoeOAIwxmvGHp1g4Dw89eLvIwKVI=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "88195a94f390381c6afcdaa933c2f6ff93959cb4",
|
"rev": "8913c168d1c56dc49a7718685968f38752171c3b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -38,9 +56,25 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
"home-manager": "home-manager",
|
"home-manager": "home-manager",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|||||||
43
flake.nix
43
flake.nix
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
description = "nix base CLI env";
|
description = "A simple Nix flake for server configuration";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
@@ -7,18 +7,51 @@
|
|||||||
url = "github:nix-community/home-manager";
|
url = "github:nix-community/home-manager";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{ nixpkgs, home-manager, ... }:
|
{
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
home-manager,
|
||||||
|
flake-utils,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
let
|
let
|
||||||
system = "x86_64-linux";
|
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
# This is the main entry point for a user's home configuration.
|
||||||
|
# The user should be changed to the actual username.
|
||||||
|
username = "root";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
homeConfigurations."root" = home-manager.lib.homeManagerConfiguration {
|
packages.default = pkgs.btop;
|
||||||
|
|
||||||
|
homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
modules = [ ./home.nix ];
|
modules = [
|
||||||
|
(
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
{
|
||||||
|
home.username = username;
|
||||||
|
home.homeDirectory = "/home/${username}";
|
||||||
|
|
||||||
|
home.stateVersion = "23.11"; # Please change this to your version.
|
||||||
|
|
||||||
|
home.alias = {
|
||||||
|
l = "ls -hal";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
home.packages = [
|
||||||
|
pkgs.btop
|
||||||
|
];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
78
home.nix
78
home.nix
@@ -1,78 +0,0 @@
|
|||||||
{ config, pkgs, ... }:
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
home = {
|
|
||||||
username = "root";
|
|
||||||
homeDirectory = "/root";
|
|
||||||
stateVersion = "25.05"; # Please read the comment before changing.
|
|
||||||
|
|
||||||
packages = with pkgs; [
|
|
||||||
neovim
|
|
||||||
tmux
|
|
||||||
|
|
||||||
git
|
|
||||||
gnutar
|
|
||||||
btop
|
|
||||||
|
|
||||||
# Rust utils
|
|
||||||
bat
|
|
||||||
eza
|
|
||||||
fd
|
|
||||||
ripgrep
|
|
||||||
ripgrep-all
|
|
||||||
zoxide
|
|
||||||
uutils-coreutils-noprefix
|
|
||||||
dust
|
|
||||||
yazi
|
|
||||||
starship
|
|
||||||
rclone
|
|
||||||
|
|
||||||
nerd-fonts.jetbrains-mono
|
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
sessionVariables = {
|
|
||||||
EDITOR = "nvim";
|
|
||||||
};
|
|
||||||
|
|
||||||
shellAliases = {
|
|
||||||
l = "eza -a1lh";
|
|
||||||
ls = "eza";
|
|
||||||
dc = "docker compose";
|
|
||||||
rsync = "rsync -az --info=progress2";
|
|
||||||
t = "tmux new-session -A -s main";
|
|
||||||
e = "nvim";
|
|
||||||
g = "lazygit";
|
|
||||||
d = "lazydocker";
|
|
||||||
vai = "home-manager switch --flake github:cupcakearmy/nix-cli#root -b backup";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
programs = {
|
|
||||||
home-manager.enable = true;
|
|
||||||
starship.enable = true;
|
|
||||||
bash.enable = true;
|
|
||||||
fish.enable = true;
|
|
||||||
tmux = {
|
|
||||||
enable = true;
|
|
||||||
clock24 = true;
|
|
||||||
mouse = true;
|
|
||||||
extraConfig = ''
|
|
||||||
# switch panes using Alt-arrow without prefix
|
|
||||||
bind -n M-Left select-pane -L
|
|
||||||
bind -n M-Right select-pane -R
|
|
||||||
bind -n M-Up select-pane -U
|
|
||||||
bind -n M-Down select-pane -D
|
|
||||||
|
|
||||||
# switch panes using jkhl
|
|
||||||
bind h select-pane -L
|
|
||||||
bind l select-pane -R
|
|
||||||
bind j select-pane -U
|
|
||||||
bind k select-pane -D
|
|
||||||
'';
|
|
||||||
shell = "${pkgs.fish}/bin/fish";
|
|
||||||
terminal = "tmux-256color";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user