Nix multi-platform.

This commit is contained in:
Joseph Hanson 2024-02-23 15:36:14 -06:00
parent 93549025ff
commit db86fe6244
3 changed files with 119 additions and 1 deletions

View file

@ -1,5 +1,43 @@
{ {
"nodes": { "nodes": {
"deploy-rs": {
"inputs": {
"flake-compat": "flake-compat",
"nixpkgs": [
"nixpkgs"
],
"utils": "utils"
},
"locked": {
"lastModified": 1708091384,
"narHash": "sha256-dTGGw2y8wvfjr+J9CjQbfdulOq72hUG17HXVNxpH1yE=",
"owner": "serokell",
"repo": "deploy-rs",
"rev": "0a0187794ac7f7a1e62cda3dabf8dc041f868790",
"type": "github"
},
"original": {
"owner": "serokell",
"repo": "deploy-rs",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": { "flake-parts": {
"inputs": { "inputs": {
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib"
@ -113,6 +151,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"deploy-rs": "deploy-rs",
"home-manager": "home-manager", "home-manager": "home-manager",
"nix-fast-build": "nix-fast-build", "nix-fast-build": "nix-fast-build",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
@ -140,6 +179,21 @@
"type": "github" "type": "github"
} }
}, },
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": { "treefmt-nix": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -160,6 +214,24 @@
"repo": "treefmt-nix", "repo": "treefmt-nix",
"type": "github" "type": "github"
} }
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View file

@ -39,7 +39,24 @@
# The `@` syntax here is used to alias the attribute set of the # The `@` syntax here is used to alias the attribute set of the
# inputs's parameter, making it convenient to use inside the function. # inputs's parameter, making it convenient to use inside the function.
outputs = { self, nixpkgs, home-manager, ... }@inputs: { outputs = { self, nixpkgs, home-manager, ... }@inputs:
let
forAllSystems = nixpkgs.lib.genAttrs [
"aarch64-linux"
"x86_64-linux"
];
in
{
pkgs = forAllSystems (localSystem: import nixpkgs {
inherit localSystem;
config = {
allowUnfree = true;
allowAliases = true;
};
});
packages = forAllSystems (import ./packages inputs);
nixosConfigurations = { nixosConfigurations = {
"durincore" = nixpkgs.lib.nixosSystem { "durincore" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
@ -87,5 +104,6 @@
]; ];
}; };
}; };
}; };
} }

28
packages/default.nix Normal file
View file

@ -0,0 +1,28 @@
{
self,
nix-fast-build,
...
}:
hostPlatform:
let
inherit (self.pkgs.${hostPlatform}) callPackage lib linkFarm;
nixosDrvs = lib.mapAttrs (_: nixos: nixos.config.system.build.toplevel) self.nixosConfigurations;
darwinDrvs = lib.mapAttrs (_: darwin: darwin.system) self.darwinConfigurations;
hostDrvs = nixosDrvs // darwinDrvs;
compatHosts = lib.filterAttrs (_: host: host.hostPlatform == hostPlatform) self.hosts;
compatHostDrvs = lib.mapAttrs
(name: _: hostDrvs.${name})
compatHosts;
compatHostsFarm = linkFarm "hosts-${hostPlatform}" (lib.mapAttrsToList (name: path: { inherit name path; }) compatHostDrvs);
in
compatHostDrvs
// (lib.optionalAttrs (compatHosts != { }) {
default = compatHostsFarm;
}) // {
inherit (nix-fast-build.packages.${hostPlatform}) nix-fast-build;
inherit (self.pkgs.${hostPlatform}) cachix nix-eval-jobs;
}