1
0
Fork 0

Flakify home-manager

This commit is contained in:
Malte 2023-02-03 06:37:18 +01:00
parent 57c4361de3
commit 8f1baa9f12
19 changed files with 199 additions and 173 deletions

View file

@ -1,12 +0,0 @@
let
nixos-stable = {
nixpkgs-channel = "nixos-stable";
home-manager-channel = "home-manager-stable";
};
in rec {
hera = nixos-stable;
apollo = nixos-stable;
zeus = nixos-stable;
fluffy = nixos-stable;
chor-cloud = hera;
}

View file

@ -136,6 +136,30 @@
"type": "github" "type": "github"
} }
}, },
"home-manager": {
"inputs": {
"nixpkgs": [
"nixos-unstable"
],
"utils": [
"pre-commit-hooks-nix",
"flake-utils"
]
},
"locked": {
"lastModified": 1674440933,
"narHash": "sha256-CASRcD/rK3fn5vUCti3jzry7zi0GsqRsBohNq9wPgLs=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "65c47ced082e3353113614f77b1bc18822dc731f",
"type": "github"
},
"original": {
"id": "home-manager",
"ref": "release-22.11",
"type": "indirect"
}
},
"nixos-hardware": { "nixos-hardware": {
"locked": { "locked": {
"lastModified": 1674550793, "lastModified": 1674550793,
@ -152,34 +176,32 @@
}, },
"nixos-stable": { "nixos-stable": {
"locked": { "locked": {
"lastModified": 1675154384, "lastModified": 1675237434,
"narHash": "sha256-gUXzyTS3WsO3g2Rz0qOYR2a26whkyL2UfTr1oPH9mm8=", "narHash": "sha256-YoFR0vyEa1HXufLNIFgOGhIFMRnY6aZ0IepZF5cYemo=",
"owner": "nixos", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "0218941ea68b4c625533bead7bbb94ccce52dceb", "rev": "285b3ff0660640575186a4086e1f8dc0df2874b5",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "id": "nixpkgs",
"ref": "nixos-22.11", "ref": "nixos-22.11",
"repo": "nixpkgs", "type": "indirect"
"type": "github"
} }
}, },
"nixos-unstable": { "nixos-unstable": {
"locked": { "locked": {
"lastModified": 1675183161, "lastModified": 1675183161,
"narHash": "sha256-Zq8sNgAxDckpn7tJo7V1afRSk2eoVbu3OjI1QklGLNg=", "narHash": "sha256-Zq8sNgAxDckpn7tJo7V1afRSk2eoVbu3OjI1QklGLNg=",
"owner": "nixos", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e1e1b192c1a5aab2960bf0a0bd53a2e8124fa18e", "rev": "e1e1b192c1a5aab2960bf0a0bd53a2e8124fa18e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "id": "nixpkgs",
"ref": "nixos-unstable", "ref": "nixos-unstable",
"repo": "nixpkgs", "type": "indirect"
"type": "github"
} }
}, },
"pre-commit-hooks-nix": { "pre-commit-hooks-nix": {
@ -212,6 +234,7 @@
"inputs": { "inputs": {
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"hexa-nur-packages": "hexa-nur-packages", "hexa-nur-packages": "hexa-nur-packages",
"home-manager": "home-manager",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nixos-stable": "nixos-stable", "nixos-stable": "nixos-stable",
"nixos-unstable": "nixos-unstable", "nixos-unstable": "nixos-unstable",

View file

@ -9,10 +9,17 @@
url = "git+ssh://git@hera.m-0.eu/config-secrets"; url = "git+ssh://git@hera.m-0.eu/config-secrets";
inputs.nixpkgs.follows = "nixos-unstable"; inputs.nixpkgs.follows = "nixos-unstable";
}; };
nixos-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; nixos-unstable.url = "nixpkgs/nixos-unstable";
nixos-stable.url = "github:nixos/nixpkgs/nixos-22.11"; nixos-stable.url = "nixpkgs/nixos-22.11";
nixpkgs.follows = "nixos-unstable"; nixpkgs.follows = "nixos-unstable";
flake-parts.inputs.nixpkgs-lib.follows = "nixos-unstable"; flake-parts.inputs.nixpkgs-lib.follows = "nixos-unstable";
home-manager = {
url = "home-manager/release-22.11";
inputs = {
utils.follows = "pre-commit-hooks-nix/flake-utils";
nixpkgs.follows = "nixos-unstable";
};
};
hexa-nur-packages = { hexa-nur-packages = {
url = "github:mweinelt/nur-packages"; url = "github:mweinelt/nur-packages";
inputs.nixpkgs.follows = "nixos-unstable"; inputs.nixpkgs.follows = "nixos-unstable";
@ -26,19 +33,15 @@
}; };
}; };
outputs = inputs @ {nixos-hardware, ...}: let outputs = inputs @ {nixos-hardware, ...}:
unstable = inputs.nixos-unstable.legacyPackages.x86_64-linux;
inherit (import ./packages {pkgs = unstable;}) haskellPackagesOverlay selectHaskellPackages;
in
inputs.flake-parts.lib.mkFlake {inherit inputs;} { inputs.flake-parts.lib.mkFlake {inherit inputs;} {
imports = [ imports = [
inputs.pre-commit-hooks-nix.flakeModule inputs.pre-commit-hooks-nix.flakeModule
./nixos/configurations.nix
./home-manager/modes.nix
./packages
]; ];
systems = ["x86_64-linux"]; systems = ["x86_64-linux"];
flake = {
nixosConfigurations = import ./nixos/configurations.nix inputs;
overlays.haskellPackages = haskellPackagesOverlay;
};
perSystem = { perSystem = {
self', self',
inputs', inputs',
@ -46,31 +49,19 @@
config, config,
lib, lib,
... ...
}: let }: {
hpkgs = pkgs.haskellPackages.override {
overrides = inputs.self.overlays.haskellPackages;
};
in {
devShells = { devShells = {
default = pkgs.mkShell { default = pkgs.mkShell {
shellHook = config.pre-commit.installationScript; shellHook = config.pre-commit.installationScript;
}; };
haskell = hpkgs.shellFor {
packages = hpkgs: (builtins.attrValues (selectHaskellPackages hpkgs));
shellHook = config.pre-commit.installationScript;
buildInputs = [
hpkgs.haskell-language-server
pkgs.cabal-install
];
};
}; };
checks = { checks = {
system-checks = pkgs.runCommand "system-checks" {} '' system-checks = pkgs.runCommand "system-checks" {} ''
${lib.concatMapStringsSep "\n" (x: "# ${x.config.system.build.toplevel}") (builtins.attrValues inputs.self.nixosConfigurations)} mkdir -p $out
echo success > $out ${lib.concatMapStringsSep "\n" (x: x) (lib.mapAttrsToList (name: x: "ln -s ${x.config.system.build.toplevel} $out/${name}-system") inputs.self.nixosConfigurations)}
${lib.concatMapStringsSep "\n" (x: x) (lib.mapAttrsToList (name: x: "ln -s ${x} $out/${name}-home") inputs.self.homeModes)}
''; '';
}; };
packages = selectHaskellPackages hpkgs;
pre-commit = { pre-commit = {
check.enable = true; check.enable = true;

View file

@ -35,7 +35,6 @@ let
makeConfig = hostName: imports: _: { makeConfig = hostName: imports: _: {
imports = imports ++ [./roles/default.nix]; imports = imports ++ [./roles/default.nix];
m-0.hostName = hostName; m-0.hostName = hostName;
nixpkgs.overlays = [(_: _: (import ../channels.nix)."${hostName}")];
}; };
makeAutostart = name: {config, ...}: { makeAutostart = name: {config, ...}: {
config.xdg.configFile."autostart/${name}.desktop".source = "${config.home.path}/share/applications/${name}.desktop"; config.xdg.configFile."autostart/${name}.desktop".source = "${config.home.path}/share/applications/${name}.desktop";

36
home-manager/modes.nix Normal file
View file

@ -0,0 +1,36 @@
{
withSystem,
lib,
inputs,
...
}: {
flake = withSystem "x86_64-linux" ({inputs', ...}: let
pkgs = inputs'.nixos-stable.legacyPackages;
flattenAttrs = attrs:
lib.listToAttrs (lib.flatten (lib.mapAttrsToList
(
outer_key:
lib.mapAttrsToList
(inner_key: value: {
name = "${outer_key}-${inner_key}";
inherit value;
})
)
attrs));
machines = import ./machines.nix;
buildHomeManager = config: (inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
config
inputs.self.nixosModules.insertOverlays
];
});
buildModesForHost = host: modes:
pkgs.runCommandLocal "${host}-modes" {} ''
mkdir $out
${lib.concatStringsSep "\n" (lib.mapAttrsToList (mode: config: "ln -s ${(buildHomeManager config).activationPackage} $out/${mode}") modes)}'';
in {
homeConfigurations = lib.mapAttrs (_: buildHomeManager) (flattenAttrs machines);
homeModes = lib.mapAttrs buildModesForHost machines;
});
}

View file

@ -13,7 +13,6 @@
./helix.nix ./helix.nix
./nvd.nix ./nvd.nix
]; ];
nixpkgs.overlays = import ../../overlays {inherit lib;};
news.display = "silent"; news.display = "silent";

View file

@ -24,10 +24,5 @@
ln -s ${standalone}/source.dhall $out/config.dhall ln -s ${standalone}/source.dhall $out/config.dhall
''; '';
in { in {
xdg.configFile = xdg.configFile.kassandra.source = dhallResult.out;
if pkgs.withSecrets
then {
kassandra.source = dhallResult.out;
}
else {};
} }

View file

@ -117,7 +117,7 @@ in {
postExec = "${sortMail}/bin/sort-mail-archive"; postExec = "${sortMail}/bin/sort-mail-archive";
preExec = toString mail2task; preExec = toString mail2task;
}; };
accounts.email.accounts = lib.mkIf pkgs.withSecrets { accounts.email.accounts = {
hera.imapnotify = { hera.imapnotify = {
onNotifyPost = toString mail2task; onNotifyPost = toString mail2task;
boxes = ["Move/todo"]; boxes = ["Move/todo"];

View file

@ -64,7 +64,7 @@ in {
msmtp.enable = true; msmtp.enable = true;
mbsync.enable = true; mbsync.enable = true;
notmuch = { notmuch = {
enable = pkgs.withSecrets; enable = true;
hooks.postInsert = '' hooks.postInsert = ''
${pkgs.notmuch}/bin/notmuch tag +deleted -- "folder:/Trash/ (not tag:deleted)" ${pkgs.notmuch}/bin/notmuch tag +deleted -- "folder:/Trash/ (not tag:deleted)"
${pkgs.notmuch}/bin/notmuch tag -deleted -- "(not folder:/Trash/) tag:deleted" ${pkgs.notmuch}/bin/notmuch tag -deleted -- "(not folder:/Trash/) tag:deleted"

View file

@ -40,15 +40,9 @@ in {
name = "update-modes"; name = "update-modes";
bins = [activateMode pkgs.git pkgs.nix-output-monitor]; bins = [activateMode pkgs.git pkgs.nix-output-monitor];
} '' } ''
params = ["${configPath}/home-manager/target.nix", "-A", "${hostName}"]
main = do main = do
say "Building ~/.modes for ${hostName}" say "Building ~/.modes for ${hostName}"
nixPath <- myNixPath "${configPath}" nom ["build", "/home/maralorn/git/config#homeModes.${hostName}", "-o", "${modeDir}"]
setEnv "WITH_SECRETS" "false"
nom_build nixPath (params ++ remoteBuildParams ++ ["--no-out-link"])
setEnv "WITH_SECRETS" "true"
nom_build nixPath (params ++ ["-o", "${modeDir}"])
activate_mode activate_mode
''; '';
quickUpdateMode = quickUpdateMode =
@ -61,10 +55,10 @@ in {
getMode = decodeUtf8 <$> (cat "${modeFile}" |> captureTrim) getMode = decodeUtf8 <$> (cat "${modeFile}" |> captureTrim)
main = do main = do
nixPath <- myNixPath "${configPath}"
mode <- getMode mode <- getMode
say [i|Quick switching to mode #{mode} ...|] say [i|Quick switching to mode #{mode} ...|]
ignoreFailure (home_manager (nixPath <> ["switch", "-A", [i|${hostName}-#{mode}|]])) &!> StdOut |> nom path :: Text <- decodeUtf8 <$> (nix ["build", "--print-out-paths", [i|/home/maralorn/git/config\#homeConfigurations.${hostName}-#{mode}.activationPackage|]] |> captureTrim)
exe ([i|#{path}/activate|] :: String)
update_modes update_modes
''; '';
selectMode = selectMode =

View file

@ -1,6 +1,7 @@
{ {
pkgs, pkgs,
config, config,
flake-inputs,
... ...
}: let }: let
fix-tasks = pkgs.writeShellScriptBin "fix-tasks" '' fix-tasks = pkgs.writeShellScriptBin "fix-tasks" ''
@ -75,10 +76,10 @@ in {
dataLocation = "${config.home.homeDirectory}/.task"; dataLocation = "${config.home.homeDirectory}/.task";
config = { config = {
taskd = { taskd = {
certificate = pkgs.privatePath "taskwarrior/public.cert"; certificate = "${flake-inputs.secrets}/taskwarrior/public.cert";
credentials = pkgs.privateValue "" "taskwarrior/credentials"; credentials = pkgs.privateValue "" "taskwarrior/credentials";
ca = pkgs.privatePath "taskwarrior/ca.cert"; ca = "${flake-inputs.secrets}/taskwarrior/ca.cert";
key = pkgs.privatePath "taskwarrior/private.key"; key = "${flake-inputs.secrets}/taskwarrior/private.key";
server = "hera.m-0.eu:53589"; server = "hera.m-0.eu:53589";
}; };
}; };

View file

@ -1,14 +0,0 @@
let
inherit (import (import ./nix/sources.nix).nixos-unstable {}) lib;
modes = import home-manager/machines.nix;
in
lib.listToAttrs (lib.flatten (lib.mapAttrsToList
(
host:
lib.mapAttrsToList
(mode: config: {
name = "${host}-${mode}";
value = config;
})
)
modes))

View file

@ -1,36 +1,74 @@
flake-inputs: let {
inherit (flake-inputs.nixos-stable) lib; withSystem,
networkingModule = name: "${flake-inputs.nixos-unstable}/nixos/modules/services/networking/${name}.nix"; lib,
modules = [ inputs,
# nftables using module not available in 22.11. ...
(networkingModule "firewall-iptables") }: {
(networkingModule "firewall-nftables") flake = withSystem "x86_64-linux" ({
(networkingModule "firewall") inputs',
(networkingModule "nat-iptables") system,
(networkingModule "nat-nftables") ...
(networkingModule "nat") }: let
(networkingModule "nftables") networkingModule = name: "${inputs.nixos-unstable}/nixos/modules/services/networking/${name}.nix";
(_: { modules = [
disabledModules = [ # nftables using module not available in 22.11.
"services/networking/firewall.nix" (networkingModule "firewall-iptables")
"services/networking/nftables.nix" (networkingModule "firewall-nftables")
"services/networking/nat.nix" (networkingModule "firewall")
"services/networking/redsocks.nix" (networkingModule "nat-iptables")
"services/networking/miniupnpd.nix" (networkingModule "nat-nftables")
"services/audio/roon-server.nix" (networkingModule "nat")
"services/audio/roon-bridge.nix" (networkingModule "nftables")
]; (_: {
}) disabledModules = [
]; "services/networking/firewall.nix"
makeSystem = name: "services/networking/nftables.nix"
lib.nixosSystem { "services/networking/nat.nix"
modules = "services/networking/redsocks.nix"
"services/networking/miniupnpd.nix"
"services/audio/roon-server.nix"
"services/audio/roon-bridge.nix"
];
})
];
makeSystem = name:
inputs'.nixos-stable.legacyPackages.nixos {
imports =
[
(import (./. + "/machines/${name}/configuration.nix") inputs)
inputs.secrets.nixosModules.secrets
inputs.self.nixosModules.insertOverlays
]
++ modules;
};
in {
nixosModules.insertOverlays = _: {
_module.args = {
flake-inputs = inputs // {inherit modules;};
flake-inputs' = inputs';
};
nixpkgs.overlays =
[ [
(import (./. + "/machines/${name}/configuration.nix") flake-inputs) (_: _:
flake-inputs.secrets.nixosModules.secrets {
(_: {config._module.args.flake-inputs = flake-inputs // {inherit modules;};}) unstable = inputs'.nixos-unstable.legacyPackages;
unfree = import inputs.nixos-stable {
inherit system;
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
};
unstableUnfree = import inputs.nixos-unstable {
config.allowUnfree = true;
inherit system;
};
}
// inputs.secrets.private)
inputs.self.overlays.addMyHaskellPackages
] ]
++ modules; ++ import ../overlays {inherit lib;};
}; };
in nixosConfigurations = lib.genAttrs ["zeus" "apollo" "hera" "fluffy"] makeSystem;
lib.genAttrs ["zeus" "apollo" "hera" "fluffy"] makeSystem });
}

View file

@ -78,7 +78,7 @@
privateNetwork = true; privateNetwork = true;
hostBridge = "bridge"; hostBridge = "bridge";
config = {pkgs, ...}: { config = {pkgs, ...}: {
imports = [(args @ {pkgs, ...}: import ../../roles (args // {inherit flake-inputs;}))] ++ flake-inputs.modules; imports = [flake-inputs.self.nixosModules.insertOverlays] ++ flake-inputs.modules;
networking = { networking = {
interfaces.eth0 = { interfaces.eth0 = {

View file

@ -2,7 +2,6 @@
pkgs, pkgs,
config, config,
lib, lib,
flake-inputs,
... ...
}: { }: {
imports = [ imports = [
@ -15,19 +14,6 @@
supportedLocales = ["en_DK.UTF-8/UTF-8" "de_DE.UTF-8/UTF-8" "en_US.UTF-8/UTF-8"]; supportedLocales = ["en_DK.UTF-8/UTF-8" "de_DE.UTF-8/UTF-8" "en_US.UTF-8/UTF-8"];
}; };
# For nixos-rebuild
nixpkgs.overlays =
[
(_: _:
{
unstable = flake-inputs.nixos-unstable.legacyPackages.x86_64-linux;
nixpkgs-channel = "nixos-stable";
home-manager-channel = "home-manager-stable";
}
// flake-inputs.secrets.private)
]
++ import ../../overlays {inherit lib;};
time.timeZone = "Europe/Berlin"; time.timeZone = "Europe/Berlin";
networking = { networking = {
@ -65,6 +51,7 @@
systemPackages = builtins.attrValues { systemPackages = builtins.attrValues {
inherit inherit
(pkgs) (pkgs)
git
gnumake gnumake
mkpasswd mkpasswd
file file
@ -121,16 +108,6 @@
; ;
inherit (pkgs.python3Packages) qrcode; inherit (pkgs.python3Packages) qrcode;
}; };
etc =
lib.mapAttrs'
(name: value: lib.nameValuePair "nix-path/${name}" {source = value;})
(lib.filterAttrs (name: value: name != "__functor") pkgs.sources)
// {
"nix-path/nixos".source = pkgs.sources."${pkgs.nixpkgs-channel}";
"nix-path/nixpkgs".source = pkgs.sources."${pkgs.nixpkgs-channel}";
"nix-path/home-manager".source =
pkgs.sources."${pkgs.home-manager-channel}";
};
variables = variables =
lib.genAttrs ["CURL_CA_BUNDLE" "GIT_SSL_CAINFO" "SSL_CERT_FILE"] lib.genAttrs ["CURL_CA_BUNDLE" "GIT_SSL_CAINFO" "SSL_CERT_FILE"]
(_: "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"); (_: "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt");
@ -138,18 +115,12 @@
nix = { nix = {
settings = { settings = {
substituters = lib.mkAfter ( substituters = lib.mkAfter (pkgs.privateValue [] "binary-caches");
pkgs.privateValue [] "binary-caches"
# ++ (
# if config.networking.hostName != "hera" then [ "ssh-ng://nix-ssh@hera.m-0.eu?trusted=true&priority=100" ] else [ ]
# )
);
trusted-public-keys = [ trusted-public-keys = [
"nixbuild.net/maralorn-1:cpqv21sJgRL+ROaKY1Gr0k7AKolAKaP3S3iemGxK/30=" "nixbuild.net/maralorn-1:cpqv21sJgRL+ROaKY1Gr0k7AKolAKaP3S3iemGxK/30="
]; ];
trusted-users = ["maralorn" "laminar"]; trusted-users = ["maralorn" "laminar"];
}; };
nixPath = ["/etc/nix-path"];
buildMachines = pkgs.privateValue [] "remote-builders"; buildMachines = pkgs.privateValue [] "remote-builders";
extraOptions = '' extraOptions = ''
experimental-features = nix-command flakes experimental-features = nix-command flakes

View file

@ -1,12 +1,4 @@
self: super: let self: super: {
unfree = import self.sources."${self.nixpkgs-channel}" { inherit (super.unfree) discord zoom-us minecraft teamviewer steam androidsdk_9_0;
config = { inherit (super.unstableUnfree) minecraft-server;
allowUnfree = true;
android_sdk.accept_license = true;
};
};
unstableUnfree = import self.sources.nixos-unstable {config.allowUnfree = true;};
in {
inherit (unfree) discord zoom-us minecraft teamviewer steam androidsdk_9_0;
inherit (unstableUnfree) minecraft-server;
} }

View file

@ -1,6 +0,0 @@
_: prev: let
inherit (import ../packages {pkgs = prev;}) haskellPackagesOverlay selectHaskellPackages;
in
selectHaskellPackages (prev.unstable.haskellPackages.override {
overrides = haskellPackagesOverlay;
})

View file

@ -108,9 +108,6 @@ in {
tag name str = ["-I", [i|#{name :: Text}=#{str :: Text}|]] :: [String] tag name str = ["-I", [i|#{name :: Text}=#{str :: Text}|]] :: [String]
getNivAssign (name, repo) = tag name <$> getNivPath path repo getNivAssign (name, repo) = tag name <$> getNivPath path repo
myNixPath :: Text -> IO [String]
myNixPath = aNixPath "${pkgs.home-manager-channel}" "${pkgs.nixpkgs-channel}"
buildSystemParams :: [String] buildSystemParams :: [String]
buildSystemParams = ["<nixpkgs/nixos>", "-A", "system"] buildSystemParams = ["<nixpkgs/nixos>", "-A", "system"]

View file

@ -1,5 +1,9 @@
{pkgs}: let {
inherit (pkgs) lib; lib,
inputs,
...
}: let
pkgs = inputs.nixos-unstable.legacyPackages.x86_64-linux;
inherit (pkgs.haskell.lib.compose) unmarkBroken doJailbreak dontCheck appendPatch; inherit (pkgs.haskell.lib.compose) unmarkBroken doJailbreak dontCheck appendPatch;
includePatterns = [ includePatterns = [
".hs" ".hs"
@ -58,6 +62,24 @@
source = ./nixpkgs-bot; source = ./nixpkgs-bot;
}; };
}; };
hpkgs = pkgs.haskellPackages.override {
overrides = haskellPackagesOverlay;
};
packages = selectHaskellPackages hpkgs;
in { in {
inherit selectHaskellPackages haskellPackagesOverlay; flake.overlays = {
inherit haskellPackagesOverlay;
addMyHaskellPackages = _: _: packages;
};
perSystem = {config, ...}: {
inherit packages;
devShells.haskell = hpkgs.shellFor {
packages = hpkgs: (builtins.attrValues (selectHaskellPackages hpkgs));
shellHook = config.pre-commit.installationScript;
buildInputs = [
hpkgs.haskell-language-server
hpkgs.cabal-install
];
};
};
} }