Compare commits
100 Commits
f05a3af30d
...
wrappers
| Author | SHA1 | Date | |
|---|---|---|---|
| 35bd80424d | |||
| 3447b28af1 | |||
| 2fea8238d1 | |||
| cf1174d36b | |||
| bae2b3027e | |||
| 68483c0231 | |||
| f0eba76e49 | |||
| 8357372b39 | |||
| 3c4aa74b0f | |||
| ed473ddfae | |||
| 133bad5aef | |||
| 3fc08793fe | |||
| 7f4fdcf4b9 | |||
| bfc5da791a | |||
| 9a09399ca3 | |||
| cf90d3e876 | |||
| 443020df4d | |||
| 3fc3beb4ed | |||
| 43ae292f39 | |||
| 026bf541e1 | |||
| e75951318d | |||
| bd236ed977 | |||
| b07bf102a4 | |||
| 9bfe140367 | |||
| 545a17586e | |||
| 685c1bc05a | |||
| a4f988c223 | |||
| a05de7df1f | |||
| aace1776d5 | |||
| 03965917ea | |||
| dac6b70445 | |||
| 932616177a | |||
| c1bfa64cc8 | |||
| 235cd297c5 | |||
| 0c91b1d493 | |||
| 9825270d64 | |||
| ee9573fc97 | |||
| d47394d4cc | |||
| 0abbcf0fd2 | |||
| 718aa466b6 | |||
| 916fd41555 | |||
| 65608646bb | |||
| 1278177e4d | |||
| f36bb22635 | |||
| fe24eb2dde | |||
| e9d585f8d0 | |||
| 93e58c341d | |||
| b8c73b446c | |||
| 58816b2356 | |||
| ca2f5ac7c8 | |||
| 904dd6e329 | |||
| 8073125f3e | |||
| f24a269af3 | |||
| a5a10772d1 | |||
| 510a026de7 | |||
| dd47ae94bf | |||
| 244519f406 | |||
| 213d97d13e | |||
| 51a2b8078f | |||
| 5d5ad75c06 | |||
| e63ca7b244 | |||
| ff7d03ecfd | |||
| c6b1361a68 | |||
| 934aeb429c | |||
| dbbdf8991f | |||
| 70315d5020 | |||
| 7080410c0c | |||
| 35e1d5ee61 | |||
| ec5ff115ce | |||
| 58066d2a08 | |||
| bf478b5f38 | |||
| e18c28905d | |||
| e8ac1fb552 | |||
| 630e385fb1 | |||
| 6df0f8d1ab | |||
| c044f2aa5a | |||
| 1caf0fa10d | |||
| 5cb1c88e51 | |||
| 5fcd6abdb2 | |||
| e59aa7a5f1 | |||
| bf9c3c2597 | |||
| 151512a071 | |||
| 8141662832 | |||
| 1196d69778 | |||
| c1e00a7c45 | |||
| fe19700514 | |||
| 25ea6ac502 | |||
| 01fde39946 | |||
| 84b32cea01 | |||
| bccb96a0b3 | |||
| 44fd737afe | |||
| 0854439bdf | |||
| ff70a35078 | |||
| b8b8a445f9 | |||
| 13a841c8db | |||
| 6c26e898b2 | |||
| 710f13ace4 | |||
| 1a7a1189e7 | |||
| ff74205c57 | |||
| 32b7932916 |
Generated
+31
-45
@@ -18,11 +18,11 @@
|
|||||||
},
|
},
|
||||||
"flake-file": {
|
"flake-file": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1774886516,
|
"lastModified": 1776202746,
|
||||||
"narHash": "sha256-w2LoQVM6DXrSdGUZBZqa1nYkMzHoB0t82DrptzZKhTs=",
|
"narHash": "sha256-RZVtJefKKy3Z2UvKWSbtRF3cUxt/2fHga2adN6MZQ1U=",
|
||||||
"owner": "vic",
|
"owner": "vic",
|
||||||
"repo": "flake-file",
|
"repo": "flake-file",
|
||||||
"rev": "3daadf37de2bb85b0ff34e2a7ab0d71e077c2b9e",
|
"rev": "7d16dfaeb912d5efdff0d0eda2aabc0c934168dd",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -95,11 +95,11 @@
|
|||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1775080052,
|
"lastModified": 1776562531,
|
||||||
"narHash": "sha256-jAB4ZZbx8ECu9GcE/PUUwT+wpooZ0Ssmn2imB8PVTdM=",
|
"narHash": "sha256-Lh5Ns9DI67E+lSMOCGK0S+mFPy0mz0yOGiJTUXiR9JI=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "6267895e9898399f0ce2fe79b645e9ee4858aaff",
|
"rev": "5b56ad02dc643808b8af6d5f3ff179e2ce9593f4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -184,11 +184,11 @@
|
|||||||
"nixos-hardware": {
|
"nixos-hardware": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1774933469,
|
"lastModified": 1775490113,
|
||||||
"narHash": "sha256-OrnCQeUO2bqaWUl0lkDWyGWjKsOhtCyd7JSfTedQNUE=",
|
"narHash": "sha256-2ZBhDNZZwYkRmefK5XLOusCJHnoeKkoN95hoSGgMxWM=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixos-hardware",
|
"repo": "nixos-hardware",
|
||||||
"rev": "f4c4c2c0c923d7811ac2a63ccc154767e4195337",
|
"rev": "c775c2772ba56e906cbeb4e0b2db19079ef11ff7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -199,11 +199,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1774709303,
|
"lastModified": 1775423009,
|
||||||
"narHash": "sha256-D3Q07BbIA2KnTcSXIqqu9P586uWxN74zNoCH3h2ESHg=",
|
"narHash": "sha256-vPKLpjhIVWdDrfiUM8atW6YkIggCEKdSAlJPzzhkQlw=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "8110df5ad7abf5d4c0f6fb0f8f978390e77f9685",
|
"rev": "68d8aa3d661f0e6bd5862291b5bb263b2a6595c9",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -215,33 +215,17 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1775064974,
|
"lastModified": 1776329215,
|
||||||
"narHash": "sha256-PqhsO5qloSyvATi9qAIrgUcEFK67xSoacjacPw+t4H0=",
|
"narHash": "sha256-mBqzkn7oJti2hqeO8iTbDxKw+1ifxpP53feQ0CEXies=",
|
||||||
"rev": "6ebfbc38bdc6b22822a6f991f2d922306f33cfbc",
|
"rev": "b86751bc4085f48661017fa226dee99fab6c651b",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.05pre973084.6ebfbc38bdc6/nixexprs.tar.xz"
|
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.05pre981196.b86751bc4085/nixexprs.tar.xz"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"
|
"url": "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs_3": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1774610258,
|
|
||||||
"narHash": "sha256-HaThtroVD9wRdx7KQk0B75JmFcXlMUoEdDFNOMOlsOs=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "832efc09b4caf6b4569fbf9dc01bec3082a00611",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixpkgs-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nvf": {
|
"nvf": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-compat": "flake-compat",
|
"flake-compat": "flake-compat",
|
||||||
@@ -254,11 +238,11 @@
|
|||||||
"systems": "systems_2"
|
"systems": "systems_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1774852850,
|
"lastModified": 1776608870,
|
||||||
"narHash": "sha256-7VK4v7ZbQw5apfgc+FvgRi8BUC45ERlcp8VTTTQ3tko=",
|
"narHash": "sha256-lBKrueFu15TdmtMF6GsiSVCifwdrUBYFoa3+zZjYTFM=",
|
||||||
"owner": "notashelf",
|
"owner": "notashelf",
|
||||||
"repo": "nvf",
|
"repo": "nvf",
|
||||||
"rev": "b4d6539e7e9948aaba5efd7a67a63672d1fa80ef",
|
"rev": "d9ba7f0a9ed6c016dc9e526cc606d1a2f7898cd4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -292,11 +276,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1774910634,
|
"lastModified": 1776119890,
|
||||||
"narHash": "sha256-B+rZDPyktGEjOMt8PcHKYmgmKoF+GaNAFJhguktXAo0=",
|
"narHash": "sha256-Zm6bxLNnEOYuS/SzrAGsYuXSwk3cbkRQZY0fJnk8a5M=",
|
||||||
"owner": "Mic92",
|
"owner": "Mic92",
|
||||||
"repo": "sops-nix",
|
"repo": "sops-nix",
|
||||||
"rev": "19bf3d8678fbbfbc173beaa0b5b37d37938db301",
|
"rev": "d4971dd58c6627bfee52a1ad4237637c0a2fb0cd",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -337,14 +321,16 @@
|
|||||||
},
|
},
|
||||||
"wrapper-modules": {
|
"wrapper-modules": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs_3"
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1774879171,
|
"lastModified": 1776464146,
|
||||||
"narHash": "sha256-a6JZDuBIwQmuEwYM4dziH+WyrpE8HCP8F7JFIn3CNvw=",
|
"narHash": "sha256-XwLFfJDz71vIF7BAhnbLhrzQjmDC2uXdo7N0oHUrYzA=",
|
||||||
"owner": "BirdeeHub",
|
"owner": "BirdeeHub",
|
||||||
"repo": "nix-wrapper-modules",
|
"repo": "nix-wrapper-modules",
|
||||||
"rev": "bab35ffae25cf6f4e4fdb3c2f7f0ac80966ce737",
|
"rev": "75febede14a0845f4ef429da692a0698bf433600",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -360,11 +346,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1774293387,
|
"lastModified": 1776505856,
|
||||||
"narHash": "sha256-yVekLWxKTUfUyuvo9HVihtOK8llIP3IZCrJmftxT+Nc=",
|
"narHash": "sha256-VbnOijrn4EdYYJwiNQFxQNXECKBa60U66UPxUQAGkBE=",
|
||||||
"owner": "lassulus",
|
"owner": "lassulus",
|
||||||
"repo": "wrappers",
|
"repo": "wrappers",
|
||||||
"rev": "3cf1e8371129e8746d37c863c5d56a81fb16caa0",
|
"rev": "738d4bf81cbf306f6917c540a5b798110e3cf1e8",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -29,7 +29,10 @@
|
|||||||
url = "github:Mic92/sops-nix";
|
url = "github:Mic92/sops-nix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
wrapper-modules.url = "github:BirdeeHub/nix-wrapper-modules";
|
wrapper-modules = {
|
||||||
|
url = "github:BirdeeHub/nix-wrapper-modules";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
wrappers = {
|
wrappers = {
|
||||||
url = "github:lassulus/wrappers";
|
url = "github:lassulus/wrappers";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
mangohud
|
mangohud
|
||||||
sublime4
|
sublime4
|
||||||
proton-vpn
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
flake.modules.nixos.forgejo = {config, pkgs, lib, ... }:
|
flake.modules.nixos.forgejo = {config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.forgejo;
|
cfg = config.forgejo;
|
||||||
|
needsPrivilegedPort = cfg.port < 1024;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.forgejo = {
|
options.forgejo = {
|
||||||
enable = lib.mkEnableOption "Enable Forgejo backed with PostgreSQL";
|
enable = lib.mkEnableOption "Enable Forgejo backed with PostgreSQL";
|
||||||
|
root_url = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
|
||||||
port = lib.mkOption {
|
port = lib.mkOption {
|
||||||
type = lib.types.port;
|
type = lib.types.port;
|
||||||
@@ -25,6 +29,12 @@
|
|||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ cfg.port ];
|
networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ cfg.port ];
|
||||||
|
|
||||||
|
systemd.services.forgejo.serviceConfig = lib.mkIf needsPrivilegedPort {
|
||||||
|
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
||||||
|
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
|
||||||
|
PrivateUsers = lib.mkForce false;
|
||||||
|
};
|
||||||
|
|
||||||
sops.secrets = {
|
sops.secrets = {
|
||||||
"forgejo/secret_key".owner = config.services.forgejo.user;
|
"forgejo/secret_key".owner = config.services.forgejo.user;
|
||||||
"forgejo/internal_token".owner = config.services.forgejo.user;
|
"forgejo/internal_token".owner = config.services.forgejo.user;
|
||||||
@@ -36,6 +46,7 @@
|
|||||||
forgejo = {
|
forgejo = {
|
||||||
enable = true;
|
enable = true;
|
||||||
lfs.enable = true;
|
lfs.enable = true;
|
||||||
|
database.type = "postgres";
|
||||||
settings = {
|
settings = {
|
||||||
DEFAULT = {
|
DEFAULT = {
|
||||||
RUN_MODE = "dev";
|
RUN_MODE = "dev";
|
||||||
@@ -44,7 +55,7 @@
|
|||||||
{
|
{
|
||||||
HTTP_PORT = cfg.port;
|
HTTP_PORT = cfg.port;
|
||||||
DISABLE_SSH = true;
|
DISABLE_SSH = true;
|
||||||
ROOT_URL = "https://forgejo.john-stream.com";
|
ROOT_URL = cfg.root_url;
|
||||||
}
|
}
|
||||||
(lib.mkIf cfg.https {
|
(lib.mkIf cfg.https {
|
||||||
PROTOCOL = "https";
|
PROTOCOL = "https";
|
||||||
@@ -53,6 +64,13 @@
|
|||||||
CERT_FILE = config.mtls.certFile;
|
CERT_FILE = config.mtls.certFile;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
oauth2_client = {
|
||||||
|
ENABLE_AUTO_REGISTRATION = true;
|
||||||
|
USERNAME = "nickname";
|
||||||
|
UPDATE_AVATAR = true;
|
||||||
|
ACCOUNT_LINKING = "login";
|
||||||
|
REGISTER_EMAIL_CONFIRM = false;
|
||||||
|
};
|
||||||
repository = {
|
repository = {
|
||||||
ENABLE_PUSH_CREATE_USER = true;
|
ENABLE_PUSH_CREATE_USER = true;
|
||||||
};
|
};
|
||||||
@@ -70,38 +88,41 @@
|
|||||||
oauth2.JWT_SECRET = lib.mkForce config.sops.secrets."forgejo/jwt_secret".path;
|
oauth2.JWT_SECRET = lib.mkForce config.sops.secrets."forgejo/jwt_secret".path;
|
||||||
server.LFS_JWT_SECRET = lib.mkForce config.sops.secrets."forgejo/lfs_jwt_secret".path;
|
server.LFS_JWT_SECRET = lib.mkForce config.sops.secrets."forgejo/lfs_jwt_secret".path;
|
||||||
};
|
};
|
||||||
|
dump = {
|
||||||
database = {
|
enable = true;
|
||||||
type = "postgres";
|
type = "tar";
|
||||||
port = config.services.postgresql.settings.port;
|
interval = "*-*-* 00/12:00:00";
|
||||||
# createDatabase = false;
|
|
||||||
};
|
};
|
||||||
# dump = {
|
|
||||||
# enable = true;
|
|
||||||
# interval = "12h";
|
|
||||||
# };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
postgresql = {
|
postgresql = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings = {
|
enableTCPIP = false;
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# https://forgejo.org/docs/latest/admin/command-line/#dump
|
||||||
|
systemd.services.forgejo-dump.serviceConfig.ExecStart = lib.mkForce ''
|
||||||
|
${lib.getExe config.services.forgejo.package} dump --verbose \
|
||||||
|
--type ${config.services.forgejo.dump.type} \
|
||||||
|
--database postgres \
|
||||||
|
--work-path ${config.services.forgejo.dump.backupDir}
|
||||||
|
'';
|
||||||
|
|
||||||
environment.systemPackages =
|
environment.systemPackages =
|
||||||
let
|
let
|
||||||
systemctl = lib.getExe' pkgs.systemd "systemctl";
|
systemctl = lib.getExe' pkgs.systemd "systemctl";
|
||||||
clean-forgejo = (pkgs.writeShellScriptBin "clean-forgejo" ''
|
clean-forgejo = (pkgs.writeShellScriptBin "clean-forgejo" ''
|
||||||
set -e
|
set -euo pipefail
|
||||||
${systemctl} stop forgejo.service
|
sudo ${systemctl} stop forgejo.service
|
||||||
|
${lib.getExe' pkgs.coreutils "echo"} "Stopped Forgejo"
|
||||||
sudo ${lib.getExe' pkgs.coreutils "rm"} -rf ${config.services.forgejo.stateDir}
|
sudo ${lib.getExe' pkgs.coreutils "rm"} -rf ${config.services.forgejo.stateDir}
|
||||||
${lib.getExe' pkgs.coreutils "echo"} "Removed ${config.services.forgejo.stateDir}"
|
${lib.getExe' pkgs.coreutils "echo"} "Removed ${config.services.forgejo.stateDir}"
|
||||||
'');
|
'');
|
||||||
clean-postgres = (pkgs.writeShellScriptBin "clean-postgres" ''
|
clean-postgres = (pkgs.writeShellScriptBin "clean-postgres" ''
|
||||||
set -e
|
set -euo pipefail
|
||||||
${systemctl} stop postgresql.service
|
sudo ${systemctl} stop postgresql.service
|
||||||
${lib.getExe' pkgs.coreutils "echo"} Stopped
|
${lib.getExe' pkgs.coreutils "echo"} "Stopped PostgreSQL"
|
||||||
sudo ${lib.getExe' pkgs.coreutils "rm"} -rf ${config.services.postgresql.dataDir}
|
sudo ${lib.getExe' pkgs.coreutils "rm"} -rf ${config.services.postgresql.dataDir}
|
||||||
${lib.getExe' pkgs.coreutils "echo"} "Removed ${config.services.postgresql.dataDir}"
|
${lib.getExe' pkgs.coreutils "echo"} "Removed ${config.services.postgresql.dataDir}"
|
||||||
'');
|
'');
|
||||||
@@ -109,10 +130,16 @@
|
|||||||
clean-forgejo
|
clean-forgejo
|
||||||
clean-postgres
|
clean-postgres
|
||||||
(pkgs.writeShellScriptBin "clean-all" ''
|
(pkgs.writeShellScriptBin "clean-all" ''
|
||||||
set -e
|
set -euo pipefail
|
||||||
${lib.getExe clean-forgejo}
|
GREEN_CHECK="\e[32m✔\e[0m"
|
||||||
${lib.getExe clean-postgres}
|
YELLOW_BANG="\e[33m!\e[0m"
|
||||||
${lib.getExe' pkgs.coreutils "echo"} "Removed everything related to forgejo"
|
${lib.getExe' pkgs.coreutils "echo"} -n -e "$YELLOW_BANG Remove everything related to Forgejo and the PostgreSQL database behind it?"
|
||||||
|
read -p " (y/n) " -n 1 -r
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
${lib.getExe clean-forgejo}
|
||||||
|
${lib.getExe clean-postgres}
|
||||||
|
${lib.getExe' pkgs.coreutils "echo"} -e "$GREEN_CHECK Removed everything related to forgejo"
|
||||||
|
fi
|
||||||
'')
|
'')
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
+286
-181
@@ -48,7 +48,7 @@ let
|
|||||||
enable = lib.mkOption {
|
enable = lib.mkOption {
|
||||||
description = "Enable automatic mTLS certificate renewal using a systemd timer.";
|
description = "Enable automatic mTLS certificate renewal using a systemd timer.";
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
default = true;
|
default = cfg.enable;
|
||||||
};
|
};
|
||||||
onCalendar = lib.mkOption {
|
onCalendar = lib.mkOption {
|
||||||
description = "systemd OnCalendar schedule for mTLS certificate renewal checks.";
|
description = "systemd OnCalendar schedule for mTLS certificate renewal checks.";
|
||||||
@@ -66,9 +66,9 @@ let
|
|||||||
default = "root";
|
default = "root";
|
||||||
};
|
};
|
||||||
group = lib.mkOption {
|
group = lib.mkOption {
|
||||||
description = "Group to run the mTLS renewal service as. Defaults to the configured renewal user when null.";
|
description = "Group to run the mTLS renewal service as. Defaults to the configured renewal user.";
|
||||||
type = lib.types.nullOr lib.types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = null;
|
default = "mtls";
|
||||||
};
|
};
|
||||||
reloadUnits = lib.mkOption {
|
reloadUnits = lib.mkOption {
|
||||||
description = "systemd units to try-reload-or-restart after a successful certificate renewal.";
|
description = "systemd units to try-reload-or-restart after a successful certificate renewal.";
|
||||||
@@ -92,169 +92,51 @@ let
|
|||||||
keyFile,
|
keyFile,
|
||||||
bundleFile,
|
bundleFile,
|
||||||
lifetime,
|
lifetime,
|
||||||
|
user,
|
||||||
|
group,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
stepCmd = lib.getExe pkgs.step-cli;
|
|
||||||
sanArgs = lib.concatMapStringsSep " " (s: "--san \"${s}\"") san;
|
sanArgs = lib.concatMapStringsSep " " (s: "--san \"${s}\"") san;
|
||||||
in
|
in
|
||||||
pkgs.writeShellScriptBin "mtls-generate" ''
|
pkgs.writeShellApplication {
|
||||||
set -euo pipefail
|
name = "mtls-generate";
|
||||||
${stepCmd} ca certificate \
|
runtimeInputs = with pkgs; [ coreutils step-cli ];
|
||||||
${subject} ${certFile} ${keyFile} \
|
text = ''
|
||||||
--not-before=-5m --not-after=${lifetime} \
|
set -euo pipefail
|
||||||
--provisioner ${provisioner} \
|
step ca certificate ${subject} ${certFile} ${keyFile} \
|
||||||
${sanArgs} \
|
--provisioner ${provisioner} \
|
||||||
"$@"
|
--not-before=-5m --not-after=${lifetime} \
|
||||||
cat ${certFile} ${keyFile} > ${bundleFile}
|
${sanArgs} \
|
||||||
'';
|
"$@"
|
||||||
|
(umask 077; cat ${certFile} ${keyFile} > ${bundleFile})
|
||||||
mkMtlsCheckScript = { pkgs, bundleFile }: pkgs.writeShellScriptBin "mtls-check" ''
|
chown ${user}:${group} ${certFile} ${keyFile} ${bundleFile}
|
||||||
${lib.getExe pkgs.openssl} x509 \
|
chmod 640 ${certFile} ${keyFile} ${bundleFile}
|
||||||
-noout -subject -issuer \
|
printf '\033[32m✔\033[0m \033[1mmTLS Bundle:\033[0m %s\n' ${lib.escapeShellArg bundleFile}
|
||||||
-ext subjectAltName,extendedKeyUsage \
|
'';
|
||||||
-enddate -in ${bundleFile}
|
|
||||||
'';
|
|
||||||
|
|
||||||
mkMtlsRenewScript = {
|
|
||||||
pkgs,
|
|
||||||
certFile,
|
|
||||||
keyFile,
|
|
||||||
bundleFile,
|
|
||||||
reloadUnits ? [ ],
|
|
||||||
postCommands ? [ ],
|
|
||||||
systemctlArgs ? [ ],
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
echoCmd = lib.getExe' pkgs.coreutils "echo";
|
|
||||||
systemctl = lib.getExe' pkgs.systemd "systemctl";
|
|
||||||
escapedArgs = lib.escapeShellArgs systemctlArgs;
|
|
||||||
systemctlCommand = "${systemctl} ${escapedArgs}";
|
|
||||||
renewReloadScript = lib.concatMapStringsSep "\n" (unit: ''
|
|
||||||
if ${systemctlCommand} --quiet is-active "${unit}"; then
|
|
||||||
${systemctlCommand} try-reload-or-restart "${unit}"
|
|
||||||
fi
|
|
||||||
'') reloadUnits;
|
|
||||||
renewPostCommands = lib.concatStringsSep "\n" postCommands;
|
|
||||||
in
|
|
||||||
pkgs.writeShellScriptBin "mtls-renew" ''
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
if ${lib.getExe pkgs.step-cli} certificate needs-renewal "${certFile}"; then
|
|
||||||
${echoCmd} "Renewing mTLS certificate"
|
|
||||||
else
|
|
||||||
${echoCmd} "Skipping renew"
|
|
||||||
exit "$?"
|
|
||||||
fi
|
|
||||||
|
|
||||||
${lib.getExe pkgs.step-cli} ca renew --force "${certFile}" "${keyFile}"
|
|
||||||
|
|
||||||
umask 077
|
|
||||||
${lib.getExe' pkgs.coreutils "cat"} "${certFile}" "${keyFile}" > "${bundleFile}"
|
|
||||||
|
|
||||||
${echoCmd} "Reloading units:"
|
|
||||||
${renewReloadScript}
|
|
||||||
|
|
||||||
${echoCmd} "Post commands:"
|
|
||||||
${renewPostCommands}
|
|
||||||
'';
|
|
||||||
|
|
||||||
mkNixosMtlsRenewService = {
|
|
||||||
pkgs,
|
|
||||||
certFile,
|
|
||||||
keyFile,
|
|
||||||
bundleFile,
|
|
||||||
reloadUnits ? [ ],
|
|
||||||
postCommands ? [ ],
|
|
||||||
user ? "root",
|
|
||||||
group ? null,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
serviceGroup = if group == null then user else group;
|
|
||||||
renewScript = mkMtlsRenewScript {
|
|
||||||
inherit pkgs certFile keyFile bundleFile reloadUnits postCommands;
|
|
||||||
};
|
};
|
||||||
in
|
|
||||||
{
|
|
||||||
description = "Renew the mTLS certificate when Smallstep marks it ready";
|
|
||||||
wantedBy = [ ];
|
|
||||||
after = [ "network-online.target" ];
|
|
||||||
wants = [ "network-online.target" ];
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "oneshot";
|
|
||||||
User = user;
|
|
||||||
Group = serviceGroup;
|
|
||||||
ExecStart = lib.getExe renewScript;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mkNixosMtlsRenewTimer = {
|
|
||||||
onCalendar,
|
|
||||||
randomizedDelaySec,
|
|
||||||
unit ? "mtls-renew.service",
|
|
||||||
}: {
|
|
||||||
description = "Periodic Smallstep renewal for the mTLS certificate";
|
|
||||||
wantedBy = [ "timers.target" ];
|
|
||||||
timerConfig = {
|
|
||||||
Persistent = true;
|
|
||||||
OnCalendar = onCalendar;
|
|
||||||
AccuracySec = "1us";
|
|
||||||
RandomizedDelaySec = randomizedDelaySec;
|
|
||||||
Unit = unit;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mkHomeManagerMtlsRenewService = {
|
|
||||||
pkgs,
|
|
||||||
certFile,
|
|
||||||
keyFile,
|
|
||||||
bundleFile,
|
|
||||||
reloadUnits ? [ ],
|
|
||||||
postCommands ? [ ],
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
renewScript = mkMtlsRenewScript {
|
|
||||||
inherit pkgs certFile keyFile bundleFile reloadUnits postCommands;
|
|
||||||
systemctlArgs = [ "--user" ];
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
Unit = {
|
|
||||||
Description = "Renew the mTLS certificate when Smallstep marks it ready";
|
|
||||||
After = [ "network-online.target" ];
|
|
||||||
Wants = [ "network-online.target" ];
|
|
||||||
};
|
|
||||||
Service = {
|
|
||||||
Type = "oneshot";
|
|
||||||
ExecStart = lib.getExe renewScript;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mkHomeManagerMtlsRenewTimer = {
|
|
||||||
onCalendar,
|
|
||||||
randomizedDelaySec,
|
|
||||||
unit ? "mtls-renew.service",
|
|
||||||
}: {
|
|
||||||
Unit = {
|
|
||||||
Description = "Periodic Smallstep renewal for the mTLS certificate";
|
|
||||||
};
|
|
||||||
Timer = {
|
|
||||||
Persistent = true;
|
|
||||||
OnCalendar = onCalendar;
|
|
||||||
AccuracySec = "1us";
|
|
||||||
RandomizedDelaySec = randomizedDelaySec;
|
|
||||||
Unit = unit;
|
|
||||||
};
|
|
||||||
Install = {
|
|
||||||
WantedBy = [ "timers.target" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.modules.nixos.mtls = { config, lib, pkgs, ... }:
|
flake.modules.nixos.mtls = { config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.mtls;
|
cfg = config.mtls;
|
||||||
sanArgs = lib.concatMapStringsSep " " (san: "--san \"${san}\"") cfg.san;
|
mtlsRenewWrapper = inputs.self.wrappers.mtlsRenew.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
inherit (cfg) certDir keyFile certFile bundleFile;
|
||||||
|
inherit (cfg.renew) user group reloadUnits postCommands;
|
||||||
|
systemd = {
|
||||||
|
description = "Renew the mTLS certificate when Smallstep marks it ready";
|
||||||
|
after = [ "network-online.target" ];
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = cfg.renew.user;
|
||||||
|
Group = cfg.renew.group;
|
||||||
|
};
|
||||||
|
} // lib.optionalAttrs cfg.renew.enable {
|
||||||
|
startAt = cfg.renew.onCalendar;
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.mtls = (mkOpts config) // {
|
options.mtls = (mkOpts config) // {
|
||||||
@@ -263,42 +145,64 @@ in
|
|||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "/etc/step-ca/certs";
|
default = "/etc/step-ca/certs";
|
||||||
};
|
};
|
||||||
|
certReaders = lib.mkOption {
|
||||||
|
description = "";
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
users.groups.certReaders = {
|
||||||
|
name = cfg.renew.group;
|
||||||
|
members = cfg.certReaders;
|
||||||
|
};
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; lib.optionals cfg.enable [
|
environment.systemPackages = with pkgs; lib.optionals cfg.enable [
|
||||||
# step-cli
|
# step-cli
|
||||||
(mkMtlsGenerateScript {
|
(mkMtlsGenerateScript {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
inherit (cfg) subject provisioner san certFile keyFile bundleFile lifetime;
|
inherit (cfg) subject provisioner san certFile keyFile bundleFile lifetime;
|
||||||
|
inherit (cfg.renew) user group;
|
||||||
})
|
})
|
||||||
(mkMtlsCheckScript { inherit pkgs; inherit (cfg) bundleFile; })
|
(inputs.self.wrappers.mtlsCheck.apply {
|
||||||
(mkMtlsRenewScript { inherit pkgs; inherit (cfg) certFile keyFile bundleFile; })
|
inherit pkgs;
|
||||||
|
inherit (cfg) bundleFile;
|
||||||
|
}).wrapper
|
||||||
|
mtlsRenewWrapper.wrapper
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
"d ${cfg.certDir} 0750 ${cfg.renew.user} ${if cfg.renew.group == null then cfg.renew.user else cfg.renew.group} -"
|
"d ${cfg.certDir} 0750 ${cfg.renew.user} ${cfg.renew.group} -"
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services.mtls-renew = lib.mkIf cfg.renew.enable (mkNixosMtlsRenewService {
|
systemd.packages = lib.mkIf cfg.renew.enable [
|
||||||
inherit pkgs;
|
mtlsRenewWrapper.outputs.systemd-system
|
||||||
inherit (cfg) certFile keyFile bundleFile;
|
];
|
||||||
inherit (cfg.renew) reloadUnits postCommands user group;
|
|
||||||
});
|
|
||||||
|
|
||||||
systemd.timers.mtls-renew = lib.mkIf cfg.renew.enable (mkNixosMtlsRenewTimer {
|
systemd.timers.mtls-renew = lib.mkIf cfg.renew.enable {
|
||||||
inherit (cfg.renew) onCalendar randomizedDelaySec;
|
wantedBy = [ "timers.target" ];
|
||||||
});
|
timerConfig = {
|
||||||
|
Persistent = true;
|
||||||
|
AccuracySec = "1us";
|
||||||
|
RandomizedDelaySec = cfg.renew.randomizedDelaySec;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.modules.homeManager.mtls = { config, lib, pkgs, ... }:
|
flake.modules.homeManager.mtls = { config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.mtls;
|
cfg = config.mtls;
|
||||||
keyFile = cfg.keyFile;
|
mtlsRenewWrapper = inputs.self.wrappers.mtlsRenew.apply {
|
||||||
certFile = cfg.certFile;
|
inherit pkgs;
|
||||||
bundleFile = cfg.bundleFile;
|
inherit (cfg) certDir keyFile certFile bundleFile;
|
||||||
sanArgs = lib.concatMapStringsSep " " (san: "--san \"${san}\"") cfg.san;
|
inherit (cfg.renew) reloadUnits postCommands;
|
||||||
|
systemctlArgs = [ "--user" ];
|
||||||
|
systemd = lib.optionalAttrs cfg.renew.enable {
|
||||||
|
startAt = cfg.renew.onCalendar;
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.mtls = (mkOpts config) // {
|
options.mtls = (mkOpts config) // {
|
||||||
@@ -313,25 +217,226 @@ in
|
|||||||
home.packages = with pkgs; lib.optionals cfg.enable [
|
home.packages = with pkgs; lib.optionals cfg.enable [
|
||||||
# step-cli
|
# step-cli
|
||||||
(mkMtlsGenerateScript {
|
(mkMtlsGenerateScript {
|
||||||
|
inherit pkgs;
|
||||||
|
inherit (cfg) keyFile certFile bundleFile;
|
||||||
inherit (cfg) subject provisioner san lifetime;
|
inherit (cfg) subject provisioner san lifetime;
|
||||||
inherit pkgs certFile keyFile bundleFile;
|
inherit (cfg.renew) user group;
|
||||||
})
|
})
|
||||||
(mkMtlsCheckScript { inherit pkgs bundleFile; })
|
(inputs.self.wrappers.mtlsCheck.apply {
|
||||||
(mkMtlsRenewScript { inherit pkgs certFile keyFile bundleFile; })
|
inherit pkgs;
|
||||||
|
inherit (cfg) bundleFile;
|
||||||
|
}).wrapper
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.user.tmpfiles.rules = lib.mkIf cfg.enable [
|
systemd.user.tmpfiles.rules = lib.mkIf cfg.enable [
|
||||||
"d ${cfg.certDir} 0700 - - -"
|
"d ${cfg.certDir} 0700 - - -" # Ensure the cert directory exists and is writable by the user
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.user.services.mtls-renew = lib.mkIf cfg.renew.enable (mkHomeManagerMtlsRenewService {
|
# Create the systemd service files for the user.
|
||||||
inherit pkgs certFile keyFile bundleFile;
|
xdg.dataFile = lib.mkIf cfg.renew.enable {
|
||||||
inherit (cfg.renew) reloadUnits postCommands;
|
"systemd/user/mtls-renew.service".source =
|
||||||
});
|
"${mtlsRenewWrapper.outputs.systemd-user}/systemd/user/mtls-renew.service";
|
||||||
|
"systemd/user/mtls-renew.timer".source =
|
||||||
|
"${mtlsRenewWrapper.outputs.systemd-user}/systemd/user/mtls-renew.timer";
|
||||||
|
"systemd/user/mtls-renew.timer.d/override.conf".text = ''
|
||||||
|
[Timer]
|
||||||
|
Persistent=true
|
||||||
|
AccuracySec=1us
|
||||||
|
RandomizedDelaySec=${cfg.renew.randomizedDelaySec}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
systemd.user.timers.mtls-renew = lib.mkIf cfg.renew.enable (mkHomeManagerMtlsRenewTimer {
|
# Ensure the timer gets started
|
||||||
inherit (cfg.renew) onCalendar randomizedDelaySec;
|
home.activation.mtlsRenewTimer = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||||
});
|
if [ -n "$XDG_RUNTIME_DIR" ] && [ -S "$XDG_RUNTIME_DIR/systemd/private" ]; then
|
||||||
|
if [ "${lib.boolToString (cfg.enable && cfg.renew.enable)}" = "true" ]; then
|
||||||
|
run ${pkgs.systemd}/bin/systemctl --user daemon-reload
|
||||||
|
run ${pkgs.systemd}/bin/systemctl --user enable --now mtls-renew.timer
|
||||||
|
else
|
||||||
|
run ${pkgs.systemd}/bin/systemctl --user disable --now mtls-renew.timer || true
|
||||||
|
run ${pkgs.systemd}/bin/systemctl --user daemon-reload || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
flake.wrappers = {
|
||||||
|
mtlsCheck = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
bundleFile = lib.mkOption {
|
||||||
|
description = "String path for the mTLS key bundle";
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "mtls-check";
|
||||||
|
# This pattern is necessary to wrap packages like openssl that provide more than one binary
|
||||||
|
package = config.pkgs.symlinkJoin {
|
||||||
|
name = "openssl";
|
||||||
|
paths = [ config.pkgs.openssl.bin config.pkgs.openssl.man ];
|
||||||
|
meta.mainProgram = "openssl";
|
||||||
|
};
|
||||||
|
args = [
|
||||||
|
"x509"
|
||||||
|
"-noout"
|
||||||
|
"-in" config.bundleFile
|
||||||
|
"-subject"
|
||||||
|
"-issuer"
|
||||||
|
"-ext" "subjectAltName,extendedKeyUsage"
|
||||||
|
"-enddate"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
mtlsNeedsRenewal = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
certFile = lib.mkOption {
|
||||||
|
description = "String path for the public cert";
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "mtls-needs-renewal";
|
||||||
|
package = config.pkgs.step-cli;
|
||||||
|
preHook = ''
|
||||||
|
echo "Checking renewal status..."
|
||||||
|
'';
|
||||||
|
args = [ "certificate" "needs-renewal" "${config.certFile}" ];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
mtlsRenew = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
|
||||||
|
imports = [ wlib.modules.systemd ];
|
||||||
|
|
||||||
|
options = {
|
||||||
|
certDir = lib.mkOption {
|
||||||
|
description = "String path to the directory where the certs will be stored";
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
keyFile = lib.mkOption {
|
||||||
|
description = "String path for the private key";
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "${config.certDir}/key.pem";
|
||||||
|
};
|
||||||
|
certFile = lib.mkOption {
|
||||||
|
description = "String path for the public cert";
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "${config.certDir}/cert.pem";
|
||||||
|
};
|
||||||
|
bundleFile = lib.mkOption {
|
||||||
|
description = "String path for the mTLS key bundle";
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "${config.certDir}/mtls.pem";
|
||||||
|
};
|
||||||
|
user = lib.mkOption {
|
||||||
|
description = "User that should own the renewed certificate files.";
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
group = lib.mkOption {
|
||||||
|
description = "Group that should own the renewed certificate files.";
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
reloadUnits = lib.mkOption {
|
||||||
|
description = "systemd units to try-reload-or-restart after a successful renewal.";
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
postCommands = lib.mkOption {
|
||||||
|
description = "Shell commands to run after a successful renewal.";
|
||||||
|
type = lib.types.listOf lib.types.lines;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
systemctlArgs = lib.mkOption {
|
||||||
|
description = "Additional arguments to pass to systemctl when reloading units.";
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "mtls-renew";
|
||||||
|
package = let
|
||||||
|
systemctlCmd = "systemctl ${lib.escapeShellArgs config.systemctlArgs}";
|
||||||
|
|
||||||
|
hasReloadUnits = config.reloadUnits != [ ];
|
||||||
|
renewReloadScript = lib.concatMapStringsSep "\n" (unit: ''
|
||||||
|
if ${systemctlCmd} --quiet is-active "${unit}"; then
|
||||||
|
${systemctlCmd} try-reload-or-restart "${unit}"
|
||||||
|
fi
|
||||||
|
'') config.reloadUnits;
|
||||||
|
|
||||||
|
hasPostCommands = config.postCommands != [ ];
|
||||||
|
renewPostCommands = lib.concatStringsSep "\n" config.postCommands;
|
||||||
|
|
||||||
|
hasOwnership = config.user != null && config.group != null;
|
||||||
|
in
|
||||||
|
config.pkgs.writeShellApplication {
|
||||||
|
name = "mtls-renew";
|
||||||
|
runtimeInputs = with config.pkgs; [ coreutils step-cli systemd ];
|
||||||
|
text = ''
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
YELLOW_BANG="\e[33m!\e[0m"
|
||||||
|
|
||||||
|
force=0
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
--force)
|
||||||
|
force=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "$YELLOW_BANG Warning: ignoring unrecognized argument '$1'"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $force -eq 0 ]] && ! step certificate needs-renewal "${config.certFile}"; then
|
||||||
|
echo "Skipping renew"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Renewing mTLS certificate"
|
||||||
|
step ca renew --force "${config.certFile}" "${config.keyFile}"
|
||||||
|
(umask 077; cat "${config.certFile}" "${config.keyFile}" > "${config.bundleFile}")
|
||||||
|
|
||||||
|
${lib.optionalString hasOwnership ''
|
||||||
|
chown ${config.user}:${config.group} ${config.certFile} ${config.keyFile} ${config.bundleFile}
|
||||||
|
chmod 640 ${config.certFile} ${config.keyFile} ${config.bundleFile}
|
||||||
|
''}
|
||||||
|
|
||||||
|
${lib.optionalString hasReloadUnits ''
|
||||||
|
echo "Reloading units: ${lib.concatStringsSep ", " config.reloadUnits}"
|
||||||
|
${renewReloadScript}
|
||||||
|
''}
|
||||||
|
|
||||||
|
${lib.optionalString hasPostCommands ''
|
||||||
|
echo "Running post commands"
|
||||||
|
${renewPostCommands}
|
||||||
|
''}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
extraPackages = [
|
||||||
|
config.pkgs.step-cli
|
||||||
|
];
|
||||||
|
systemd = {
|
||||||
|
description = "Automatic mTLS renewal service";
|
||||||
|
documentation = [
|
||||||
|
"https://smallstep.com/docs/step-ca/certificate-authority-server-production"
|
||||||
|
];
|
||||||
|
startLimitIntervalSec = 0;
|
||||||
|
after = [ "network-online.target" ];
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
|
serviceConfig.Type = lib.mkDefault "oneshot";
|
||||||
|
# serviceConfig.ExecCondition = "";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -1,40 +1,63 @@
|
|||||||
# This module provides all the shell options
|
# This module provides all the shell options
|
||||||
{ inputs, lib, ... }:
|
{ self, inputs, ... }: {
|
||||||
{
|
|
||||||
flake.modules.homeManager.shell-tools = { config, pkgs, ... }: {
|
flake.modules.homeManager.shell-tools = { config, pkgs, ... }: {
|
||||||
options.shell.program = lib.mkOption {
|
|
||||||
type = lib.types.enum [ "bash" "zsh" ];
|
|
||||||
default = "zsh";
|
|
||||||
description = "Which interactive shell configuration to enable.";
|
|
||||||
};
|
|
||||||
|
|
||||||
imports = with inputs.self.modules.homeManager; [
|
imports = with inputs.self.modules.homeManager; [
|
||||||
bash
|
# bash
|
||||||
zsh
|
zsh
|
||||||
|
|
||||||
# Tools
|
|
||||||
eza
|
|
||||||
files
|
files
|
||||||
];
|
];
|
||||||
|
|
||||||
config = {
|
home.packages = with pkgs; [
|
||||||
home.shell.enableShellIntegration = true;
|
btop
|
||||||
programs.zsh.enable = lib.mkForce (config.shell.program == "zsh");
|
uv
|
||||||
home.packages = with pkgs; [
|
xclip
|
||||||
wget
|
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.shell-tools
|
||||||
curl
|
];
|
||||||
busybox
|
|
||||||
gnugrep
|
home.shell.enableShellIntegration = true;
|
||||||
dig
|
};
|
||||||
btop
|
|
||||||
uv
|
perSystem = { system, pkgs, self', ... }: {
|
||||||
xclip
|
packages.shell-tools = inputs.wrappers.lib.wrapPackage {
|
||||||
jq
|
inherit pkgs;
|
||||||
ripgrep
|
# binName = "show-tools";
|
||||||
(writeShellScriptBin "ds" ''
|
package = (pkgs.symlinkJoin {
|
||||||
${lib.getExe pkgs.gdu} -x -I /snap /
|
name = "show-tools";
|
||||||
'')
|
meta.mainProgram = "show-tools";
|
||||||
];
|
paths = with pkgs; [
|
||||||
|
nh
|
||||||
|
ripgrep
|
||||||
|
fd
|
||||||
|
jq
|
||||||
|
wget
|
||||||
|
curl
|
||||||
|
dig
|
||||||
|
self'.packages.gdu
|
||||||
|
self'.packages.my-eza
|
||||||
|
hostname
|
||||||
|
iproute2
|
||||||
|
direnv
|
||||||
|
(writeShellApplication {
|
||||||
|
name = "show-tools";
|
||||||
|
text = ''
|
||||||
|
IFS=':' read -r -a path_dirs <<< "''${PATH:-}"
|
||||||
|
|
||||||
|
for dir in "''${path_dirs[@]}"; do
|
||||||
|
[[ "$dir" == */bin ]] || continue
|
||||||
|
[[ -d "$dir" ]] || continue
|
||||||
|
|
||||||
|
printf '%s\n' "$dir"/*
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
packages.gdu = inputs.wrappers.lib.wrapPackage {
|
||||||
|
inherit pkgs;
|
||||||
|
package = pkgs.gdu;
|
||||||
|
args = [ "-x" "--si" "--collapse-path" "--mouse" "$@" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
{ self, inputs, ... }:
|
||||||
|
let
|
||||||
|
mkPrincipalArgs = principals:
|
||||||
|
builtins.concatLists (map (principal: [ "--principal" principal ]) principals);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
perSystem = { system, self', pkgs, lib, ... }: {
|
||||||
|
packages.ssh-certs = inputs.wrappers.lib.wrapPackage {
|
||||||
|
inherit pkgs;
|
||||||
|
package = (pkgs.symlinkJoin {
|
||||||
|
name = "ssh-certs";
|
||||||
|
meta.mainProgram = "sign-ssh-user-cert";
|
||||||
|
paths = [
|
||||||
|
(inputs.self.wrappers.signUserWrapper.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
provisioner = "admin";
|
||||||
|
overwrite = true;
|
||||||
|
validUsers = [ "john" "root" "appdaemon" ];
|
||||||
|
}).wrapper
|
||||||
|
|
||||||
|
(inputs.self.wrappers.signHostWrapper.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
provisioner = "admin";
|
||||||
|
overwrite = true;
|
||||||
|
# extraPrincipals = [ "home-pc" ];
|
||||||
|
}).wrapper
|
||||||
|
];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
flake.wrappers.signHostWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
provisioner = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = "admin";
|
||||||
|
};
|
||||||
|
extraPrincipals = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
overwrite = lib.mkEnableOption "Overwrite existing cert file?";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "sign-ssh-host-cert";
|
||||||
|
package = config.pkgs.step-cli;
|
||||||
|
extraPackages = with config.pkgs; [ hostname iproute2 systemd ];
|
||||||
|
preHook = ''
|
||||||
|
HOSTNAME=$(hostname -s)
|
||||||
|
IP_ADDRESS=$(ip -4 -o addr show scope global | while read -r _ _ _ addr _; do
|
||||||
|
case "$addr" in
|
||||||
|
192.168.1.*/*)
|
||||||
|
printf '%s\n' "''${addr%%/*}"
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done)
|
||||||
|
echo "Signing SSH host cert for $HOSTNAME at $IP_ADDRESS"
|
||||||
|
'';
|
||||||
|
args =
|
||||||
|
[
|
||||||
|
"ssh" "certificate"
|
||||||
|
"--host" "--sign"
|
||||||
|
"--principal" "$HOSTNAME"
|
||||||
|
"--principal" "$IP_ADDRESS"
|
||||||
|
]
|
||||||
|
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
|
||||||
|
++ lib.optionals config.overwrite [ "-f" ]
|
||||||
|
++ mkPrincipalArgs config.extraPrincipals;
|
||||||
|
postHook = ''
|
||||||
|
systemctl reload-or-restart sshd
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
flake.wrappers.signUserWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
provisioner = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = "admin";
|
||||||
|
};
|
||||||
|
validUsers = lib.mkOption {
|
||||||
|
description = "A list of the user names that this cert will be valid for";
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
overwrite = lib.mkEnableOption "Overwrite existing cert file?";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "sign-ssh-user-cert";
|
||||||
|
package = config.pkgs.step-cli;
|
||||||
|
args = [ "ssh" "certificate" "--sign" ]
|
||||||
|
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
|
||||||
|
++ lib.optionals config.overwrite [ "-f" ]
|
||||||
|
++ mkPrincipalArgs config.validUsers;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
{ self, inputs, ... }: {
|
||||||
|
flake.modules.homeManager.step-client = { config, pkgs, lib, ... }: {
|
||||||
|
home.file.".step/config/defaults.json".text = builtins.toJSON {
|
||||||
|
ca-url = "https://janus.john-stream.com/";
|
||||||
|
fingerprint = "2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6";
|
||||||
|
root = ../hosts/janus/root_ca.crt;
|
||||||
|
};
|
||||||
|
home.packages = [
|
||||||
|
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.step-bootstrap
|
||||||
|
];
|
||||||
|
# sops.secrets."step-ca-defaults" = {
|
||||||
|
# sopsFile = ../hosts/janus/defaults.json;
|
||||||
|
# format = "json";
|
||||||
|
# key = ""; # This causes it to decode the whole file
|
||||||
|
# path = "${config.home.homeDirectory}/defaults.json";
|
||||||
|
# mode = "0400";
|
||||||
|
# };
|
||||||
|
};
|
||||||
|
|
||||||
|
perSystem = { system, pkgs, lib, ... }: {
|
||||||
|
packages.step-bootstrap = (inputs.self.wrappers.stepBootstrap.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
ca-url = "https://janus.john-stream.com";
|
||||||
|
fingerprint = "2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6";
|
||||||
|
install = true;
|
||||||
|
}).wrapper;
|
||||||
|
};
|
||||||
|
|
||||||
|
flake.wrappers.stepBootstrap = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
ca-url = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
fingerprint = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
install = lib.mkEnableOption "Install the cert to the system trust store";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "step-bootstrap";
|
||||||
|
package = config.pkgs.step-cli;
|
||||||
|
args = [
|
||||||
|
"ca" "bootstrap"
|
||||||
|
"--ca-url" config.ca-url
|
||||||
|
"--fingerprint" config.fingerprint
|
||||||
|
]
|
||||||
|
++ lib.optional config.install "--install";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -2,40 +2,59 @@
|
|||||||
let
|
let
|
||||||
username = "john";
|
username = "john";
|
||||||
hostname = "janus";
|
hostname = "janus";
|
||||||
ca-url = "https://janus.john-stream.com/";
|
|
||||||
fingerprint = "2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.modules.nixos.janus-ca =
|
flake.modules.nixos.janus-ca =
|
||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
let
|
let
|
||||||
|
cfg = config.janus-ca;
|
||||||
johnHome = lib.attrByPath [ "users" "users" username "home" ] "/home/${username}" config;
|
johnHome = lib.attrByPath [ "users" "users" username "home" ] "/home/${username}" config;
|
||||||
johnGroup = lib.attrByPath [ "users" "users" username "group" ] username config;
|
johnGroup = lib.attrByPath [ "users" "users" username "group" ] username config;
|
||||||
|
cfgInEtc = lib.hasPrefix "/etc/" cfg.certDir;
|
||||||
|
certDirEtcPath =
|
||||||
|
if cfgInEtc then
|
||||||
|
lib.removePrefix "/etc/" cfg.certDir
|
||||||
|
else
|
||||||
|
cfg.certDir;
|
||||||
|
certRootEtcPath = "${certDirEtcPath}/root_ca.crt";
|
||||||
mkStepRules = home: user: group: [
|
mkStepRules = home: user: group: [
|
||||||
"d ${home}/.step 0700 ${user} ${group} -"
|
"d ${home}/.step 0700 ${user} ${group} -"
|
||||||
"d ${home}/.step/config 0700 ${user} ${group} -"
|
"d ${home}/.step/config 0700 ${user} ${group} -"
|
||||||
"d ${home}/.step/certs 0700 ${user} ${group} -"
|
"d ${home}/.step/certs 0700 ${user} ${group} -"
|
||||||
"L+ ${home}/.step/config/defaults.json - - - - /etc/step/config/defaults.json"
|
"L+ ${home}/.step/config/defaults.json - - - - /etc/step-ca/defaults.json"
|
||||||
"L+ ${home}/.step/certs/root_ca.crt - - - - /etc/step/certs/root_ca.crt"
|
"L+ ${home}/.step/certs/root_ca.crt - - - - ${cfg.certDir}/root_ca.crt"
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
environment.etc."step/config/defaults.json".text = builtins.toJSON {
|
options.janus-ca = {
|
||||||
inherit ca-url fingerprint;
|
certDir = lib.mkOption {
|
||||||
root = "/etc/step-ca/certs/root_ca.crt";
|
description = "String path to where the mtls certs will be stored.";
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "/etc/step-ca/certs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
environment.etc = lib.mkIf cfgInEtc {
|
||||||
|
"step-ca/defaults.json".text = builtins.toJSON {
|
||||||
|
ca-url = "https://janus.john-stream.com/";
|
||||||
|
fingerprint = builtins.readFile ./fingerprint;
|
||||||
|
root = "/etc/${certRootEtcPath}";
|
||||||
|
};
|
||||||
|
"${certRootEtcPath}".source = ./root_ca.crt;
|
||||||
|
};
|
||||||
|
systemd.tmpfiles.rules =
|
||||||
|
mkStepRules johnHome username johnGroup
|
||||||
|
++ mkStepRules "/root" "root" "root";
|
||||||
};
|
};
|
||||||
environment.etc."step-ca/certs/root_ca.crt".source = ./root_ca.crt;
|
|
||||||
systemd.tmpfiles.rules =
|
|
||||||
mkStepRules johnHome username johnGroup
|
|
||||||
++ mkStepRules "/root" "root" "root";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.modules.homeManager.janus-ca = { config, ... }: {
|
flake.modules.homeManager.janus-ca = { config, ... }: {
|
||||||
home.file.".step/config/defaults.json".text = builtins.toJSON {
|
home.file.".step/config/defaults.json".text = builtins.toJSON {
|
||||||
inherit ca-url fingerprint;
|
ca-url = "https://janus.john-stream.com/";
|
||||||
root = "${config.home.homeDirectory}/.step/certs/root_ca.crt";
|
fingerprint = builtins.readFile ./fingerprint;
|
||||||
|
root = ./root_ca.crt;
|
||||||
};
|
};
|
||||||
home.file.".step/certs/root_ca.crt".source = ./root_ca.crt;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.nixosConfigurations."${hostname}" = inputs.nixpkgs.lib.nixosSystem {
|
flake.nixosConfigurations."${hostname}" = inputs.nixpkgs.lib.nixosSystem {
|
||||||
@@ -66,7 +85,6 @@ in
|
|||||||
home-manager.users."${username}" = {
|
home-manager.users."${username}" = {
|
||||||
imports = with inputs.self.modules.homeManager; [
|
imports = with inputs.self.modules.homeManager; [
|
||||||
mysops
|
mysops
|
||||||
step-ssh-user
|
|
||||||
];
|
];
|
||||||
shell.program = "zsh";
|
shell.program = "zsh";
|
||||||
docker.enable = true;
|
docker.enable = true;
|
||||||
@@ -74,23 +92,4 @@ in
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
flake-file.inputs = {
|
|
||||||
wrappers = {
|
|
||||||
url = "github:lassulus/wrappers";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
perSystem = { pkgs, lib, ... }: {
|
|
||||||
packages.janus-ca = inputs.wrappers.lib.wrapPackage {
|
|
||||||
inherit pkgs;
|
|
||||||
package = pkgs.step-cli;
|
|
||||||
binName = "janus-cert";
|
|
||||||
args = [
|
|
||||||
"ca" "certificate"
|
|
||||||
"--ca-url=${ca-url}"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
hostname = "john-p14s";
|
hostname = "john-p14s";
|
||||||
homeDirectory = config.home-manager.users.john.home.homeDirectory;
|
homeDirectory = config.home-manager.users.john.home.homeDirectory;
|
||||||
flakeDir = "${homeDirectory}/Documents/dendritic";
|
flakeDir = "${homeDirectory}/Documents/dendritic";
|
||||||
my-neovim = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.my-neovim;
|
selfPkgs = inputs.self.packages.${pkgs.stdenv.hostPlatform.system};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
@@ -36,12 +36,10 @@
|
|||||||
# List packages installed in system profile. To search, run:
|
# List packages installed in system profile. To search, run:
|
||||||
# $ nix search wget
|
# $ nix search wget
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
wget
|
|
||||||
cacert
|
|
||||||
busybox
|
|
||||||
dig
|
|
||||||
samba
|
samba
|
||||||
my-neovim
|
selfPkgs.my-neovim
|
||||||
|
selfPkgs.wg-platform
|
||||||
|
selfPkgs.jsl-zsh
|
||||||
];
|
];
|
||||||
|
|
||||||
security.pam.services.swaylock = {};
|
security.pam.services.swaylock = {};
|
||||||
@@ -86,6 +84,11 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fonts.packages = with pkgs; [
|
||||||
|
nerd-fonts.hack
|
||||||
|
nerd-fonts.sauce-code-pro
|
||||||
|
];
|
||||||
|
|
||||||
services.libinput.enable = true; # Enable touchpad support (enabled default in most desktopManager).
|
services.libinput.enable = true; # Enable touchpad support (enabled default in most desktopManager).
|
||||||
services.fprintd.enable = true; # Enables fingerprint sensor
|
services.fprintd.enable = true; # Enables fingerprint sensor
|
||||||
|
|
||||||
@@ -124,8 +127,10 @@
|
|||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
bash
|
bash
|
||||||
discord
|
discord
|
||||||
my-neovim
|
proton-vpn
|
||||||
|
joplin-desktop
|
||||||
];
|
];
|
||||||
|
ssh.certificates.enable = true;
|
||||||
ssh.matchSets = {
|
ssh.matchSets = {
|
||||||
appdaemon = true;
|
appdaemon = true;
|
||||||
homelab = true;
|
homelab = true;
|
||||||
|
|||||||
@@ -1,40 +1,33 @@
|
|||||||
{ self, inputs, ... }:
|
{ withSystem, self, inputs, ... }:
|
||||||
let
|
let
|
||||||
username = "john";
|
username = "john";
|
||||||
hostname = "john-pc-ubuntu";
|
hostname = "john-pc-ubuntu";
|
||||||
|
|
||||||
testHost = "soteria"; # which host to test build
|
|
||||||
testTarget = "fded:fb16:653e:25da:be24:11ff:fea0:753f"; # test-nix
|
|
||||||
# testTarget = "fded:fb16:653e:25da:be24:11ff:fe89:1cc3"; # soteria
|
# testTarget = "fded:fb16:653e:25da:be24:11ff:fe89:1cc3"; # soteria
|
||||||
|
# testTarget = "fded:fb16:653e:25da:be24:11ff:fea0:753f"; # test-nix
|
||||||
|
testHost = "soteria"; # which host to test build
|
||||||
|
testTarget = "test-nix";
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.modules.homeManager."${hostname}" = { config, pkgs, lib, ... }:
|
flake.modules.homeManager."${hostname}" = { config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
flakeDir = "${config.xdg.configHome}/home-manager/jsl-dendritic";
|
selfPkgs = inputs.self.packages.${pkgs.stdenv.hostPlatform.system};
|
||||||
resticPasswordFile = "${config.xdg.configHome}/restic/password.txt";
|
resticPasswordFile = "${config.xdg.configHome}/restic/password.txt";
|
||||||
|
flakeDir = "${config.xdg.configHome}/home-manager/jsl-dendritic";
|
||||||
testPushCmd = (pkgs.writeShellScriptBin "test-push" ''
|
|
||||||
${lib.getExe' pkgs.coreutils "echo"} "Pushing ${testHost} to ${testTarget}"
|
|
||||||
${lib.getExe' pkgs.coreutils "mkdir"} -p /var/tmp/nix-build
|
|
||||||
${lib.getExe' pkgs.coreutils "chmod"} 1777 /var/tmp/nix-build
|
|
||||||
${lib.getExe pkgs.nixos-rebuild} switch \
|
|
||||||
--flake ${flakeDir}#${testHost} \
|
|
||||||
--target-host root@${testTarget}
|
|
||||||
'');
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = with inputs.self.modules.homeManager; [
|
imports = with inputs.self.modules.homeManager; [
|
||||||
rebuild
|
rebuild
|
||||||
john
|
john
|
||||||
mysops
|
|
||||||
janus-ca
|
|
||||||
step-ssh-user
|
|
||||||
mtls
|
mtls
|
||||||
restic
|
restic
|
||||||
docker
|
docker
|
||||||
desktop
|
desktop
|
||||||
# neovim
|
step-client
|
||||||
|
mysops
|
||||||
|
# myPackage
|
||||||
|
# myStepClient
|
||||||
];
|
];
|
||||||
# TODO: make this more restrictive, rather than allowing all unfree packages
|
# TODO: make this more restrictive, rather than allowing all unfree packages
|
||||||
nixpkgs.config.allowUnfree = true;
|
nixpkgs.config.allowUnfree = true;
|
||||||
@@ -45,21 +38,22 @@ in
|
|||||||
home.username = "${username}";
|
home.username = "${username}";
|
||||||
home.homeDirectory = "/home/${username}";
|
home.homeDirectory = "/home/${username}";
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
nixos-rebuild
|
selfPkgs.jsl-zsh
|
||||||
testPushCmd
|
selfPkgs.my-neovim
|
||||||
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.my-neovim
|
selfPkgs.ssh-certs
|
||||||
|
# selfPkgs.step-bootstrap
|
||||||
|
# selfPkgs.wg-platform
|
||||||
|
# self'.packages.myWrappedPackage
|
||||||
|
(inputs.self.wrappers.test-push.apply {
|
||||||
|
inherit pkgs flakeDir;
|
||||||
|
host = testHost;
|
||||||
|
target = testTarget;
|
||||||
|
}).wrapper
|
||||||
];
|
];
|
||||||
|
|
||||||
shell.program = "zsh";
|
|
||||||
|
|
||||||
homeManagerFlakeDir = flakeDir;
|
homeManagerFlakeDir = flakeDir;
|
||||||
docker.enable = true;
|
docker.enable = true;
|
||||||
|
|
||||||
step-ssh-user = {
|
|
||||||
enable = true;
|
|
||||||
principals = ["root" "${username}" "appdaemon"];
|
|
||||||
provisioner = "admin";
|
|
||||||
};
|
|
||||||
ssh = {
|
ssh = {
|
||||||
certificates.enable = true;
|
certificates.enable = true;
|
||||||
knownHosts = [
|
knownHosts = [
|
||||||
@@ -70,6 +64,7 @@ in
|
|||||||
appdaemon = true;
|
appdaemon = true;
|
||||||
homelab = true;
|
homelab = true;
|
||||||
dev = true;
|
dev = true;
|
||||||
|
tailscale = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -109,10 +104,13 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.homeConfigurations."${hostname}" = inputs.home-manager.lib.homeManagerConfiguration {
|
flake.homeConfigurations."john@john-pc-ubuntu" = withSystem "x86_64-linux" (ctx@{ system, inputs', ... }:
|
||||||
pkgs = import inputs.nixpkgs { system = "x86_64-linux"; };
|
inputs.home-manager.lib.homeManagerConfiguration {
|
||||||
modules = with inputs.self.modules; [
|
# pkgs = import inputs.nixpkgs {
|
||||||
homeManager."${hostname}"
|
# inherit system;
|
||||||
];
|
# overlays = [ inputs.self.overlays.default ];
|
||||||
};
|
# };
|
||||||
|
pkgs = inputs'.nixpkgs.legacyPackages;
|
||||||
|
modules = [ inputs.self.modules.homeManager."${hostname}" ];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{ self, inputs, ... }: {
|
||||||
|
flake.wrappers.test-push = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
flakeDir = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
host = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
target = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
sshUser = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "root";
|
||||||
|
};
|
||||||
|
elevationStrategy = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "none";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "test-push";
|
||||||
|
package = config.pkgs.nh;
|
||||||
|
args = [
|
||||||
|
"os" "switch" "${config.flakeDir}#${config.host}"
|
||||||
|
"--target-host" "${config.sshUser}@${config.target}"
|
||||||
|
"--elevation-strategy" "${config.elevationStrategy}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ forgejo:
|
|||||||
#ENC[AES256_GCM,data:ZqwgnKjaolJtjcy287fnDOkb/oSLnBpfWfsTeVPwbIE8YLRSoPP4gbCnHJBLq+TJNNI=,iv:zTvw4ZS6C1ifUwOijNLuTfUQ3JM+5gj1X2f/s8MwWXc=,tag:Y1yKlL+jIRHVBulGlSErog==,type:comment]
|
#ENC[AES256_GCM,data:ZqwgnKjaolJtjcy287fnDOkb/oSLnBpfWfsTeVPwbIE8YLRSoPP4gbCnHJBLq+TJNNI=,iv:zTvw4ZS6C1ifUwOijNLuTfUQ3JM+5gj1X2f/s8MwWXc=,tag:Y1yKlL+jIRHVBulGlSErog==,type:comment]
|
||||||
jwt_secret: ENC[AES256_GCM,data:e59MlATOorsTIQjtTUKfX5Yo3CVsbbfuKczp1gh1m2D1kkZK3ORFztYpjg==,iv:JH3PVUmXToiThEKDkDJ8MGVMAPlIEgPSWhru+9WgNjk=,tag:FfDpaCPejpw6kGDkxJwDWw==,type:str]
|
jwt_secret: ENC[AES256_GCM,data:e59MlATOorsTIQjtTUKfX5Yo3CVsbbfuKczp1gh1m2D1kkZK3ORFztYpjg==,iv:JH3PVUmXToiThEKDkDJ8MGVMAPlIEgPSWhru+9WgNjk=,tag:FfDpaCPejpw6kGDkxJwDWw==,type:str]
|
||||||
lfs_jwt_secret: ENC[AES256_GCM,data:xi9PEKFUGRyc3YOg3JM3KrrENi9xsbeBjiz4R16SK5WDafoGFLazN6KRJQ==,iv:1IhPyQDwA8tZ22pfZJiU8TRTCLCHC/HAnKdmSGDfvcM=,tag:rLdREVSKBm67rt8ayN16Vw==,type:str]
|
lfs_jwt_secret: ENC[AES256_GCM,data:xi9PEKFUGRyc3YOg3JM3KrrENi9xsbeBjiz4R16SK5WDafoGFLazN6KRJQ==,iv:1IhPyQDwA8tZ22pfZJiU8TRTCLCHC/HAnKdmSGDfvcM=,tag:rLdREVSKBm67rt8ayN16Vw==,type:str]
|
||||||
|
restic_password: ENC[AES256_GCM,data:u7QOZXJkxVG4J75K5nphb2uJGdz6jbWuVSsKKu+41fshp7cVoRijtr/Cs02LjVse,iv:bt1W2FeBTG6ypBFYzMPXPIkYTSn0uHURY2ui6MRgYY8=,tag:DObAMws/zQcM+UKUe9EECA==,type:str]
|
||||||
sops:
|
sops:
|
||||||
age:
|
age:
|
||||||
- recipient: age1ykcs39e62pz3xu6cedg8ea685kv5d5qsrhgkndygzm8rx30xd5ys5t3qxt
|
- recipient: age1ykcs39e62pz3xu6cedg8ea685kv5d5qsrhgkndygzm8rx30xd5ys5t3qxt
|
||||||
@@ -37,7 +38,7 @@ sops:
|
|||||||
Yjd0MUcxcExvWVpCOUR3MkdZdGQyWUkKnru0Y2A98+0Mps7EtVK7ct3vPqIGveUt
|
Yjd0MUcxcExvWVpCOUR3MkdZdGQyWUkKnru0Y2A98+0Mps7EtVK7ct3vPqIGveUt
|
||||||
E5fzpcKvdefzObrx7BPTwJ19t2fZg/dSi7HKwx3vmKZSzyQaqJOzsg==
|
E5fzpcKvdefzObrx7BPTwJ19t2fZg/dSi7HKwx3vmKZSzyQaqJOzsg==
|
||||||
-----END AGE ENCRYPTED FILE-----
|
-----END AGE ENCRYPTED FILE-----
|
||||||
lastmodified: "2026-04-02T03:47:52Z"
|
lastmodified: "2026-04-04T23:18:43Z"
|
||||||
mac: ENC[AES256_GCM,data:NvCF78rzYOv2Ulf3TLB4eKtYEqNkfSzPBPRXcpTTO9QoSH3axdapkhUzsSq2d30RV/F/PLMbMaERMgW1SFT0Uikvk0s5ALmwN29MMwA6BMyup5bzOQeOIxOoeYrKOeqCJdI3ZhtqV/ebvyTebVI7Q6Jw0QKf+9SW2RfYGFJkKF0=,iv:VSoGZkzSzI9SPnvrzyIgWgW/teRNiFlf5fdmHKVg2TE=,tag:qm/jUdQ63MdWUxBDJ9kxww==,type:str]
|
mac: ENC[AES256_GCM,data:qBgeli5lHb4pyA8nAADBuRBAaq8VbAIsFI37OZtgnbnoHW2crxo3YC+EknaIYnZpZ48kwVhQS5lGRjI6JsWWhTH3+LVAhTmS2Qj/pZTD/JDLK6XJGXS4U9nB7m9aGYyW8gFCy9/DfoJWGsS//+ZmUikKPfd5kMZgh1zGoYCIGug=,iv:h+2fA+bO2SMCNrEslP36x3BPRaIy25cU/DNX8CYSC6A=,tag:RvVyUZ4ONRaKaqGiT31eUQ==,type:str]
|
||||||
unencrypted_suffix: _unencrypted
|
unencrypted_suffix: _unencrypted
|
||||||
version: 3.12.2
|
version: 3.12.2
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ self, inputs, lib, ... }:
|
{ withSystem, self, inputs, lib, ... }:
|
||||||
let
|
let
|
||||||
username = "john";
|
username = "john";
|
||||||
hostname = "soteria";
|
hostname = "soteria";
|
||||||
@@ -17,21 +17,9 @@ in
|
|||||||
nixos.forgejo
|
nixos.forgejo
|
||||||
# nixos.restic-server
|
# nixos.restic-server
|
||||||
# nixos.restic-envoy
|
# nixos.restic-envoy
|
||||||
({ pkgs, ... }: {
|
({ config, pkgs, ... }: {
|
||||||
networking.hostName = hostname;
|
networking.hostName = hostname;
|
||||||
mtls = {
|
time.timeZone = "America/Chicago";
|
||||||
enable = true;
|
|
||||||
subject = hostname;
|
|
||||||
san = [
|
|
||||||
"${hostname}.john-stream.com"
|
|
||||||
"192.168.1.142"
|
|
||||||
];
|
|
||||||
lifetime = "1h";
|
|
||||||
renew.onCalendar = "*:3/15";
|
|
||||||
renew.postCommands = [
|
|
||||||
"${lib.getExe pkgs.docker} restart envoy"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Removes password for sudo
|
# Removes password for sudo
|
||||||
security.sudo-rs.extraRules = lib.mkAfter [
|
security.sudo-rs.extraRules = lib.mkAfter [
|
||||||
@@ -45,52 +33,88 @@ in
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
# nix.settings.build-dir = "/var/tmp/nix-build";
|
|
||||||
# systemd.tmpfiles.rules = [
|
users.users."${username}".extraGroups = [ "mtls" ];
|
||||||
# "d /var/tmp/nix-build 1777 root root -"
|
mtls = {
|
||||||
# ];
|
enable = true;
|
||||||
step-ssh-host = {
|
certDir = config.janus-ca.certDir;
|
||||||
hostname = hostname;
|
subject = hostname;
|
||||||
|
san = [
|
||||||
|
"${hostname}.john-stream.com"
|
||||||
|
# "192.168.1.142"
|
||||||
|
"forgejo.john-stream.com"
|
||||||
|
"192.168.1.244"
|
||||||
|
];
|
||||||
|
lifetime = "12h";
|
||||||
|
renew.onCalendar = "*:3/15";
|
||||||
|
renew.reloadUnits = [ "forgejo.service" "restic-rest-server.service" ];
|
||||||
|
certReaders = [ config.services.forgejo.user "restic" ];
|
||||||
};
|
};
|
||||||
|
forgejo = {
|
||||||
|
enable = true;
|
||||||
|
root_url = "https://forgejo.john-stream.com";
|
||||||
|
https = true;
|
||||||
|
port = 443;
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.firewall.allowedTCPPorts = [ 8000 ];
|
||||||
|
services.restic.server = {
|
||||||
|
enable = true;
|
||||||
|
privateRepos = true;
|
||||||
|
listenAddress = "0.0.0.0:8000";
|
||||||
|
extraFlags = [
|
||||||
|
"--no-auth"
|
||||||
|
"--tls"
|
||||||
|
"--tls-cert=${config.mtls.certFile}"
|
||||||
|
"--tls-key=${config.mtls.keyFile}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
loginText.extraServiceStatus = {
|
||||||
|
Docker = "docker";
|
||||||
|
"mTLS Renewal" = "mtls-renew.timer";
|
||||||
|
Forgejo = "forgejo.service";
|
||||||
|
"Forgejo Backup" = "forgejo-dump.timer";
|
||||||
|
"Restic REST Server" = "restic-rest-server.service";
|
||||||
|
};
|
||||||
|
|
||||||
|
step-ssh-host.hostname = hostname;
|
||||||
|
|
||||||
# This provides the secrets at install time
|
# This provides the secrets at install time
|
||||||
sops.defaultSopsFile = ./secrets.yaml;
|
sops.defaultSopsFile = ./secrets.yaml;
|
||||||
|
|
||||||
programs.zsh.enable = true;
|
programs.zsh.enable = true;
|
||||||
home-manager.users."${username}" = {
|
|
||||||
imports = with inputs.self.modules; [
|
home-manager.users."${username}".imports = [ inputs.self.modules.homeManager.soteria ];
|
||||||
homeManager."${hostname}"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.janus-ca
|
|
||||||
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.my-neovim
|
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.my-neovim
|
||||||
|
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.jsl-zsh
|
||||||
];
|
];
|
||||||
|
|
||||||
forgejo.enable = true;
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.modules.homeManager."${hostname}" = { config, pkgs, lib, ... }: {
|
flake.modules.homeManager.soteria = { config, pkgs, lib, ... }: {
|
||||||
imports = with inputs.self.modules; [
|
imports = [
|
||||||
homeManager.rebuild
|
inputs.self.modules.homeManager.rebuild
|
||||||
homeManager.mysops
|
inputs.self.modules.homeManager.mysops
|
||||||
];
|
({ config, pkgs, lib, ... }: {
|
||||||
|
homeManagerFlakeDir = "${config.xdg.configHome}/home-manager";
|
||||||
|
docker.enable = true;
|
||||||
|
|
||||||
homeManagerFlakeDir = "${config.xdg.configHome}/home-manager";
|
# This will provide the edit-secrets script targeting this file
|
||||||
shell.program = "zsh";
|
mysops.hostSecretFile = "${config.homeManagerFlakeDir}/modules/hosts/soteria/secrets.yaml";
|
||||||
docker.enable = true;
|
})
|
||||||
|
|
||||||
# This will provide the edit-secrets script targeting this file
|
|
||||||
mysops.hostSecretFile = "${config.homeManagerFlakeDir}/modules/hosts/soteria/secrets.yaml";
|
|
||||||
};
|
|
||||||
|
|
||||||
flake.homeConfigurations."${hostname}" = inputs.home-manager.lib.homeManagerConfiguration {
|
|
||||||
pkgs = import inputs.nixpkgs { system = "x86_64-linux"; };
|
|
||||||
modules = with inputs.self.modules; [
|
|
||||||
homeManager."${username}"
|
|
||||||
homeManager."${hostname}"
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
flake.homeConfigurations.soteria = withSystem "x86_64-linux" (ctx@{ config, inputs', ...}:
|
||||||
|
inputs.home-manager.lib.homeManagerConfiguration {
|
||||||
|
pkgs = inputs'.nixpkgs.legacyPackages;
|
||||||
|
modules = [
|
||||||
|
inputs.self.modules.homeManager."${username}"
|
||||||
|
inputs.self.modules.homeManager.soteria
|
||||||
|
];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
+102
-60
@@ -6,11 +6,21 @@
|
|||||||
flakeDir = config.rebuild.flakeDir;
|
flakeDir = config.rebuild.flakeDir;
|
||||||
echoCmd = lib.getExe' pkgs.coreutils "echo";
|
echoCmd = lib.getExe' pkgs.coreutils "echo";
|
||||||
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
|
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
|
||||||
nfs = (pkgs.writeShellScriptBin "nfs" ''
|
|
||||||
HOSTNAME=${hostnameCmd}
|
nfs = with pkgs; writeShellApplication {
|
||||||
${echoCmd} "Switching to the $HOSTNAME nixos profile"
|
name = "nfs";
|
||||||
sudo ${lib.getExe pkgs.nixos-rebuild} switch --impure --flake ${flakeDir}#$HOSTNAME
|
runtimeInputs = [ coreutils hostname nh ];
|
||||||
'');
|
text = ''
|
||||||
|
HOSTNAME=$(hostname -s)
|
||||||
|
echo "Switching to the $HOSTNAME nixos profile"
|
||||||
|
nh os switch "$@" "${flakeDir}#$HOSTNAME"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
nfsu = with pkgs; writeShellApplication {
|
||||||
|
name = "nfsu";
|
||||||
|
runtimeInputs = [ nfs pkgs.git ];
|
||||||
|
text = ''nfs --refresh "$@"'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.rebuild = {
|
options.rebuild = {
|
||||||
@@ -22,29 +32,38 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [ nfs nfsu ];
|
||||||
nfs
|
|
||||||
(writeShellScriptBin "nfsu" ''
|
|
||||||
${lib.getExe nix} flake update --impure --flake ${flakeDir}
|
|
||||||
${lib.getExe git} -C ${flakeDir} add ${flakeDir}/flake.lock > /dev/null 2>&1
|
|
||||||
${lib.getExe nfs}
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.modules.homeManager.rebuild =
|
flake.modules.homeManager.rebuild =
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
nixBin = lib.getExe pkgs.nix;
|
|
||||||
flakeDir = config.homeManagerFlakeDir;
|
flakeDir = config.homeManagerFlakeDir;
|
||||||
echoCmd = lib.getExe' pkgs.coreutils "echo";
|
|
||||||
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
|
flake-parts-check = with pkgs; writeShellApplication {
|
||||||
nhms = (pkgs.writeShellScriptBin "nhms" ''
|
name = "flake-parts-check";
|
||||||
HOSTNAME=${hostnameCmd}
|
runtimeInputs = [ nix ];
|
||||||
${echoCmd} "Switching to the $HOSTNAME home-manager profile"
|
text = ''
|
||||||
${lib.getExe pkgs.home-manager} switch --impure --flake ${flakeDir}#$HOSTNAME
|
cd ${flakeDir}
|
||||||
'');
|
nix run "${flakeDir}#write-flake"
|
||||||
|
nix flake check
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
test-build = with pkgs; writeShellApplication {
|
||||||
|
name = "test-build";
|
||||||
|
runtimeInputs = [ coreutils nix hostname ];
|
||||||
|
text = ''
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
HOSTNAME=$(hostname -s)
|
||||||
|
else
|
||||||
|
HOSTNAME="$1"
|
||||||
|
fi
|
||||||
|
echo "Testing the evaulation of the nixos config for $HOSTNAME"
|
||||||
|
nix eval "${flakeDir}#nixosConfigurations.$HOSTNAME.config.system.build.toplevel.drvPath"
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
@@ -53,54 +72,77 @@
|
|||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "${config.xdg.configHome}/home-manager";
|
default = "${config.xdg.configHome}/home-manager";
|
||||||
};
|
};
|
||||||
buildHostname = lib.mkOption {
|
|
||||||
description = "Hostname for the NixOS configuration to use.";
|
|
||||||
type = lib.types.str;
|
|
||||||
default = hostnameCmd;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.activation.printFlakeDir = lib.hm.dag.entryAfter ["writeBoundary"] ''
|
home.activation.printFlakeDir = lib.hm.dag.entryAfter ["writeBoundary"] ''
|
||||||
run ${echoCmd} "Home Manager flake directory: ${flakeDir}"
|
run echo "Home Manager flake directory: ${flakeDir}"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
home-manager
|
home-manager
|
||||||
(writeShellScriptBin "flake-parts-check" ''
|
(symlinkJoin {
|
||||||
cd ${flakeDir}
|
name = "build-tools";
|
||||||
${nixBin} run "${flakeDir}#write-flake"
|
paths = [
|
||||||
${nixBin} flake check
|
flake-parts-check
|
||||||
'')
|
test-build
|
||||||
nhms
|
(inputs.self.wrappers.home-switch.apply {
|
||||||
(writeShellScriptBin "nhmu" ''
|
inherit pkgs flakeDir;
|
||||||
${nixBin} flake update --flake ${flakeDir}
|
}).wrapper
|
||||||
${lib.getExe nhms}
|
(inputs.self.wrappers.home-switch.apply {
|
||||||
'')
|
binName = lib.mkForce "nhmu";
|
||||||
|
inherit pkgs flakeDir;
|
||||||
(writeShellScriptBin "test-build" ''
|
extraOptions = [ "--update" ];
|
||||||
if [ -z "$1" ]; then
|
}).wrapper
|
||||||
HOSTNAME=${hostnameCmd}
|
(inputs.wrappers.lib.wrapPackage {
|
||||||
else
|
binName = "cleanup";
|
||||||
HOSTNAME="$1"
|
inherit pkgs;
|
||||||
fi
|
package = nh;
|
||||||
${echoCmd} "Testing the evaulation of the nixos config for $HOSTNAME"
|
args = [ "clean" "user" "--keep-since" "3days" ];
|
||||||
${lib.getExe nix} eval ${flakeDir}#nixosConfigurations.$HOSTNAME.config.system.build.toplevel.drvPath
|
})
|
||||||
'')
|
];
|
||||||
|
})
|
||||||
(writeShellScriptBin "cleanup" ''
|
|
||||||
set -e
|
|
||||||
DAYS=$1
|
|
||||||
if [ -z "$DAYS" ]; then
|
|
||||||
${echoCmd} "usage: cleanup <days>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
${lib.getExe home-manager} expire-generations "-$DAYS days"
|
|
||||||
${lib.getExe nix} profile wipe-history --older-than "''${DAYS}d"
|
|
||||||
${lib.getExe nix} store gc
|
|
||||||
${lib.getExe nix} store optimise
|
|
||||||
'')
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
flake.wrappers.home-switch = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
flakeDir = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
user = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "$(whoami)";
|
||||||
|
};
|
||||||
|
hostname = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "$(hostname -s)";
|
||||||
|
};
|
||||||
|
configuration = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "${config.user}@${config.hostname}";
|
||||||
|
};
|
||||||
|
extraOptions = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "nhms";
|
||||||
|
extraPackages = with config.pkgs; [ coreutils hostname nh ];
|
||||||
|
preHook = ''
|
||||||
|
CONFIG=${config.configuration}
|
||||||
|
echo "Switching to $CONFIG"
|
||||||
|
'';
|
||||||
|
package = config.pkgs.nh;
|
||||||
|
args = [
|
||||||
|
"home" "switch"
|
||||||
|
"--configuration" "${config.configuration}"
|
||||||
|
"$@"
|
||||||
|
"${config.flakeDir}"
|
||||||
|
] ++ config.extraOptions;
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,17 +14,27 @@
|
|||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
];
|
];
|
||||||
|
|
||||||
|
environment.shells = [
|
||||||
|
"${lib.getExe pkgs.zsh}"
|
||||||
|
"${lib.getExe inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.jsl-zsh}"
|
||||||
|
];
|
||||||
|
|
||||||
|
users.groups."${username}" = {};
|
||||||
|
|
||||||
users.users."${username}" = {
|
users.users."${username}" = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
|
group = username;
|
||||||
home = "/home/${username}";
|
home = "/home/${username}";
|
||||||
shell = lib.mkIf config.programs.zsh.enable pkgs.zsh;
|
shell = pkgs.zsh;
|
||||||
extraGroups = [ "input" "networkmanager" ]
|
extraGroups = [ "input" "networkmanager" ]
|
||||||
++ lib.optional isAdmin "wheel"
|
++ lib.optional isAdmin "wheel"
|
||||||
++ lib.optional config.virtualisation.docker.enable "docker"
|
++ lib.optional config.virtualisation.docker.enable "docker"
|
||||||
++ lib.optional (isAdmin && config.services.forgejo.enable) config.services.forgejo.group
|
++ lib.optional (isAdmin && config.services.forgejo.enable) config.services.forgejo.group
|
||||||
++ lib.optional (isAdmin && config.services.postgresql.enable) "postgres";
|
++ lib.optional (isAdmin && config.services.postgresql.enable) "postgres";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
programs.zsh.enable = true;
|
||||||
|
|
||||||
security.sudo-rs.enable = lib.mkIf isAdmin true;
|
security.sudo-rs.enable = lib.mkIf isAdmin true;
|
||||||
|
|
||||||
home-manager.useGlobalPkgs = true;
|
home-manager.useGlobalPkgs = true;
|
||||||
@@ -33,7 +43,9 @@
|
|||||||
imports = [ self.modules.homeManager."${username}" ];
|
imports = [ self.modules.homeManager."${username}" ];
|
||||||
home.username = "${username}";
|
home.username = "${username}";
|
||||||
home.homeDirectory = "/home/${username}";
|
home.homeDirectory = "/home/${username}";
|
||||||
# home.packages = homePackages;
|
home.packages = with pkgs; [
|
||||||
|
# fzf zoxide starship
|
||||||
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{ self, inputs, ... }: {
|
||||||
|
config.flake-file.inputs = {
|
||||||
|
wrapper-modules = {
|
||||||
|
url = "github:BirdeeHub/nix-wrapper-modules";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
wrappers = {
|
||||||
|
url = "github:lassulus/wrappers";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
options = {
|
||||||
|
# This is what allows wrappers to be defined in flake.wrappers.<wrapper-name> throughout different flake-parts modules
|
||||||
|
flake = inputs.flake-parts.lib.mkSubmoduleOptions {
|
||||||
|
wrappers = inputs.nixpkgs.lib.mkOption {
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,44 +1,56 @@
|
|||||||
{ inputs, ... }: {
|
{ inputs, ... }: {
|
||||||
flake.modules.nixos.login-text = { config, ... }: {
|
flake.modules.nixos.login-text = { config, lib, ... }:
|
||||||
programs.rust-motd = {
|
let
|
||||||
enable = true;
|
defaultServiceStatus = {
|
||||||
refreshInterval = "*:0/5";
|
SSH = "sshd.socket";
|
||||||
order = [
|
"SSH Cert Renewal" = "step-ssh-host-renew.timer";
|
||||||
"global"
|
};
|
||||||
"last_login"
|
in {
|
||||||
"service_status"
|
options.loginText.extraServiceStatus = lib.mkOption {
|
||||||
# "uptime"
|
type = lib.types.attrsOf lib.types.str;
|
||||||
"memory"
|
default = { };
|
||||||
"filesystems"
|
description = "Additional rust-motd service status entries keyed by display name.";
|
||||||
];
|
};
|
||||||
settings = {
|
|
||||||
global = {
|
|
||||||
time_format = "%Y-%m-%d %H:%M:%S %Z";
|
|
||||||
};
|
|
||||||
|
|
||||||
last_login = {
|
config = {
|
||||||
john = 3;
|
programs.rust-motd = {
|
||||||
root = 3;
|
enable = true;
|
||||||
};
|
refreshInterval = "*:0/5";
|
||||||
|
order = [
|
||||||
|
"global"
|
||||||
|
"last_login"
|
||||||
|
"service_status"
|
||||||
|
# "uptime"
|
||||||
|
"memory"
|
||||||
|
"filesystems"
|
||||||
|
];
|
||||||
|
settings = {
|
||||||
|
global = {
|
||||||
|
time_format = "%Y-%m-%d %H:%M:%S %Z";
|
||||||
|
};
|
||||||
|
|
||||||
service_status = {
|
last_login = {
|
||||||
Docker = "docker";
|
john = 3;
|
||||||
SSH = "sshd.socket";
|
root = 3;
|
||||||
"SSH Cert Renewal" = "step-ssh-host-renew.timer";
|
};
|
||||||
"mTLS Renewal" = "mtls-renew.timer";
|
|
||||||
};
|
|
||||||
|
|
||||||
# This calculation is wrong for LXCs
|
service_status = lib.mkMerge [
|
||||||
# uptime = {
|
defaultServiceStatus
|
||||||
# prefix = "Uptime";
|
config.loginText.extraServiceStatus
|
||||||
# };
|
];
|
||||||
|
|
||||||
memory = {
|
# This calculation is wrong for LXCs
|
||||||
swap_pos = "beside";
|
# uptime = {
|
||||||
};
|
# prefix = "Uptime";
|
||||||
|
# };
|
||||||
|
|
||||||
filesystems = {
|
memory = {
|
||||||
root = "/";
|
swap_pos = "beside";
|
||||||
|
};
|
||||||
|
|
||||||
|
filesystems = {
|
||||||
|
root = "/";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
{
|
{
|
||||||
flake.modules.homeManager.bash = { pkgs, lib, config, ... }:
|
flake.modules.homeManager.bash = { pkgs, lib, config, ... }:
|
||||||
{
|
{
|
||||||
programs.bash = lib.mkIf (config.shell.program == "bash") {
|
programs.bash = {
|
||||||
enable = true;
|
enable = true;
|
||||||
enableCompletion = true;
|
enableCompletion = true;
|
||||||
package = pkgs.bash;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,32 @@
|
|||||||
{ inputs, pkgs, lib, ... }:
|
{ self, inputs, ... }:
|
||||||
{
|
{
|
||||||
flake.modules.homeManager.eza = { pkgs, lib, ... }: {
|
flake.modules.homeManager.eza = { config, pkgs, lib, ... }: {
|
||||||
programs.eza = {
|
programs.eza = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.eza;
|
|
||||||
enableBashIntegration = true;
|
enableBashIntegration = true;
|
||||||
enableZshIntegration = true;
|
enableZshIntegration = true;
|
||||||
|
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.my-eza;
|
||||||
};
|
};
|
||||||
home.shellAliases = {
|
};
|
||||||
ls = "${lib.getExe pkgs.eza} -lgos type --no-time --follow-symlinks";
|
|
||||||
|
perSystem = { system, pkgs, ... }: {
|
||||||
|
packages.my-eza = inputs.wrappers.lib.wrapPackage {
|
||||||
|
inherit pkgs;
|
||||||
|
package = pkgs.eza;
|
||||||
|
args = [
|
||||||
|
"--all"
|
||||||
|
"--long"
|
||||||
|
"--group-directories-first"
|
||||||
|
"--icons=auto"
|
||||||
|
"--color=auto"
|
||||||
|
"--sort=type"
|
||||||
|
"--dereference"
|
||||||
|
"--octal-permissions"
|
||||||
|
"--smart-group"
|
||||||
|
"--no-time"
|
||||||
|
"--git"
|
||||||
|
"$@"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+13
-10
@@ -1,15 +1,18 @@
|
|||||||
{
|
{
|
||||||
flake.modules.homeManager.files = { pkgs, ... }:
|
flake.modules.homeManager.files = { pkgs, lib, ... }:
|
||||||
{
|
{
|
||||||
programs.lf.enable = true;
|
programs.lf = {
|
||||||
programs.lf.cmdKeybindings = {
|
enable = true;
|
||||||
"D" = "delete";
|
cmdKeybindings = {
|
||||||
|
"D" = "delete";
|
||||||
|
};
|
||||||
|
settings = {
|
||||||
|
preview = true;
|
||||||
|
hidden = true;
|
||||||
|
drawbox = true;
|
||||||
|
icons = true;
|
||||||
|
ignorecase = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
home.packages = with pkgs; [
|
|
||||||
gdu
|
|
||||||
lf
|
|
||||||
# TODO: find a CLI file editor that's not insane
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,4 @@
|
|||||||
{ self, inputs, ... }: {
|
{ self, inputs, ... }: {
|
||||||
flake-file.inputs = {
|
|
||||||
wrapper-modules.url = "github:BirdeeHub/nix-wrapper-modules";
|
|
||||||
# wrapper-modules.inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
|
|
||||||
flake.modules.nixos.niri = { pkgs, lib, ... }: {
|
flake.modules.nixos.niri = { pkgs, lib, ... }: {
|
||||||
programs.niri = {
|
programs.niri = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|||||||
+71
-71
@@ -1,4 +1,4 @@
|
|||||||
{ inputs, ... }:
|
{ self, inputs, ... }:
|
||||||
let
|
let
|
||||||
inputs' = inputs; # save a reference before it's shadowed
|
inputs' = inputs; # save a reference before it's shadowed
|
||||||
in
|
in
|
||||||
@@ -14,84 +14,84 @@ in
|
|||||||
imports = [ inputs.sops-nix.nixosModules.sops ];
|
imports = [ inputs.sops-nix.nixosModules.sops ];
|
||||||
};
|
};
|
||||||
|
|
||||||
# Define the homeModules that are used by flake-parts
|
flake.modules.homeManager.mysops =
|
||||||
# https://flake.parts/options/home-manager.html#opt-flake.modules.homeManager
|
{ config, pkgs, lib, ... }:
|
||||||
flake.modules.homeManager.mysops = { inputs, config, pkgs, lib, ... }:
|
|
||||||
let
|
|
||||||
cfg = config.mysops;
|
|
||||||
sopsBin = lib.getExe pkgs.sops;
|
|
||||||
sopsConfigPath = ../../.sops.yaml;
|
|
||||||
sopsSecretsPath = ../../keys/secrets.yaml;
|
|
||||||
|
|
||||||
editScript = lib.optional (cfg.hostSecretFile != null) (pkgs.writeShellScriptBin "edit-secrets" ''
|
|
||||||
${sopsBin} --config ${sopsConfigPath} ${cfg.hostSecretFile}
|
|
||||||
'');
|
|
||||||
in
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
# This import makes the sops config attribute available below
|
|
||||||
inputs'.sops-nix.homeManagerModules.sops
|
|
||||||
];
|
|
||||||
|
|
||||||
options.mysops = {
|
|
||||||
ageKeyFile = lib.mkOption {
|
|
||||||
description = "Default location for the age key";
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "${config.xdg.configHome}/sops/age/keys.txt";
|
|
||||||
};
|
|
||||||
hostSecretFile = lib.mkOption {
|
|
||||||
description = "Path to the secrets file for this host. Used to create the edit-secrets script";
|
|
||||||
type = lib.types.nullOr lib.types.str;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config =
|
|
||||||
let
|
let
|
||||||
echo = lib.getExe' pkgs.coreutils "echo";
|
cfg = config.mysops;
|
||||||
dirname = lib.getExe' pkgs.coreutils "dirname";
|
|
||||||
mkdir = lib.getExe' pkgs.coreutils "mkdir";
|
|
||||||
show-age-key = (pkgs.writeShellScriptBin "show-age-key" ''
|
|
||||||
${lib.getExe' pkgs.age "age-keygen"} -y ${cfg.ageKeyFile}
|
|
||||||
'');
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
home.packages = with pkgs; [
|
imports = [
|
||||||
eza
|
# This import makes the sops config attribute available below
|
||||||
age
|
inputs'.sops-nix.homeManagerModules.sops
|
||||||
sops # This is necessary to make the sops binary available
|
];
|
||||||
ssh-to-age
|
|
||||||
(writeShellScriptBin "gen-age-key" ''
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
if [ ! -f "${config.ssh.identityFile}" ]; then
|
options.mysops = {
|
||||||
${echo} "SSH identity file not found: ${config.ssh.identityFile}" >&2
|
hostSecretFile = lib.mkOption {
|
||||||
exit 1
|
description = "Path to the secrets file for this host. Used to create the edit-secrets script";
|
||||||
fi
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
if [ -e "${cfg.ageKeyFile}" ]; then
|
config =
|
||||||
${echo} "Refusing to overwrite existing age key file: ${cfg.ageKeyFile}" >&2
|
let
|
||||||
exit 1
|
my-sops = (inputs.self.wrappers.mySops.apply {
|
||||||
fi
|
inherit pkgs;
|
||||||
|
sshKey = config.ssh.identityFile;
|
||||||
|
}).wrapper;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
# Option definitions for the sops home-manager module:
|
||||||
|
# https://github.com/Mic92/sops-nix/blob/master/modules/home-manager/sops.nix
|
||||||
|
sops = {
|
||||||
|
defaultSopsFile = ../../keys/secrets.yaml;
|
||||||
|
defaultSopsFormat = "yaml";
|
||||||
|
age.sshKeyPaths = [ "${config.ssh.identityFile}" ];
|
||||||
|
};
|
||||||
|
|
||||||
${mkdir} -p "$(${dirname} "${cfg.ageKeyFile}")"
|
home.packages = with pkgs; [
|
||||||
${lib.getExe pkgs.ssh-to-age} -i ${config.ssh.identityFile} -private-key > ${cfg.ageKeyFile}
|
my-sops
|
||||||
${echo} -n "Created ${cfg.ageKeyFile}: "
|
(inputs.wrappers.lib.wrapPackage {
|
||||||
${echo} $(${lib.getExe show-age-key})
|
binName = "ls-secrets";
|
||||||
'')
|
inherit pkgs;
|
||||||
show-age-key
|
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.my-eza;
|
||||||
(writeShellScriptBin "ls-secrets" "${lib.getExe pkgs.eza} -alT --follow-symlinks ~/.config/sops-nix/secrets")
|
args = [
|
||||||
] ++ editScript;
|
"-T" "--follow-symlinks"
|
||||||
|
"${config.xdg.configHome}/sops-nix/secrets"
|
||||||
|
];
|
||||||
|
})
|
||||||
|
|
||||||
home.shellAliases.sops = "${sopsBin} --config ${sopsConfigPath}";
|
]
|
||||||
|
++ lib.optional (cfg.hostSecretFile != null) (inputs.wrappers.lib.wrapPackage {
|
||||||
|
binName = "edit-secrets";
|
||||||
|
inherit pkgs;
|
||||||
|
package = my-sops;
|
||||||
|
args = [ cfg.hostSecretFile ];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# Option definitions for the sops home-manager module:
|
flake.wrappers.mySops = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
# https://github.com/Mic92/sops-nix/blob/master/modules/home-manager/sops.nix
|
options = {
|
||||||
sops = {
|
sshKey = lib.mkOption {
|
||||||
defaultSopsFile = sopsSecretsPath;
|
type = lib.types.str;
|
||||||
defaultSopsFormat = "yaml";
|
description = "String path to the SSH key to use for creating an AGE key at runtime";
|
||||||
age.sshKeyPaths = [ "${config.ssh.identityFile}" ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
config = {
|
||||||
|
# binName = "my-sops";
|
||||||
|
package = config.pkgs.sops;
|
||||||
|
extraPackages = with config.pkgs; [ coreutils ssh-to-age ];
|
||||||
|
preHook = ''
|
||||||
|
AGE_KEY=$(umask 077; mktemp)
|
||||||
|
ssh-to-age -private-key -i ${config.sshKey} > "$AGE_KEY"
|
||||||
|
'';
|
||||||
|
flags."--config" = "${../../.sops.yaml}";
|
||||||
|
postHook = ''
|
||||||
|
rm "$AGE_KEY"
|
||||||
|
echo "Removed $AGE_KEY"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
{ self, inputs, ... }: {
|
||||||
|
perSystem = { system, pkgs, lib, ... }: {
|
||||||
|
packages.starship = (inputs.wrappers.wrapperModules.starship.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
settings = lib.recursiveUpdate (lib.importTOML (pkgs.fetchurl {
|
||||||
|
url = https://starship.rs/presets/toml/catppuccin-powerline.toml;
|
||||||
|
sha256 = "1jzbbzm3nwdlldq43aj3csp0ps23fsa6x2225z85l0s9qbj4cdy2";
|
||||||
|
})) {
|
||||||
|
palette = "catppuccin_mocha";
|
||||||
|
add_newline = true;
|
||||||
|
line_break.disabled = false;
|
||||||
|
git_status.diverged = "⇕⇡\${ahead_count}⇣\${behind_count}";
|
||||||
|
cmd_duration.format = " $duration";
|
||||||
|
cmd_duration.show_notifications = false;
|
||||||
|
hostname = {
|
||||||
|
disabled = false;
|
||||||
|
ssh_symbol = "🌐";
|
||||||
|
format = "[$ssh_symbol$hostname]($style)";
|
||||||
|
style = "bg:red fg:crust";
|
||||||
|
};
|
||||||
|
os.symbols.NixOS = " ";
|
||||||
|
format = lib.replaceStrings ["\n"] [""] ''
|
||||||
|
[](red)
|
||||||
|
$os
|
||||||
|
$username
|
||||||
|
$hostname
|
||||||
|
[](bg:peach fg:red)
|
||||||
|
$directory
|
||||||
|
[](bg:yellow fg:peach)
|
||||||
|
$git_branch
|
||||||
|
$git_status
|
||||||
|
[](fg:yellow bg:green)
|
||||||
|
$c
|
||||||
|
$rust
|
||||||
|
$golang
|
||||||
|
$nodejs
|
||||||
|
$php
|
||||||
|
$java
|
||||||
|
$kotlin
|
||||||
|
$haskell
|
||||||
|
$python
|
||||||
|
[](fg:green bg:sapphire)
|
||||||
|
$conda
|
||||||
|
[](fg:sapphire bg:lavender)
|
||||||
|
$time
|
||||||
|
[ ](fg:lavender)
|
||||||
|
$cmd_duration
|
||||||
|
$line_break
|
||||||
|
$character
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}).wrapper;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
{ self, inputs, ... }: {
|
|
||||||
#
|
|
||||||
# Home Manager Module
|
|
||||||
#
|
|
||||||
flake.modules.homeManager.step-ssh-user = { config, pkgs, lib, ... }:
|
|
||||||
let
|
|
||||||
cfg = config.step-ssh-user;
|
|
||||||
firstPrincipal = lib.head cfg.principals;
|
|
||||||
principalArgs = lib.concatMapStringsSep " "
|
|
||||||
(principal: "--principal \"${principal}\"") cfg.principals;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.step-ssh-user = {
|
|
||||||
enable = lib.mkEnableOption "opionated step client config for SSH certs";
|
|
||||||
provisioner = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "admin";
|
|
||||||
};
|
|
||||||
principals = lib.mkOption {
|
|
||||||
type = lib.types.listOf lib.types.str;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
config = lib.mkIf cfg.enable {
|
|
||||||
sops.secrets."janus/admin_jwk".mode = "0400";
|
|
||||||
home.packages = with pkgs; [
|
|
||||||
(writeShellScriptBin "sign-ssh-cert" ''
|
|
||||||
${lib.getExe pkgs.step-cli} ssh certificate \
|
|
||||||
--sign \
|
|
||||||
${principalArgs} \
|
|
||||||
--provisioner "${cfg.provisioner}" \
|
|
||||||
--provisioner-password-file "${config.sops.secrets."janus/admin_jwk".path}" \
|
|
||||||
"${firstPrincipal}" "${config.ssh.identityFile}.pub"
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -2,39 +2,13 @@
|
|||||||
flake.modules.nixos.wireguard = { config, pkgs, lib, ... }:
|
flake.modules.nixos.wireguard = { config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
wgInterface = "platform";
|
wgInterface = "platform";
|
||||||
systemctl = lib.getExe' pkgs.systemd "systemctl";
|
|
||||||
journalctl = lib.getExe' pkgs.systemd "journalctl";
|
|
||||||
|
|
||||||
mkConnect = interface:
|
|
||||||
let
|
|
||||||
serviceName = "wg-quick-${interface}";
|
|
||||||
service = "${serviceName}.service";
|
|
||||||
in
|
|
||||||
pkgs.writeShellScriptBin "wg-connect-${interface}" ''
|
|
||||||
${systemctl} start ${service}
|
|
||||||
start_time=$(${systemctl} show -p ActiveEnterTimestamp ${serviceName} | cut -d= -f2)
|
|
||||||
${journalctl} -u ${service} --since "$start_time" --no-pager
|
|
||||||
'';
|
|
||||||
mkDisconnect = interface:
|
|
||||||
let
|
|
||||||
serviceName = "wg-quick-${interface}";
|
|
||||||
service = "${serviceName}.service";
|
|
||||||
in
|
|
||||||
pkgs.writeShellScriptBin "wg-disconnect-${interface}" ''
|
|
||||||
STOPTIME=$(${lib.getExe' pkgs.coreutils "date"} '+%Y-%m-%d %H:%M:%S')
|
|
||||||
${systemctl} stop ${service}
|
|
||||||
start_time=$(${systemctl} show -p ActiveEnterTimestamp ${serviceName} | cut -d= -f2)
|
|
||||||
${journalctl} -u ${service} --since "$STOPTIME" --no-pager
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ inputs.sops-nix.nixosModules.sops ];
|
imports = [ inputs.sops-nix.nixosModules.sops ];
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
wireguard-tools
|
wireguard-tools # https://github.com/WireGuard/wireguard-tools
|
||||||
wg-netmanager
|
# wg-netmanager # https://github.com/gin66/wg_netmanager
|
||||||
(mkConnect "platform")
|
|
||||||
(mkDisconnect "platform")
|
|
||||||
];
|
];
|
||||||
|
|
||||||
sops.secrets.wireguard_private_key = { };
|
sops.secrets.wireguard_private_key = { };
|
||||||
@@ -56,4 +30,39 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
perSystem = { system, pkgs, lib, ... }:
|
||||||
|
let
|
||||||
|
connect = pkgs.writeShellApplication {
|
||||||
|
name = "wg-platform-connect";
|
||||||
|
text = ''
|
||||||
|
sudo systemctl start wg-quick-platform.service
|
||||||
|
START_TIME=$(sudo systemctl show -p ActiveEnterTimestamp wg-quick-platform | cut -d= -f2)
|
||||||
|
journalctl -u wg-quick-platform --since "$START_TIME" --no-pager
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
disconnect = pkgs.writeShellApplication {
|
||||||
|
name = "wg-platform-disconnect";
|
||||||
|
text = ''
|
||||||
|
STOP_TIME=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
systemctl stop wg-quick-platform.service
|
||||||
|
journalctl -u wg-quick-platform.service --since "$STOP_TIME" --no-pager
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages.wg-platform = inputs.wrappers.lib.wrapPackage {
|
||||||
|
inherit pkgs;
|
||||||
|
runtimeInputs = with pkgs; [ coreutils systemd wireguard-tools ];
|
||||||
|
package = pkgs.symlinkJoin {
|
||||||
|
name = "wg-platform";
|
||||||
|
meta.mainProgram = "wg-platform-connect";
|
||||||
|
paths = [
|
||||||
|
connect
|
||||||
|
disconnect
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{ self, inputs, ... }:
|
||||||
|
let
|
||||||
|
packageName = "zed-editor";
|
||||||
|
|
||||||
|
zedWrapper = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
text-to-say = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = "Text for the ascii cow to say.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "my-pkg";
|
||||||
|
package = config.pkgs.cowsay;
|
||||||
|
args = [ config.text-to-say ];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
in
|
||||||
|
{
|
||||||
|
perSystem = { system, pkgs, lib, ... }: {
|
||||||
|
packages."${packageName}" = (zedWrapper.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
text-to-say = "Hello from wrapped module!";
|
||||||
|
}).wrapper;
|
||||||
|
};
|
||||||
|
|
||||||
|
flake.modules.homeManager."${packageName}" = { config, pkgs, lib, ... }: {
|
||||||
|
home.packages = [
|
||||||
|
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}."${packageName}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,25 @@
|
|||||||
{ inputs, ... }:
|
{ self, inputs, ... }:
|
||||||
let
|
let
|
||||||
username = "john";
|
username = "john";
|
||||||
|
historySize = 10000;
|
||||||
|
homeEndKeyBindings = ''
|
||||||
|
# Normalize common Home/End escape sequences across terminal emulators.
|
||||||
|
bindkey "^[[H" beginning-of-line
|
||||||
|
bindkey "^[[F" end-of-line
|
||||||
|
bindkey "^[[1~" beginning-of-line
|
||||||
|
bindkey "^[[4~" end-of-line
|
||||||
|
bindkey "^[[7~" beginning-of-line
|
||||||
|
bindkey "^[[8~" end-of-line
|
||||||
|
bindkey "^[OH" beginning-of-line
|
||||||
|
bindkey "^[OF" end-of-line
|
||||||
|
bindkey "^[[3~" delete-char
|
||||||
|
|
||||||
|
# Normalize common Ctrl+Arrow sequences for word-wise movement.
|
||||||
|
bindkey "^[[1;5D" backward-word
|
||||||
|
bindkey "^[[1;5C" forward-word
|
||||||
|
bindkey "^[[5D" backward-word
|
||||||
|
bindkey "^[[5C" forward-word
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.modules = {
|
flake.modules = {
|
||||||
@@ -16,11 +35,14 @@ in
|
|||||||
homeManager.zsh = { pkgs, config, ... }: {
|
homeManager.zsh = { pkgs, config, ... }: {
|
||||||
programs.zsh = {
|
programs.zsh = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.zsh;
|
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.jsl-zsh;
|
||||||
enableCompletion = true;
|
enableCompletion = true;
|
||||||
autosuggestion.enable = true;
|
autosuggestion.enable = true;
|
||||||
# syntaxHighlighting.enable = true;
|
# syntaxHighlighting.enable = true;
|
||||||
initContent = "HOST=$(hostname -s)";
|
initContent = ''
|
||||||
|
HOST=$(hostname -s)
|
||||||
|
${homeEndKeyBindings}
|
||||||
|
'';
|
||||||
dotDir = "${config.xdg.configHome}/zsh";
|
dotDir = "${config.xdg.configHome}/zsh";
|
||||||
history = {
|
history = {
|
||||||
append = true;
|
append = true;
|
||||||
@@ -31,8 +53,8 @@ in
|
|||||||
"eza"
|
"eza"
|
||||||
"clear"
|
"clear"
|
||||||
];
|
];
|
||||||
save = 1000;
|
save = historySize;
|
||||||
size = 1000;
|
size = historySize;
|
||||||
share = true;
|
share = true;
|
||||||
};
|
};
|
||||||
oh-my-zsh = {
|
oh-my-zsh = {
|
||||||
@@ -51,4 +73,71 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
perSystem = { config, self', pkgs, lib, ... }: {
|
||||||
|
packages.jsl-zsh =
|
||||||
|
let
|
||||||
|
ignorePatterns = [
|
||||||
|
"ls" "eza" "history" "clear"
|
||||||
|
];
|
||||||
|
aliasStr = lib.concatStringsSep "\n" (
|
||||||
|
lib.mapAttrsToList (k: v: "alias -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}") {
|
||||||
|
ls = "eza";
|
||||||
|
ll = "eza -l";
|
||||||
|
la = "eza -a";
|
||||||
|
lt = "eza --tree";
|
||||||
|
lla = "eza -la";
|
||||||
|
ds = "gdu -i /snap /";
|
||||||
|
ld = "lazydocker";
|
||||||
|
});
|
||||||
|
in
|
||||||
|
(inputs.wrappers.wrapperModules.zsh.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
binName = "jsl-zsh";
|
||||||
|
env = {
|
||||||
|
LANG = "en_US.UTF-8";
|
||||||
|
COLORTERM = "truecolor";
|
||||||
|
};
|
||||||
|
settings = {
|
||||||
|
completion = {
|
||||||
|
enable = true;
|
||||||
|
extraCompletions = true;
|
||||||
|
caseInsensitive = true;
|
||||||
|
fuzzySearch = true;
|
||||||
|
};
|
||||||
|
autoSuggestions = {
|
||||||
|
enable = true;
|
||||||
|
strategy = [ "history" "completion" ];
|
||||||
|
};
|
||||||
|
history = {
|
||||||
|
append = true;
|
||||||
|
expanded = true;
|
||||||
|
share = true;
|
||||||
|
ignoreAllDups = true;
|
||||||
|
ignoreSpace = true;
|
||||||
|
};
|
||||||
|
integrations = {
|
||||||
|
fzf.enable = true;
|
||||||
|
starship = {
|
||||||
|
enable = true;
|
||||||
|
package = self'.packages.starship;
|
||||||
|
};
|
||||||
|
zoxide.enable = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
extraRC = ''
|
||||||
|
${homeEndKeyBindings}
|
||||||
|
|
||||||
|
HISTFILE=$HOME/.config/zsh/.zsh_history
|
||||||
|
SAVEHIST=${toString historySize}
|
||||||
|
HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" ignorePatterns})"}
|
||||||
|
|
||||||
|
HOSTNAME=$(hostname -s)
|
||||||
|
${aliasStr}
|
||||||
|
'';
|
||||||
|
extraPackages = with pkgs; [
|
||||||
|
lazydocker
|
||||||
|
self'.packages.shell-tools
|
||||||
|
];
|
||||||
|
}).wrapper;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -102,6 +102,7 @@ in
|
|||||||
certs = mkEnableOption "Enable Janus and Soteria SSH targets";
|
certs = mkEnableOption "Enable Janus and Soteria SSH targets";
|
||||||
homelab = mkEnableOption "Enable various Homelab targets";
|
homelab = mkEnableOption "Enable various Homelab targets";
|
||||||
dev = mkEnableOption "Enable development targets";
|
dev = mkEnableOption "Enable development targets";
|
||||||
|
tailscale = mkEnableOption "Enable tailscale targets";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -175,6 +176,10 @@ in
|
|||||||
"docs" = {
|
"docs" = {
|
||||||
hostname = "192.168.1.110";
|
hostname = "192.168.1.110";
|
||||||
user = "root";
|
user = "root";
|
||||||
|
extraOptions = {
|
||||||
|
RequestTTY = "force";
|
||||||
|
RemoteCommand = "~/.nix-profile/bin/jsl-zsh";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
"gitea" = {
|
"gitea" = {
|
||||||
hostname = "192.168.1.104";
|
hostname = "192.168.1.104";
|
||||||
@@ -193,6 +198,20 @@ in
|
|||||||
"test-nix" = {
|
"test-nix" = {
|
||||||
hostname = "fded:fb16:653e:25da:be24:11ff:fea0:753f";
|
hostname = "fded:fb16:653e:25da:be24:11ff:fea0:753f";
|
||||||
user = "john";
|
user = "john";
|
||||||
|
extraOptions = {
|
||||||
|
RequestTTY = "auto";
|
||||||
|
# RemoteCommand = "/run/current-system/sw/bin/jsl-zsh";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
(lib.mkIf cfg.matchSets.tailscale {
|
||||||
|
"jdl-docker" = {
|
||||||
|
hostname = "jdl-docker.tailcf205.ts.net";
|
||||||
|
user = "john";
|
||||||
|
extraOptions = {
|
||||||
|
RequestTTY = "auto";
|
||||||
|
# RemoteCommand = "~/.nix-profile/bin/jsl-zsh";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|||||||
+25
-24
@@ -1,6 +1,10 @@
|
|||||||
{ self, inputs, lib, ... }:
|
{ self, inputs, lib, ... }:
|
||||||
let
|
let
|
||||||
username = "john";
|
username = "john";
|
||||||
|
baseUserModules = self.factory.user {
|
||||||
|
username = username;
|
||||||
|
isAdmin = true;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.meta.users."${username}" = {
|
flake.meta.users."${username}" = {
|
||||||
@@ -8,41 +12,38 @@ in
|
|||||||
name = "John Lancaster";
|
name = "John Lancaster";
|
||||||
inherit username;
|
inherit username;
|
||||||
key = "";
|
key = "";
|
||||||
keygrip = [
|
keygrip = [ ];
|
||||||
];
|
|
||||||
authorizedKeys = [
|
authorizedKeys = [
|
||||||
# "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIAUa4dcg1TWc4pW++uodyhX4eOqrX/QYIxFWtEP7HFJ john@john-pc-ubuntu"
|
# "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIAUa4dcg1TWc4pW++uodyhX4eOqrX/QYIxFWtEP7HFJ john@john-pc-ubuntu"
|
||||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMOkGLo4N/L3RYvaIZ1FmePlxa1HK0fMciZxKtRhN58F root@janus"
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMOkGLo4N/L3RYvaIZ1FmePlxa1HK0fMciZxKtRhN58F root@janus"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.modules = lib.mkMerge [
|
flake.modules = {
|
||||||
(self.factory.user {
|
nixos."${username}" = { ... }: {
|
||||||
username = username;
|
imports = [
|
||||||
isAdmin = true;
|
baseUserModules.nixos."${username}"
|
||||||
})
|
];
|
||||||
{
|
users.users."${username}" = {
|
||||||
nixos."${username}" = {
|
openssh.authorizedKeys.keys = inputs.self.meta.users."${username}".authorizedKeys;
|
||||||
imports = [
|
|
||||||
inputs.home-manager.nixosModules.home-manager
|
|
||||||
];
|
|
||||||
users.users."${username}" = {
|
|
||||||
openssh.authorizedKeys.keys = inputs.self.meta.users."${username}".authorizedKeys;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# This module will be imported by the user factory
|
# This module will be imported by the user factory
|
||||||
homeManager."${username}" = with inputs.self.meta.users."${username}"; {
|
homeManager."${username}" = { pkgs, ... }:
|
||||||
|
with inputs.self.meta.users."${username}"; {
|
||||||
home.stateVersion = "25.11";
|
home.stateVersion = "25.11";
|
||||||
|
imports = [
|
||||||
|
inputs.self.modules.homeManager.shell-tools
|
||||||
|
inputs.self.modules.homeManager.ssh
|
||||||
|
inputs.self.modules.homeManager.git
|
||||||
|
];
|
||||||
|
# home.packages = [
|
||||||
|
# inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.shell-tools
|
||||||
|
# ];
|
||||||
xdg.enable = true;
|
xdg.enable = true;
|
||||||
programs.git.settings.user.name = name;
|
programs.git.settings.user.name = name;
|
||||||
programs.git.settings.user.email = email;
|
programs.git.settings.user.email = email;
|
||||||
imports = with inputs.self.modules.homeManager; [
|
|
||||||
ssh
|
|
||||||
shell-tools
|
|
||||||
git
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user