refactor outputs.nix
Splits everything into separate files.
This commit is contained in:
parent
afb2ca459e
commit
5b97801911
7 changed files with 83 additions and 73 deletions
37
apps.nix
Normal file
37
apps.nix
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
nixos-switch = {
|
||||||
|
type = "app";
|
||||||
|
program = toString (pkgs.writeScript "deploy" ''
|
||||||
|
#!${pkgs.runtimeShell}
|
||||||
|
flake=$(nix flake metadata --json ${./.} | jq -r .url)
|
||||||
|
nixos-rebuild switch --flake ".#$1" --use-remote-sudo
|
||||||
|
'');
|
||||||
|
};
|
||||||
|
apps.deploy = {
|
||||||
|
type = "app";
|
||||||
|
program = toString (pkgs.writeScript "deploy" ''
|
||||||
|
#!${pkgs.runtimeShell}
|
||||||
|
domain='dadada.li'
|
||||||
|
flake=$(nix flake metadata --json ${./.} | jq -r .url)
|
||||||
|
nixos-rebuild switch --upgrade --flake "''${flake}#$1" --target-host "''${1}.$domain" --build-host localhost --use-remote-sudo
|
||||||
|
'');
|
||||||
|
};
|
||||||
|
hm-switch = {
|
||||||
|
type = "app";
|
||||||
|
program = toString (pkgs.writeScript "hm-switch" ''
|
||||||
|
#!${pkgs.runtimeShell}
|
||||||
|
set -eu -o pipefail -x
|
||||||
|
tmpdir=$(mktemp -d)
|
||||||
|
export PATH=${pkgs.lib.makeBinPath [pkgs.coreutils pkgs.nixFlakes pkgs.jq]}
|
||||||
|
trap "rm -rf $tmpdir" EXIT
|
||||||
|
declare -A profiles=(["gorgon"]="home")
|
||||||
|
profile=''${profiles[$HOSTNAME]:-common}
|
||||||
|
flake=$(nix flake metadata --json ${./.} | jq -r .url)
|
||||||
|
nix build --out-link "$tmpdir/result" "$flake#hmConfigurations.''${profile}.activationPackage" "$@"
|
||||||
|
link=$(realpath $tmpdir/result)
|
||||||
|
$link/activate
|
||||||
|
'');
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
9
checks.nix
Normal file
9
checks.nix
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{ pkgs, formatter }:
|
||||||
|
{
|
||||||
|
format = pkgs.runCommand
|
||||||
|
"check-format"
|
||||||
|
{
|
||||||
|
buildInputs = [ formatter ];
|
||||||
|
}
|
||||||
|
"${formatter}/bin/nixpkgs-fmt --check ${./.} && touch $out";
|
||||||
|
}
|
6
dev-shell.nix
Normal file
6
dev-shell.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{ pkgs, agenix-bin, ... }:
|
||||||
|
pkgs.mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
agenix-bin
|
||||||
|
];
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
{ self
|
{ self
|
||||||
, nixpkgs
|
, nixpkgs
|
||||||
, home-manager
|
, home-manager
|
||||||
,
|
, ...
|
||||||
} @ inputs:
|
} @ inputs:
|
||||||
let
|
let
|
||||||
hmConfiguration =
|
hmConfiguration =
|
||||||
|
|
10
hydra-jobs.nix
Normal file
10
hydra-jobs.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{ self, nixpkgs, flake-utils, ... }:
|
||||||
|
(nixpkgs.lib.mapAttrs'
|
||||||
|
(name: config: nixpkgs.lib.nameValuePair name config.config.system.build.toplevel)
|
||||||
|
self.nixosConfigurations
|
||||||
|
) //
|
||||||
|
(nixpkgs.lib.mapAttrs'
|
||||||
|
(name: config: nixpkgs.lib.nameValuePair name config.activation-script)
|
||||||
|
self.hmConfigurations
|
||||||
|
) //
|
||||||
|
(let tests = import ./tests; in flake-utils.lib.eachDefaultSystem tests)
|
|
@ -1,9 +1,8 @@
|
||||||
# TODO refactor adapterModule and redundant module config
|
# TODO refactor adapterModule and redundant module config
|
||||||
{ self
|
{ self
|
||||||
, admins
|
, admins
|
||||||
, agenixModule
|
, agenix
|
||||||
, nixpkgs
|
, nixpkgs
|
||||||
, nixosSystem
|
|
||||||
, home-manager
|
, home-manager
|
||||||
, homePage
|
, homePage
|
||||||
, nixos-hardware
|
, nixos-hardware
|
||||||
|
@ -11,9 +10,11 @@
|
||||||
, scripts
|
, scripts
|
||||||
, recipemd
|
, recipemd
|
||||||
, secretsPath
|
, secretsPath
|
||||||
,
|
, ...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
nixosSystem = nixpkgs.lib.nixosSystem;
|
||||||
|
agenixModule = agenix.nixosModule;
|
||||||
adapterModule = system: {
|
adapterModule = system: {
|
||||||
nixpkgs.config.allowUnfreePredicate = pkg: true;
|
nixpkgs.config.allowUnfreePredicate = pkg: true;
|
||||||
nixpkgs.overlays =
|
nixpkgs.overlays =
|
||||||
|
|
85
outputs.nix
85
outputs.nix
|
@ -12,89 +12,36 @@
|
||||||
, agenix
|
, agenix
|
||||||
, ...
|
, ...
|
||||||
} @ inputs:
|
} @ inputs:
|
||||||
let
|
|
||||||
secretsPath = ./secrets;
|
|
||||||
in
|
|
||||||
(flake-utils.lib.eachDefaultSystem (system:
|
(flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
selfPkgs = self.packages.${system};
|
selfPkgs = self.packages.${system};
|
||||||
formatter = self.formatter.${system};
|
formatter = self.formatter.${system};
|
||||||
agenix-bin = agenix.packages."${system}".agenix;
|
agenix-bin = agenix.defaultPackage."${system}";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
apps.nixos-switch = {
|
apps = import ./apps.nix { inherit pkgs; };
|
||||||
type = "app";
|
|
||||||
program = toString (pkgs.writeScript "deploy" ''
|
|
||||||
#!${pkgs.runtimeShell}
|
|
||||||
flake=$(nix flake metadata --json ${./.} | jq -r .url)
|
|
||||||
nixos-rebuild switch --flake ".#$1" --use-remote-sudo
|
|
||||||
'');
|
|
||||||
};
|
|
||||||
apps.deploy = {
|
|
||||||
type = "app";
|
|
||||||
program = toString (pkgs.writeScript "deploy" ''
|
|
||||||
#!${pkgs.runtimeShell}
|
|
||||||
domain='dadada.li'
|
|
||||||
flake=$(nix flake metadata --json ${./.} | jq -r .url)
|
|
||||||
nixos-rebuild switch --upgrade --flake "''${flake}#$1" --target-host "''${1}.$domain" --build-host localhost --use-remote-sudo
|
|
||||||
'');
|
|
||||||
};
|
|
||||||
apps.hm-switch = {
|
|
||||||
type = "app";
|
|
||||||
program = toString (pkgs.writeScript "hm-switch" ''
|
|
||||||
#!${pkgs.runtimeShell}
|
|
||||||
set -eu -o pipefail -x
|
|
||||||
tmpdir=$(mktemp -d)
|
|
||||||
export PATH=${pkgs.lib.makeBinPath [pkgs.coreutils pkgs.nixFlakes pkgs.jq]}
|
|
||||||
trap "rm -rf $tmpdir" EXIT
|
|
||||||
declare -A profiles=(["gorgon"]="home")
|
|
||||||
profile=''${profiles[$HOSTNAME]:-common}
|
|
||||||
flake=$(nix flake metadata --json ${./.} | jq -r .url)
|
|
||||||
nix build --out-link "$tmpdir/result" "$flake#hmConfigurations.''${profile}.activationPackage" "$@"
|
|
||||||
link=$(realpath $tmpdir/result)
|
|
||||||
$link/activate
|
|
||||||
'');
|
|
||||||
};
|
|
||||||
|
|
||||||
devShell = pkgs.callPackage
|
devShells.default = pkgs.callPackage ./dev-shell.nix { inherit pkgs agenix-bin; };
|
||||||
({}:
|
|
||||||
pkgs.mkShell {
|
|
||||||
buildInputs = [
|
|
||||||
agenix-bin
|
|
||||||
];
|
|
||||||
}
|
|
||||||
)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
formatter = nixpkgs.legacyPackages."${system}".nixpkgs-fmt;
|
formatter = nixpkgs.legacyPackages."${system}".nixpkgs-fmt;
|
||||||
checks = {
|
|
||||||
format = pkgs.runCommand "check-format" { buildInputs = [ formatter ]; } "${formatter}/bin/nixpkgs-fmt --check ${./.} && touch $out";
|
checks = import ./checks.nix { inherit formatter pkgs; };
|
||||||
};
|
|
||||||
}))
|
}))
|
||||||
// {
|
// {
|
||||||
hmConfigurations = import ./home/configurations.nix {
|
|
||||||
inherit self nixpkgs home-manager;
|
hmConfigurations = import ./home/configurations.nix inputs;
|
||||||
};
|
|
||||||
hmModules = import ./home/modules inputs;
|
hmModules = import ./home/modules inputs;
|
||||||
nixosConfigurations = import ./nixos/configurations.nix {
|
|
||||||
agenixModule = agenix.nixosModule;
|
nixosConfigurations = import ./nixos/configurations.nix (inputs // {
|
||||||
nixosSystem = nixpkgs.lib.nixosSystem;
|
|
||||||
admins = import ./admins.nix;
|
admins = import ./admins.nix;
|
||||||
inherit self secretsPath nixpkgs home-manager nixos-hardware nvd scripts homePage recipemd;
|
secretsPath = ./secrets;
|
||||||
};
|
});
|
||||||
|
|
||||||
nixosModules = import ./nixos/modules inputs;
|
nixosModules = import ./nixos/modules inputs;
|
||||||
|
|
||||||
overlays = import ./overlays;
|
overlays = import ./overlays;
|
||||||
hydraJobs =
|
|
||||||
(
|
hydraJobs = import ./hydra-jobs.nix inputs;
|
||||||
nixpkgs.lib.mapAttrs'
|
|
||||||
(name: config: nixpkgs.lib.nameValuePair name config.config.system.build.toplevel)
|
|
||||||
self.nixosConfigurations
|
|
||||||
)
|
|
||||||
// (
|
|
||||||
nixpkgs.lib.mapAttrs'
|
|
||||||
(name: config: nixpkgs.lib.nameValuePair name config.activation-script)
|
|
||||||
self.hmConfigurations
|
|
||||||
)
|
|
||||||
// (let tests = import ./tests; in flake-utils.lib.eachDefaultSystem tests);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue