mirror of
https://github.com/srid/nixos-config.git
synced 2025-12-26 15:04:59 +08:00
Move lib.nix to nixos-flake
This commit is contained in:
parent
7675a76b1b
commit
d2ab5c2003
4 changed files with 44 additions and 142 deletions
|
|
@ -1,4 +1,4 @@
|
|||
This repository contains the Nix / NixOS configuration for all of my systems.
|
||||
This repository contains the Nix / NixOS configuration for all of my systems. See [nixos-template](https://github.com/srid/nixos-template) for the common base.
|
||||
|
||||
## Setup
|
||||
|
||||
|
|
|
|||
60
flake.lock
generated
60
flake.lock
generated
|
|
@ -72,27 +72,6 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"darwin": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1673295039,
|
||||
"narHash": "sha256-AsdYgE8/GPwcelGgrntlijMg4t3hLFJFCRF3tL5WVjA=",
|
||||
"owner": "lnl7",
|
||||
"repo": "nix-darwin",
|
||||
"rev": "87b9d090ad39b25b2400029c64825fc2a8868943",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "lnl7",
|
||||
"ref": "master",
|
||||
"repo": "nix-darwin",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"ema": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
|
|
@ -435,6 +414,27 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix-darwin_2": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1673295039,
|
||||
"narHash": "sha256-AsdYgE8/GPwcelGgrntlijMg4t3hLFJFCRF3tL5WVjA=",
|
||||
"owner": "lnl7",
|
||||
"repo": "nix-darwin",
|
||||
"rev": "87b9d090ad39b25b2400029c64825fc2a8868943",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "lnl7",
|
||||
"ref": "master",
|
||||
"repo": "nix-darwin",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix-serve-ng": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat_2",
|
||||
|
|
@ -455,6 +455,21 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixos-flake": {
|
||||
"locked": {
|
||||
"lastModified": 1678904900,
|
||||
"narHash": "sha256-+V7g48xaUPihdRTFaZesfHOLyZBFLodPTHLOptY5vWs=",
|
||||
"owner": "srid",
|
||||
"repo": "nixos-flake",
|
||||
"rev": "8f27f6311c31220a5122353f925f3d858d2d8666",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "srid",
|
||||
"repo": "nixos-flake",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixos-hardware": {
|
||||
"locked": {
|
||||
"lastModified": 1678397099,
|
||||
|
|
@ -745,13 +760,14 @@
|
|||
"agenix": "agenix",
|
||||
"coc-rust-analyzer": "coc-rust-analyzer",
|
||||
"comma": "comma",
|
||||
"darwin": "darwin",
|
||||
"emacs-overlay": "emacs-overlay",
|
||||
"emanote": "emanote",
|
||||
"flake-parts": "flake-parts_2",
|
||||
"hci": "hci",
|
||||
"home-manager": "home-manager",
|
||||
"nix-darwin": "nix-darwin_2",
|
||||
"nix-serve-ng": "nix-serve-ng",
|
||||
"nixos-flake": "nixos-flake",
|
||||
"nixos-hardware": "nixos-hardware",
|
||||
"nixos-shell": "nixos-shell",
|
||||
"nixos-vscode-server": "nixos-vscode-server",
|
||||
|
|
|
|||
10
flake.nix
10
flake.nix
|
|
@ -5,12 +5,13 @@
|
|||
# Principle inputs
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
darwin.url = "github:lnl7/nix-darwin/master";
|
||||
darwin.inputs.nixpkgs.follows = "nixpkgs";
|
||||
nix-darwin.url = "github:lnl7/nix-darwin/master";
|
||||
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
|
||||
home-manager.url = "github:nix-community/home-manager";
|
||||
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||
agenix.url = "github:ryantm/agenix";
|
||||
nixos-hardware.url = "github:NixOS/nixos-hardware";
|
||||
nixos-flake.url = "github:srid/nixos-flake";
|
||||
|
||||
# CI server
|
||||
hci.url = "github:hercules-ci/hercules-ci-agent";
|
||||
|
|
@ -35,11 +36,11 @@
|
|||
coc-rust-analyzer.flake = false;
|
||||
};
|
||||
|
||||
outputs = inputs@{ self, home-manager, nixpkgs, darwin, ... }:
|
||||
outputs = inputs@{ self, ... }:
|
||||
inputs.flake-parts.lib.mkFlake { inherit (inputs) self; } {
|
||||
systems = [ "x86_64-linux" "aarch64-darwin" ];
|
||||
imports = [
|
||||
./lib.nix
|
||||
inputs.nixos-flake.flakeModule
|
||||
./users
|
||||
./home
|
||||
./nixos
|
||||
|
|
@ -47,7 +48,6 @@
|
|||
];
|
||||
|
||||
flake = {
|
||||
flakeModule = ./lib.nix;
|
||||
# Configurations for Linux (NixOS) systems
|
||||
nixosConfigurations = {
|
||||
pce = self.lib.mkLinuxSystem {
|
||||
|
|
|
|||
114
lib.nix
114
lib.nix
|
|
@ -1,114 +0,0 @@
|
|||
# Support code for this repo. This module could be made its own external repo.
|
||||
{ self, inputs, config, flake-parts-lib, lib, ... }:
|
||||
let
|
||||
inherit (flake-parts-lib)
|
||||
mkPerSystemOption;
|
||||
inherit (lib)
|
||||
types;
|
||||
specialArgsFor = rec {
|
||||
common = {
|
||||
flake = { inherit inputs config; };
|
||||
};
|
||||
x86_64-linux = common // {
|
||||
system = "x86_64-linux";
|
||||
};
|
||||
aarch64-darwin = common // {
|
||||
system = "aarch64-darwin";
|
||||
rosettaPkgs = import inputs.nixpkgs { system = "x86_64-darwin"; };
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options = {
|
||||
perSystem = mkPerSystemOption
|
||||
({ config, self', inputs', pkgs, system, ... }: {
|
||||
options.nixos-template = lib.mkOption {
|
||||
default = { };
|
||||
type = types.submodule {
|
||||
options = {
|
||||
primary-inputs = lib.mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ "nixpkgs" "home-manager" "darwin" "nixos-hardware" ];
|
||||
description = ''
|
||||
List of flake inputs to update when running `nix run .#update`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
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 = specialArgsFor.x86_64-linux;
|
||||
})
|
||||
];
|
||||
};
|
||||
# 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 = specialArgsFor.aarch64-darwin;
|
||||
})
|
||||
];
|
||||
};
|
||||
lib = {
|
||||
mkLinuxSystem = mod: inputs.nixpkgs.lib.nixosSystem rec {
|
||||
system = "x86_64-linux";
|
||||
# Arguments to pass to all modules.
|
||||
specialArgs = specialArgsFor.${system};
|
||||
modules = [ mod ];
|
||||
};
|
||||
|
||||
mkMacosSystem = mod: inputs.darwin.lib.darwinSystem rec {
|
||||
system = "aarch64-darwin";
|
||||
specialArgs = specialArgsFor.${system};
|
||||
modules = [ mod ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
perSystem = { system, config, pkgs, lib, ... }: {
|
||||
packages = {
|
||||
update =
|
||||
let
|
||||
inputs = config.nixos-template.primary-inputs;
|
||||
in
|
||||
pkgs.writeShellApplication {
|
||||
name = "update-main-flake-inputs";
|
||||
text = ''
|
||||
nix flake lock ${lib.foldl' (acc: x: acc + " --update-input " + x) "" inputs}
|
||||
'';
|
||||
};
|
||||
|
||||
activate =
|
||||
pkgs.writeShellApplication {
|
||||
name = "activate";
|
||||
text =
|
||||
# TODO: Replace with deploy-rs or (new) nixinate
|
||||
if system == "aarch64-darwin" then
|
||||
''
|
||||
set -x
|
||||
${self.darwinConfigurations.default.system}/sw/bin/darwin-rebuild \
|
||||
switch --flake .#default
|
||||
''
|
||||
else
|
||||
''
|
||||
set -x
|
||||
${lib.getExe pkgs.nixos-rebuild} --use-remote-sudo switch -j auto
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue