From 45b63706a4f08d2de5abb794e01fb2c932166d47 Mon Sep 17 00:00:00 2001 From: asnev Date: Tue, 27 Oct 2026 23:43:06 +0700 Subject: [PATCH] moved systemConstants out of flake-parts namespace also added `systemConstants` as module argument --- modules/generic/system-constants.nix | 34 -------------------- modules/home/primaryUser/programs/git.nix | 14 ++++---- modules/hosts/phostron/entry.nix | 19 ++++------- modules/nixpkgs.nix | 26 +++++---------- modules/system-constants.nix | 39 +++++++++++++++++++++++ modules/users.nix | 27 +++++++++------- 6 files changed, 76 insertions(+), 83 deletions(-) delete mode 100644 modules/generic/system-constants.nix create mode 100644 modules/system-constants.nix diff --git a/modules/generic/system-constants.nix b/modules/generic/system-constants.nix deleted file mode 100644 index 1772668..0000000 --- a/modules/generic/system-constants.nix +++ /dev/null @@ -1,34 +0,0 @@ -{self, ...}: let - imports = [self.modules.generic.systemConstants]; -in { - flake.modules.generic.systemConstants = {config, lib, ...}: { - options.systemConstants = lib.mkOption { - type = lib.types.lazyAttrsOf lib.types.unspecified; - default = {}; - }; - - config.systemConstants = { - repositoryOwnerUsername = "asnev"; - repositoryOwnerEmail = "notasnev@proton.me"; - - nixpkgsStateVersion = "26.05"; - nixpkgsAllowUnfree = true; - - homeManagerStateVersion = config.systemConstants.nixpkgsStateVersion; - - primaryUserUsername = "coyote"; - primaryUserHomeDirectory = "/home/coyote"; - primaryUserId = 1000; - - phostronHostname = "phostron"; - phostronHostPlatform = "x86_64-linux"; - phostronStateVersion = config.systemConstants.nixpkgsStateVersion; - }; - }; - - perSystem = {inherit imports;}; - flake.modules = { - nixos.base = {inherit imports;}; - homeManager.primaryUser = {inherit imports;}; - }; -} diff --git a/modules/home/primaryUser/programs/git.nix b/modules/home/primaryUser/programs/git.nix index 4224f6b..6c34e8c 100644 --- a/modules/home/primaryUser/programs/git.nix +++ b/modules/home/primaryUser/programs/git.nix @@ -1,21 +1,21 @@ -{ - flake.modules.homeManager.primaryUser = {config, ...}: { +{systemConstants, ...}: { + flake.modules.homeManager.primaryUser = { programs.git = { enable = true; settings = { - user.name = config.systemConstants.repositoryOwnerUsername; - user.email = config.systemConstants.repositoryOwnerEmail; + user.name = systemConstants.repositoryOwnerUsername; + user.email = systemConstants.repositoryOwnerEmail; }; signing = { - key = "${config.systemConstants.primaryUserHomeDirectory}/.ssh/id_ed25519.pub"; + key = "${systemConstants.primaryUserHomeDirectory}/.ssh/id_ed25519.pub"; format = "ssh"; }; includes = [ { - condition = "gitdir:${config.systemConstants.primaryUserHomeDirectory}/NixOS/"; - contents.core.sshCommand = "ssh -i ${config.systemConstants.primaryUserHomeDirectory}/.ssh/id_ed25519"; + condition = "gitdir:${systemConstants.primaryUserInfraDirectory}"; + contents.core.sshCommand = "ssh -i ${systemConstants.primaryUserHomeDirectory}/.ssh/id_ed25519"; } ]; }; diff --git a/modules/hosts/phostron/entry.nix b/modules/hosts/phostron/entry.nix index 8b5941a..9b738ca 100644 --- a/modules/hosts/phostron/entry.nix +++ b/modules/hosts/phostron/entry.nix @@ -1,20 +1,13 @@ { - self, inputs, + self, + systemConstants, ... }: { - flake.modules.nixos.phostron = { - config, - lib, - ... - }: { - networking.hostName = config.systemConstants.phostronHostname; - nixpkgs.hostPlatform = lib.mkDefault config.systemConstants.phostronHostPlatform; - system.stateVersion = config.systemConstants.phostronStateVersion; - }; - - flake.modules.homeManager.primaryUser = {config, ...}: { - home.stateVersion = config.systemConstants.phostronStateVersion; + flake.modules.nixos.phostron = {lib, ...}: { + networking.hostName = systemConstants.phostronHostname; + nixpkgs.hostPlatform = lib.mkDefault systemConstants.phostronHostPlatform; + system.stateVersion = systemConstants.phostronStateVersion; }; flake.nixosConfigurations.phostron = inputs.nixpkgs.lib.nixosSystem { diff --git a/modules/nixpkgs.nix b/modules/nixpkgs.nix index cd22b11..d2e5002 100644 --- a/modules/nixpkgs.nix +++ b/modules/nixpkgs.nix @@ -1,37 +1,27 @@ { inputs, - self, + systemConstants, ... }: let - overlays = [self.overlays.default]; + overlays = systemConstants.nixpkgsOverlays; + config = {allowUnfree = systemConstants.nixpkgsAllowUnfree;}; in { flake-file.inputs = { - nixpkgs.url = "https://channels.nixos.org/nixos-26.05/nixexprs.tar.zst"; + nixpkgs.url = "https://channels.nixos.org/nixos-${systemConstants.nixpkgsStableVersion}/nixexprs.tar.zst"; nixpkgs-unstable.url = "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1100280.3ec636362e18/nixexprs.tar.zst"; nixpkgs-lib.follows = "nixpkgs-unstable"; }; perSystem = { - config, final, system, ... }: { - _module.args.pkgs = import inputs.nixpkgs { - inherit system overlays; - config.allowUnfree = config.systemConstants.nixpkgsAllowUnfree; - }; - - overlayAttrs.unstable = import inputs.nixpkgs-unstable { - inherit system; - config.allowUnfree = config.systemConstants.nixpkgsAllowUnfree; - }; + _module.args.pkgs = import inputs.nixpkgs {inherit system overlays config;}; + overlayAttrs.unstable = import inputs.nixpkgs-unstable {inherit system config;}; }; - flake.modules.nixos.base = {config, ...}: { - nixpkgs = { - inherit overlays; - config.allowUnfree = config.systemConstants.nixpkgsAllowUnfree; - }; + flake.modules.nixos.base = { + nixpkgs = {inherit overlays config;}; }; } diff --git a/modules/system-constants.nix b/modules/system-constants.nix new file mode 100644 index 0000000..f0060d8 --- /dev/null +++ b/modules/system-constants.nix @@ -0,0 +1,39 @@ +{ + config, + lib, + pkgs, + self, + ... +}: { + options.systemConstants = lib.mkOption { + type = lib.types.lazyAttrsOf lib.types.unspecified; + default = {}; + }; + + config.systemConstants = rec { + infraName = "chitin"; + + repositoryOwnerUsername = "asnev"; + repositoryOwnerEmail = "notasnev@proton.me"; + + nixpkgsStableVersion = "26.05"; # did you read the "did you read the comment?" comment? + nixpkgsAllowUnfree = true; + nixpkgsOverlays = [self.overlays.default]; + + phostronHostname = "phostron"; + phostronHostPlatform = "x86_64-linux"; + phostronStateVersion = nixpkgsStableVersion; + + homeManagerStateVersion = nixpkgsStableVersion; + + primaryUserUsername = "coyote"; + primaryUserHomeDirectory = + if pkgs.stdenv.hostPlatform.isLinux + then "/home/${primaryUserUsername}" + else throw "Unsupported platform: ${pkgs.stdenv.hostPlatform.system}"; + primaryUserInfraDirectory = "${primaryUserHomeDirectory}/${infraName}"; + primaryUserId = 1000; + }; + + config._module.args.systemConstants = config.systemConstants; +} diff --git a/modules/users.nix b/modules/users.nix index 2e8218a..5d52d56 100644 --- a/modules/users.nix +++ b/modules/users.nix @@ -1,10 +1,14 @@ -{self, ...}: { - flake.modules.nixos.primaryUser = {config, ...}: { - users.users.${config.systemConstants.primaryUserUsername} = { +{ + self, + systemConstants, + ... +}: { + flake.modules.nixos.primaryUser = { + users.users.${systemConstants.primaryUserUsername} = { isNormalUser = true; - description = config.systemConstants.primaryUserUsername; - home = config.systemConstants.primaryUserHomeDirectory; - uid = config.systemConstants.primaryUserId; + description = systemConstants.primaryUserUsername; + home = systemConstants.primaryUserHomeDirectory; + uid = systemConstants.primaryUserId; extraGroups = [ "wheel" "networkmanager" @@ -19,15 +23,16 @@ }; }; - flake.modules.nixos.homeManagerModule = {config, ...}: { - home-manager.users.${config.systemConstants.primaryUserUsername} = self.modules.homeManager.primaryUser; + flake.modules.nixos.homeManagerModule = { + home-manager.users.${systemConstants.primaryUserUsername} = self.modules.homeManager.primaryUser; }; - flake.modules.homeManager.primaryUser = {config, ...}: { + flake.modules.homeManager.primaryUser = { home = { - username = config.systemConstants.primaryUserUsername; - homeDirectory = config.systemConstants.primaryUserHomeDirectory; + username = systemConstants.primaryUserUsername; + homeDirectory = systemConstants.primaryUserHomeDirectory; shell.enableShellIntegration = true; + stateVersion = systemConstants.homeManagerStateVersion; }; }; }