or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
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.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
NixOS and Home Manager update with nix systemd services
In previous e articles, we described how we deploy native flake NixOs as a development environment and Home Manager to manage user's specific packages, configurations, and services.
Context
All developers in the project are running as primary Dev environment NixOs VM on Google Cloud. Our development team is divided into two streams.
The problem we try to solve
Only Infra/Cloud Dev team has access to the root "wheel." Still, because we selected to run our development environment on the NixOS application, development team members can install any application or service for their account without the need for root privileges.
As we use flake for NixOs deployment, we tightly control flake.lock file allows us to maintain consistency between developers in the package version we deploy OS-wide and nix Home Manager.
As only Infra/Cloud Dev team can update flake.lock files that refer to Github SHA commit/revisions in nixpkgs
Ex. flake.lock file
We need to find a solution where the Infra/Cloud Dev team updates the latest flake.lock file that may have security or new package version updates.
Once the git repository was updated and changes pushed, we needed a mechanism to propagate the changes to the rest of the Google Cloud VM fleet running NixOs.
We find the pull model most robust and easy to implement using native Linux systemd scheduling, and all this is directly integrated into our nix configuration system.
Solution
We have two separate managed components, one is for managing global OS configuration, and one is for nix Home manager. We need two different systemd services to manage updates for every component update separately.
Ideally, our solution should support nix natively as we do not want to diverge too much from the nix configuration language.
NixOs system-wide update systemd service
We have few options
We can use a separate git repository and integrate it directly into
/etc/nixos/flake.nix
The example you can find in on GitHub NixOs SYS Auto Update Repo
Option two is to have direct integration with the existing nix configuration.
By having a service directory in the main repo and define with nix expression:
Note: just to make sure to import service.nix file into your
/etc/nixos/configuration.nix
imports = [./services/nixos-auto-update.nix];
and declare in servicesservices.nixos-auto-update.enable = true;
NixOs Home Manager systemd service update
As for the nix Home Manager, we will define same as for OS-wide update
We can use a separate git repository and integrate it directly into
~/.config/nixpkgs
The example you can find in on GitHub NixOs HM Auto Update Repo
Option two is to have direct integration with the existing nix configuration
By having a service directory in the main repo and define with nix expression:
Note: just to make sure to import service.nix file into your
~/.config/nixpkgs/users.$USER/home.nix
imports = [../../services/nixos-hm-auto-update.nix];
and declare in servicesservices.nixos-hm-auto-update.enable = true;
Note: solution and code was developed by one of my colleague in the project
Verification
Once services have been deployed, we can see if services started and completed successfully.
Note: System update service will run after 5 min once os started
Note: Nix Home Manager update service will run after 10 min once os started to eliminate any conflict with os serviced scheduler