From 7ff57aa6e4bae15c1a322e2fc204fe9a973dd777 Mon Sep 17 00:00:00 2001 From: oddlama Date: Fri, 6 Jan 2023 00:16:05 +0100 Subject: [PATCH] fix: import upstream (lovesegfault's) changes to hosts structure --- flake.lock | 18 ++++----- flake.nix | 13 ++++--- hosts/nom/disko.nix | 93 ++++++++++++++++++++++++++++++++++++++++++++ nix/checks.nix | 23 ----------- nix/dev-shell.nix | 1 - nix/home-manager.nix | 13 ++++++- nix/host-drvs.nix | 2 +- nix/hosts.nix | 37 ++++++++++++------ nix/nixos.nix | 2 +- 9 files changed, 148 insertions(+), 54 deletions(-) create mode 100644 hosts/nom/disko.nix diff --git a/flake.lock b/flake.lock index 919ae8b..7c75eda 100644 --- a/flake.lock +++ b/flake.lock @@ -109,11 +109,11 @@ ] }, "locked": { - "lastModified": 1672780900, - "narHash": "sha256-DxuSn6BdkZapIbg76xzYx1KhVPEZeBexMkt1q/sMVPA=", + "lastModified": 1672954852, + "narHash": "sha256-xkMJs1KTyKwxVErNdbgC4K6GRHU24Uv2DhbcFtfzLrk=", "owner": "nix-community", "repo": "home-manager", - "rev": "54245e1820caabd8a0b53ce4d47e4d0fefe04cd4", + "rev": "3ecd5305a41b6dd87f6cdf8cfe83ac07bdc47a0f", "type": "github" }, "original": { @@ -154,11 +154,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1672617983, - "narHash": "sha256-68WDiCBs631mbDDk4UAKdGURKcsfW6hjb7wgudTAe5o=", + "lastModified": 1672791794, + "narHash": "sha256-mqGPpGmwap0Wfsf3o2b6qHJW1w2kk/I6cGCGIU+3t6o=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0fc9fca9c8d43edd79d33fea0dd8409d7c4580f4", + "rev": "9813adc7f7c0edd738c6bdd8431439688bb0cb3d", "type": "github" }, "original": { @@ -199,11 +199,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1672734157, - "narHash": "sha256-uwUBnv0bN1SO4QVIo8KUx/jxRYCy7cW8kzZa+Qsrw9k=", + "lastModified": 1672912243, + "narHash": "sha256-QnQeKUjco2kO9J4rBqIBPp5XcOMblIMnmyhpjeaJBYc=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "d0ce0a861260493c6c21f16f59d25076f73cb931", + "rev": "a4548c09eac4afb592ab2614f4a150120b29584c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index bf85dd7..9228f4d 100644 --- a/flake.nix +++ b/flake.nix @@ -59,11 +59,14 @@ checks = import ./nix/checks.nix inputs localSystem; devShells.default = import ./nix/dev-shell.nix inputs localSystem; - legacyPackages = - { - default = self.packages.${localSystem}.all; - } - // (import ./nix/host-drvs.nix inputs localSystem); + packages = let + hostDrvs = import ./nix/host-drvs.nix inputs localSystem; + default = + if builtins.hasAttr "${localSystem}" hostDrvs + then {default = self.packages.${localSystem}.${localSystem};} + else {}; + in + hostDrvs // default; pkgs = import nixpkgs { inherit localSystem; diff --git a/hosts/nom/disko.nix b/hosts/nom/disko.nix new file mode 100644 index 0000000..1ff831a --- /dev/null +++ b/hosts/nom/disko.nix @@ -0,0 +1,93 @@ +{ + nom = { + disk = { + "Intenso_SSD_3833430-532201046" = { + type = "disk"; + device = "/dev/disk/by-id/ata-Intenso_SSD_3833430-532201046"; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + type = "partition"; + name = "efi"; + start = "2048"; + end = "8GiB"; + fs-type = "fat32"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + } + { + type = "partition"; + name = "swap"; + start = "8GiB"; + end = "100%"; + content = { + type = "swap"; + randomEncryption = true; + }; + } + ]; + }; + }; + "Samsung_SSD_980_PRO_1TB_S5GXNX1T325329W" = { + type = "disk"; + device = "/dev/disk/by-id/nvme-Samsung_SSD_980_PRO_1TB_S5GXNX1T325329W"; + content = { + type = "zfs"; + pool = "rpool"; + }; + }; + }; + zpool = { + rpool = { + type = "zpool"; + mode = "mirror"; + rootFsOptions = { + compression = "zstd"; + acltype = "posix"; + atime = "off"; + xattr = "sa"; + dnodesize = "auto"; + mountpoint = "none"; + canmount = "off"; + devices = "off"; + encryption = "aes-256-gcm"; + keyformat = "passphrase"; + keylocation = "prompt"; + "autobackup:snap" = "true"; + "autobackup:home" = "true"; + }; + options = { + ashift = "12"; + bootfs = "rpool/root/nixos"; + }; + datasets = { + "root" = { + zfs_type = "filesystem"; + }; + "root/nixos" = { + zfs_type = "filesystem"; + options = { + canmount = "on"; + mountpoint = "/"; + }; + }; + "home" = { + zfs_type = "filesystem"; + }; + "home/root" = { + zfs_type = "filesystem"; + options = { + canmount = "on"; + mountpoint = "/root"; + }; + }; + }; + }; + }; + }; +} diff --git a/nix/checks.nix b/nix/checks.nix index ca41ec1..e6208c1 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -12,33 +12,10 @@ with self.pkgs.${system}; hooks = { actionlint.enable = true; luacheck.enable = true; - #nix-linter.enable = true; alejandra.enable = true; statix.enable = true; stylua.enable = true; }; - #settings.nix-linter.checks = [ - # "DIYInherit" - # "EmptyInherit" - # "EmptyLet" - # "EtaReduce" - # "LetInInheritRecset" - # "ListLiteralConcat" - # "NegateAtom" - # "SequentialLet" - # "SetLiteralUpdate" - # "UnfortunateArgName" - # "UnneededRec" - # "UnusedArg" - # "UnusedLetBind" - # "UpdateEmptySet" - # "BetaReduction" - # "EmptyVariadicParamSet" - # "UnneededAntiquote" - # "no-FreeLetInFunc" - # "no-AlphabeticalArgs" - # "no-AlphabeticalBindings" - #]; }; } // (deploy-rs.lib.deployChecks self.deploy) diff --git a/nix/dev-shell.nix b/nix/dev-shell.nix index e25740c..c8ab043 100644 --- a/nix/dev-shell.nix +++ b/nix/dev-shell.nix @@ -8,7 +8,6 @@ with self.pkgs.${system}; cachix deploy-rs.deploy-rs nix-build-uncached - #nix-linter alejandra ragenix rnix-lsp diff --git a/nix/home-manager.nix b/nix/home-manager.nix index 17d8a3c..cfb2852 100644 --- a/nix/home-manager.nix +++ b/nix/home-manager.nix @@ -6,9 +6,18 @@ ... }: let inherit (nixpkgs) lib; - hosts = (import ./hosts.nix).homeManager.all; + hosts = let + hostsNix = import ./hosts.nix; + in + if builtins.hasAttr "homeManager" hostsNix + then hostsNix.homeManager + else {}; - genModules = hostName: {homeDirectory, ...}: {config, ...}: { + genModules = hostName: {homeDirectory, ...}: { + config, + pkgs, + ... + }: { imports = [(../hosts + "/${hostName}")]; nix.registry = { nixpkgs.flake = nixpkgs; diff --git a/nix/host-drvs.nix b/nix/host-drvs.nix index c417321..d94862f 100644 --- a/nix/host-drvs.nix +++ b/nix/host-drvs.nix @@ -9,7 +9,7 @@ structuredHostDrvs = lib.mapAttrsRecursiveCond - (as: !(as ? "type" && (lib.elem as.type ["home-manager" "nixos"]))) + (hostAttr: !(hostAttr ? "type" && (lib.elem hostAttr.type ["homeManager" "nixos"]))) (path: _: hostDrvs.${lib.last path}) hosts; diff --git a/nix/hosts.nix b/nix/hosts.nix index 0152b18..2efdb16 100644 --- a/nix/hosts.nix +++ b/nix/hosts.nix @@ -14,7 +14,7 @@ let }; }; - inherit (builtins) attrNames concatMap listToAttrs; + inherit (builtins) attrNames concatMap listToAttrs filter; filterAttrs = pred: set: listToAttrs (concatMap (name: let @@ -24,18 +24,31 @@ let then [{inherit name value;}] else []) (attrNames set)); - systemPred = system: (_: v: builtins.match ".*${system}.*" v.hostPlatform != null); + removeEmptyAttrs = filterAttrs (_: v: v != {}); - genFamily = filter: hosts: rec { - all = filterAttrs filter hosts; + genSystemGroups = hosts: let + systems = ["aarch64-linux" "x86_64-linux"]; + systemHostGroup = name: { + inherit name; + value = filterAttrs (_: host: host.hostPlatform == name) hosts; + }; + in + removeEmptyAttrs (listToAttrs (map systemHostGroup systems)); - nixos = genFamily (_: v: v.type == "nixos") all; - homeManager = genFamily (_: v: v.type == "home-manager") all; + genTypeGroups = hosts: let + types = ["homeManager" "nixos"]; + typeHostGroup = name: { + inherit name; + value = filterAttrs (_: host: host.type == name) hosts; + }; + in + removeEmptyAttrs (listToAttrs (map typeHostGroup types)); - linux = genFamily (systemPred "-linux") all; - - aarch64-linux = genFamily (systemPred "aarch64-linux") all; - x86_64-linux = genFamily (systemPred "x86_64-linux") all; - }; + genHostGroups = hosts: let + all = hosts; + systemGroups = genSystemGroups all; + typeGroups = genTypeGroups all; + in + all // systemGroups // typeGroups // {inherit all;}; in - genFamily (_: _: true) hosts + genHostGroups hosts diff --git a/nix/nixos.nix b/nix/nixos.nix index b951353..1823139 100644 --- a/nix/nixos.nix +++ b/nix/nixos.nix @@ -9,7 +9,7 @@ ... }: let inherit (nixpkgs) lib; - hosts = (import ./hosts.nix).nixos.all; + hosts = (import ./hosts.nix).nixos; nixRegistry = { nix.registry = {