feat: add guix as a daemon service

This commit is contained in:
Ryan Yin
2024-01-13 00:17:44 +08:00
parent 8c8a9105e4
commit c4a28eb062
6 changed files with 78 additions and 152 deletions

177
flake.lock generated
View File

@@ -4,9 +4,7 @@
"inputs": { "inputs": {
"darwin": "darwin", "darwin": "darwin",
"home-manager": "home-manager", "home-manager": "home-manager",
"nixpkgs": [ "nixpkgs": ["nixpkgs"]
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1694733633, "lastModified": 1694733633,
@@ -26,9 +24,7 @@
"anyrun": { "anyrun": {
"inputs": { "inputs": {
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"nixpkgs": [ "nixpkgs": ["nixpkgs"]
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1701453400, "lastModified": 1701453400,
@@ -63,22 +59,10 @@
}, },
"crane": { "crane": {
"inputs": { "inputs": {
"flake-compat": [ "flake-compat": ["lanzaboote", "flake-compat"],
"lanzaboote", "flake-utils": ["lanzaboote", "flake-utils"],
"flake-compat" "nixpkgs": ["lanzaboote", "nixpkgs"],
], "rust-overlay": ["lanzaboote", "rust-overlay"]
"flake-utils": [
"lanzaboote",
"flake-utils"
],
"nixpkgs": [
"lanzaboote",
"nixpkgs"
],
"rust-overlay": [
"lanzaboote",
"rust-overlay"
]
}, },
"locked": { "locked": {
"lastModified": 1681177078, "lastModified": 1681177078,
@@ -96,10 +80,7 @@
}, },
"darwin": { "darwin": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": ["agenix", "nixpkgs"]
"agenix",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1673295039, "lastModified": 1673295039,
@@ -166,10 +147,7 @@
}, },
"flake-parts": { "flake-parts": {
"inputs": { "inputs": {
"nixpkgs-lib": [ "nixpkgs-lib": ["anyrun", "nixpkgs"]
"anyrun",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1696343447, "lastModified": 1696343447,
@@ -187,10 +165,7 @@
}, },
"flake-parts_2": { "flake-parts_2": {
"inputs": { "inputs": {
"nixpkgs-lib": [ "nixpkgs-lib": ["lanzaboote", "nixpkgs"]
"lanzaboote",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1680392223, "lastModified": 1680392223,
@@ -280,11 +255,7 @@
}, },
"gitignore": { "gitignore": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": ["lanzaboote", "pre-commit-hooks-nix", "nixpkgs"]
"lanzaboote",
"pre-commit-hooks-nix",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1660459072, "lastModified": 1660459072,
@@ -302,11 +273,7 @@
}, },
"gitignore_2": { "gitignore_2": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": ["nixos-rk3588", "pre-commit-hooks", "nixpkgs"]
"nixos-rk3588",
"pre-commit-hooks",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1660459072, "lastModified": 1660459072,
@@ -324,10 +291,7 @@
}, },
"gitignore_3": { "gitignore_3": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": ["pre-commit-hooks", "nixpkgs"]
"pre-commit-hooks",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1660459072, "lastModified": 1660459072,
@@ -345,10 +309,7 @@
}, },
"home-manager": { "home-manager": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": ["agenix", "nixpkgs"]
"agenix",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1682203081, "lastModified": 1682203081,
@@ -366,9 +327,7 @@
}, },
"home-manager_2": { "home-manager_2": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": ["nixpkgs"]
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1704498488, "lastModified": 1704498488,
@@ -388,9 +347,7 @@
"hyprland": { "hyprland": {
"inputs": { "inputs": {
"hyprland-protocols": "hyprland-protocols", "hyprland-protocols": "hyprland-protocols",
"nixpkgs": [ "nixpkgs": ["nixpkgs"],
"nixpkgs"
],
"systems": "systems", "systems": "systems",
"wlroots": "wlroots", "wlroots": "wlroots",
"xdph": "xdph" "xdph": "xdph"
@@ -412,14 +369,8 @@
}, },
"hyprland-protocols": { "hyprland-protocols": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": ["hyprland", "nixpkgs"],
"hyprland", "systems": ["hyprland", "systems"]
"nixpkgs"
],
"systems": [
"hyprland",
"systems"
]
}, },
"locked": { "locked": {
"lastModified": 1691753796, "lastModified": 1691753796,
@@ -456,9 +407,7 @@
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-parts": "flake-parts_2", "flake-parts": "flake-parts_2",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": [ "nixpkgs": ["nixpkgs"],
"nixpkgs"
],
"pre-commit-hooks-nix": "pre-commit-hooks-nix", "pre-commit-hooks-nix": "pre-commit-hooks-nix",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
}, },
@@ -513,9 +462,7 @@
}, },
"nix-darwin": { "nix-darwin": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": ["nixpkgs-darwin"]
"nixpkgs-darwin"
]
}, },
"locked": { "locked": {
"lastModified": 1704277720, "lastModified": 1704277720,
@@ -549,9 +496,7 @@
"nixos-generators": { "nixos-generators": {
"inputs": { "inputs": {
"nixlib": "nixlib", "nixlib": "nixlib",
"nixpkgs": [ "nixpkgs": ["nixpkgs"]
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1701689616, "lastModified": 1701689616,
@@ -641,11 +586,11 @@
}, },
"nixpkgs-darwin": { "nixpkgs-darwin": {
"locked": { "locked": {
"lastModified": 1704590667, "lastModified": 1704884582,
"narHash": "sha256-fTn6QFubMmBSlmfvPbqqrwZXf4+H7+B5ygDGVEHCqQo=", "narHash": "sha256-vLZko1MngM8/Onghu8g8zocupJEUFR4n1zw73kxTWb8=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "7e451ea687631acf29744281f036541db66bff1a", "rev": "a1fc22b2efdeba72b0519ac1548ec3c26e7f7b13",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -721,16 +666,16 @@
}, },
"nixpkgs_3": { "nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1704420045, "lastModified": 1704722960,
"narHash": "sha256-C36QmoJd5tdQ5R9MC1jM7fBkZW9zBUqbUCsgwS6j4QU=", "narHash": "sha256-mKGJ3sPsT6//s+Knglai5YflJUF2DGj7Ai6Ynopz0kI=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "c1be43e8e837b8dbee2b3665a007e761680f0c3d", "rev": "317484b1ead87b9c1b8ac5261a8d2dd748a0492d",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "nixos",
"ref": "nixos-23.11", "ref": "nixos-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@@ -820,22 +765,11 @@
}, },
"pre-commit-hooks": { "pre-commit-hooks": {
"inputs": { "inputs": {
"flake-compat": [ "flake-compat": ["nixos-rk3588"],
"nixos-rk3588" "flake-utils": ["nixos-rk3588", "flake-utils"],
],
"flake-utils": [
"nixos-rk3588",
"flake-utils"
],
"gitignore": "gitignore_2", "gitignore": "gitignore_2",
"nixpkgs": [ "nixpkgs": ["nixos-rk3588", "nixpkgs"],
"nixos-rk3588", "nixpkgs-stable": ["nixos-rk3588", "nixpkgs"]
"nixpkgs"
],
"nixpkgs-stable": [
"nixos-rk3588",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1702456155, "lastModified": 1702456155,
@@ -853,19 +787,10 @@
}, },
"pre-commit-hooks-nix": { "pre-commit-hooks-nix": {
"inputs": { "inputs": {
"flake-compat": [ "flake-compat": ["lanzaboote", "flake-compat"],
"lanzaboote", "flake-utils": ["lanzaboote", "flake-utils"],
"flake-compat"
],
"flake-utils": [
"lanzaboote",
"flake-utils"
],
"gitignore": "gitignore", "gitignore": "gitignore",
"nixpkgs": [ "nixpkgs": ["lanzaboote", "nixpkgs"],
"lanzaboote",
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
@@ -887,9 +812,7 @@
"flake-compat": "flake-compat_2", "flake-compat": "flake-compat_2",
"flake-utils": "flake-utils_4", "flake-utils": "flake-utils_4",
"gitignore": "gitignore_3", "gitignore": "gitignore_3",
"nixpkgs": [ "nixpkgs": ["nixpkgs"],
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable_2" "nixpkgs-stable": "nixpkgs-stable_2"
}, },
"locked": { "locked": {
@@ -934,14 +857,8 @@
}, },
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"flake-utils": [ "flake-utils": ["lanzaboote", "flake-utils"],
"lanzaboote", "nixpkgs": ["lanzaboote", "nixpkgs"]
"flake-utils"
],
"nixpkgs": [
"lanzaboote",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1682129965, "lastModified": 1682129965,
@@ -960,10 +877,7 @@
"rust-overlay_2": { "rust-overlay_2": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_3", "flake-utils": "flake-utils_3",
"nixpkgs": [ "nixpkgs": ["nuenv", "nixpkgs"]
"nuenv",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1701397143, "lastModified": 1701397143,
@@ -1108,18 +1022,9 @@
}, },
"xdph": { "xdph": {
"inputs": { "inputs": {
"hyprland-protocols": [ "hyprland-protocols": ["hyprland", "hyprland-protocols"],
"hyprland", "nixpkgs": ["hyprland", "nixpkgs"],
"hyprland-protocols" "systems": ["hyprland", "systems"]
],
"nixpkgs": [
"hyprland",
"nixpkgs"
],
"systems": [
"hyprland",
"systems"
]
}, },
"locked": { "locked": {
"lastModified": 1700508250, "lastModified": 1700508250,

View File

@@ -52,12 +52,11 @@
} }
); );
devShells = forEachSystem ( devShells = forEachSystem (
system: system: let
let pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
in in {
{
default = pkgs.mkShell { default = pkgs.mkShell {
packages = with pkgs;[ packages = with pkgs; [
# fix https://discourse.nixos.org/t/non-interactive-bash-errors-from-flake-nix-mkshell/33310 # fix https://discourse.nixos.org/t/non-interactive-bash-errors-from-flake-nix-mkshell/33310
bashInteractive bashInteractive
# fix `cc` replaced by clang, which causes nvim-treesitter compilation error # fix `cc` replaced by clang, which causes nvim-treesitter compilation error
@@ -101,8 +100,7 @@
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
# for macos # for macos
# nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-23.11-darwin"; nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-23.11-darwin";
nixpkgs-darwin.url = "github:nixos/nixpkgs/nixos-unstable";
nix-darwin = { nix-darwin = {
url = "github:lnl7/nix-darwin"; url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs-darwin"; inputs.nixpkgs.follows = "nixpkgs-darwin";

View File

@@ -71,6 +71,13 @@
options = ["subvol=@nix" "noatime" "compress-force=zstd:1"]; options = ["subvol=@nix" "noatime" "compress-force=zstd:1"];
}; };
# for guix store, which use `/gnu/store` as its store directory.
fileSystems."/gnu" = {
device = "/dev/disk/by-uuid/1167076c-dee1-486c-83c1-4b1af37555cd";
fsType = "btrfs";
options = ["subvol=@guix" "noatime" "compress-force=zstd:1"];
};
fileSystems."/persistent" = { fileSystems."/persistent" = {
device = "/dev/disk/by-uuid/1167076c-dee1-486c-83c1-4b1af37555cd"; device = "/dev/disk/by-uuid/1167076c-dee1-486c-83c1-4b1af37555cd";
fsType = "btrfs"; fsType = "btrfs";

View File

@@ -1,10 +1,3 @@
{ {mylib, ...}: {
imports = [ imports = mylib.scanPaths ./.;
./fonts.nix
./graphic.nix
./misc.nix
./peripherals.nix
./security.nix
./visualisation.nix
];
} }

View File

@@ -0,0 +1,21 @@
{
# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/guix/default.nix
services.guix = {
enable = true;
# The store directory where the Guix service will serve to/from.
# NOTE: most of the cached builds are assumed to be in `/gnu/store`.
storeDir = "/gnu/store";
# The state directory where Guix service will store its data such as its
# user-specific profiles, cache, and state files.
stateDir = "/var";
gc = {
enable = true;
# https://guix.gnu.org/en/manual/en/html_node/Invoking-guix-gc.html
extraArgs = [
"--delete-generations=1m"
"--free-space=10G"
"--optimize"
];
};
};
}

View File

@@ -106,6 +106,7 @@ mkfs.btrfs -L crypted-nixos /dev/mapper/crypted-nixos # create-btrfs
# mount the root partition and create subvolumes # mount the root partition and create subvolumes
mount /dev/mapper/crypted-nixos /mnt # create-btrfs mount /dev/mapper/crypted-nixos /mnt # create-btrfs
btrfs subvolume create /mnt/@nix # create-btrfs btrfs subvolume create /mnt/@nix # create-btrfs
btrfs subvolume create /mnt/@guix # create-btrfs
btrfs subvolume create /mnt/@tmp # create-btrfs btrfs subvolume create /mnt/@tmp # create-btrfs
btrfs subvolume create /mnt/@swap # create-btrfs btrfs subvolume create /mnt/@swap # create-btrfs
btrfs subvolume create /mnt/@persistent # create-btrfs btrfs subvolume create /mnt/@persistent # create-btrfs
@@ -122,6 +123,7 @@ umount /mnt # create-btrfs
# 2. Save the disk space. # 2. Save the disk space.
mkdir /mnt/{nix,tmp,swap,persistent,snapshots,boot} # mount-1 mkdir /mnt/{nix,tmp,swap,persistent,snapshots,boot} # mount-1
mount -o compress-force=zstd:1,noatime,subvol=@nix /dev/mapper/crypted-nixos /mnt/nix # mount-1 mount -o compress-force=zstd:1,noatime,subvol=@nix /dev/mapper/crypted-nixos /mnt/nix # mount-1
mount -o compress-force=zstd:1,noatime,subvol=@guix /dev/mapper/crypted-nixos /mnt/gnu # mount-1
mount -o compress-force=zstd:1,subvol=@tmp /dev/mapper/crypted-nixos /mnt/tmp # mount-1 mount -o compress-force=zstd:1,subvol=@tmp /dev/mapper/crypted-nixos /mnt/tmp # mount-1
mount -o subvol=@swap /dev/mapper/crypted-nixos /mnt/swap # mount-1 mount -o subvol=@swap /dev/mapper/crypted-nixos /mnt/swap # mount-1
mount -o compress-force=zstd:1,noatime,subvol=@persistent /dev/mapper/crypted-nixos /mnt/persistent # mount-1 mount -o compress-force=zstd:1,noatime,subvol=@persistent /dev/mapper/crypted-nixos /mnt/persistent # mount-1