mirror of
https://github.com/srid/nixos-config.git
synced 2026-03-03 18:35:15 +08:00
Isolate common nix into lib.nix
This commit is contained in:
parent
2fdf57226a
commit
08bfaa4e88
6 changed files with 93 additions and 85 deletions
87
lib.nix
Normal file
87
lib.nix
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
# Support code for this repo. This module could be made its own external repo.
|
||||
{ self, inputs, config, ... }:
|
||||
{
|
||||
flake = {
|
||||
# Linux home-manager module
|
||||
nixosModules.home-manager = {
|
||||
imports = [
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
({
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.extraSpecialArgs = {
|
||||
inherit inputs;
|
||||
system = "x86_64-linux";
|
||||
flake = { inherit config; };
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
# macOS home-manager module
|
||||
darwinModules.home-manager = {
|
||||
imports = [
|
||||
inputs.home-manager.darwinModules.home-manager
|
||||
({
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.extraSpecialArgs = {
|
||||
inherit inputs;
|
||||
system = "aarch64-darwin";
|
||||
flake = { inherit config; };
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
lib = {
|
||||
mkLinuxSystem = mod: inputs.nixpkgs.lib.nixosSystem rec {
|
||||
system = "x86_64-linux";
|
||||
# Arguments to pass to all modules.
|
||||
specialArgs = {
|
||||
inherit system inputs;
|
||||
flake = { inherit config; };
|
||||
};
|
||||
modules = [ mod ];
|
||||
};
|
||||
|
||||
mkMacosSystem = mod: inputs.darwin.lib.darwinSystem rec {
|
||||
system = "aarch64-darwin";
|
||||
specialArgs = {
|
||||
inherit inputs system;
|
||||
flake = { inherit config; };
|
||||
rosettaPkgs = import inputs.nixpkgs { system = "x86_64-darwin"; };
|
||||
};
|
||||
modules = [ mod ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
perSystem = { system, pkgs, lib, ... }: {
|
||||
# A rough app for activating the system locally.
|
||||
#
|
||||
# TODO: Replace with deploy-rs or (new) nixinate
|
||||
apps.activate =
|
||||
let
|
||||
# Create a flake app that wraps the given bash CLI.
|
||||
bashCmdApp = name: cmd: {
|
||||
type = "app";
|
||||
program =
|
||||
(pkgs.writeShellApplication {
|
||||
inherit name;
|
||||
text = ''
|
||||
set -x
|
||||
${cmd}
|
||||
'';
|
||||
}) + "/bin/${name}";
|
||||
};
|
||||
in
|
||||
if system == "aarch64-darwin" then
|
||||
bashCmdApp "darwin" ''
|
||||
${self.darwinConfigurations.default.system}/sw/bin/darwin-rebuild \
|
||||
switch --flake ${self}#default
|
||||
''
|
||||
else
|
||||
bashCmdApp "linux" ''
|
||||
${lib.getExe pkgs.nixos-rebuild} --use-remote-sudo switch -j auto
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue