diff --git a/default.nix b/default.nix index 41c6ca2..d6c5e01 100644 --- a/default.nix +++ b/default.nix @@ -1 +1,31 @@ -_: builtins.getFlake (builtins.toString ./.) +# if evaluating outside of the store, copy the current directory to the store and import it +# filtering out .gitignore files and .git directories +# if evaluating inside the store, import the outputs.nix file + +let + # Ideally this file should be selfcontained, but I like the utilities in nixpkgs lib + lib = (import "${(import ./inputs.nix {}).nixpkgs}/lib").extend (self: super: { + proot = import ./lib/gitignore-filter.nix { lib = self; }; + inherit (self.proot) parseGitignore runGitignoreFilter toGitignoreMatcher; + }); + + currentFilePath = (builtins.unsafeGetAttrPos "any" { any = "any"; }).file; + storePathLength = builtins.stringLength (builtins.toString builtins.storeDir); + evaluatingInStore = (builtins.substring 0 storePathLength currentFilePath) == builtins.storeDir; + + selfInStore = builtins.path { + path = ./.; + name = "source"; + filter = path: type: + let + selfPath = builtins.dirOf currentFilePath; + gitIgnoreFilters = lib.parseGitignore selfPath path; + result = type != "unknown" + && type != "symlink" + && builtins.baseNameOf path != ".git" + && lib.runGitignoreFilter gitIgnoreFilters path type; + in result; + }; +in +if !(evaluatingInStore) then { ... }@args: import selfInStore ({ selfPath = selfInStore; } // args ) +else { ... }@args: import ./outputs.nix ({ selfPath = selfInStore; } // args) diff --git a/flake.lock b/flake.lock deleted file mode 100644 index f6bc799..0000000 --- a/flake.lock +++ /dev/null @@ -1,190 +0,0 @@ -{ - "nodes": { - "cosmic-modules": { - "inputs": { - "flake-compat": "flake-compat", - "nixpkgs": "nixpkgs", - "nixpkgs-stable": "nixpkgs-stable", - "rust-overlay": "rust-overlay" - }, - "locked": { - "lastModified": 1743246566, - "narHash": "sha256-arEFUDLjADYIZ7T6PZX1yLOnfMoZ1ByebtmPuvV98+s=", - "owner": "lilyinstarlight", - "repo": "nixos-cosmic", - "rev": "c709db4b95e58f410978bb49c87cb74214d03e78", - "type": "github" - }, - "original": { - "owner": "lilyinstarlight", - "repo": "nixos-cosmic", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1717312683, - "narHash": "sha256-FrlieJH50AuvagamEvWMIE6D2OAnERuDboFDYAED/dE=", - "owner": "nix-community", - "repo": "flake-compat", - "rev": "38fd3954cf65ce6faf3d0d45cd26059e059f07ea", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixos-vscode-server": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1729422940, - "narHash": "sha256-DlvJv33ml5UTKgu4b0HauOfFIoDx6QXtbqUF3vWeRCY=", - "owner": "nix-community", - "repo": "nixos-vscode-server", - "rev": "8b6db451de46ecf9b4ab3d01ef76e59957ff549f", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixos-vscode-server", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1743095683, - "narHash": "sha256-gWd4urRoLRe8GLVC/3rYRae1h+xfQzt09xOfb0PaHSk=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5e5402ecbcb27af32284d4a62553c019a3a49ea6", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1742937945, - "narHash": "sha256-lWc+79eZRyvHp/SqMhHTMzZVhpxkRvthsP1Qx6UCq0E=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "d02d88f8de5b882ccdde0465d8fa2db3aa1169f7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-24.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-unstable": { - "locked": { - "lastModified": 1743095683, - "narHash": "sha256-gWd4urRoLRe8GLVC/3rYRae1h+xfQzt09xOfb0PaHSk=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5e5402ecbcb27af32284d4a62553c019a3a49ea6", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "ref": "nixos-unstable", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1742937945, - "narHash": "sha256-lWc+79eZRyvHp/SqMhHTMzZVhpxkRvthsP1Qx6UCq0E=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "d02d88f8de5b882ccdde0465d8fa2db3aa1169f7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "ref": "nixos-24.11", - "type": "github" - } - }, - "root": { - "inputs": { - "cosmic-modules": "cosmic-modules", - "nixos-vscode-server": "nixos-vscode-server", - "nixpkgs": "nixpkgs_2", - "nixpkgs-unstable": "nixpkgs-unstable" - } - }, - "rust-overlay": { - "inputs": { - "nixpkgs": [ - "cosmic-modules", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1743215516, - "narHash": "sha256-52qbrkG65U1hyrQWltgHTgH4nm0SJL+9TWv2UDCEPNI=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "524463199fdee49338006b049bc376b965a2cfed", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "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" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index b183431..0000000 --- a/flake.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ - inputs = { - nixos-vscode-server = { - type = "github"; - owner = "nix-community"; - repo = "nixos-vscode-server"; - inputs = { - nixpkgs.follows = "nixpkgs"; - }; - }; - nixpkgs = { - type = "github"; - owner = "NixOS"; - repo = "nixpkgs"; - ref = "nixos-24.11"; - }; - nixpkgs-unstable = { - type = "github"; - owner = "NixOS"; - repo = "nixpkgs"; - ref = "nixos-unstable"; - }; - cosmic-modules = { - type = "github"; - owner = "lilyinstarlight"; - repo = "nixos-cosmic"; - }; - }; - outputs = inputs: import ./outputs.nix { - inherit inputs; - }; -} diff --git a/hosts/main/default.nix b/hosts/main/default.nix index 75d7df7..3b9807f 100644 --- a/hosts/main/default.nix +++ b/hosts/main/default.nix @@ -83,6 +83,8 @@ OLLAMA_HOST = "127.0.0.1:${builtins.toString config.services.ollama.port}"; }; + nixpkgs.hostPlatform = "x86_64-linux"; + system.stateVersion = "23.05"; }; } diff --git a/hosts/tablet.nix b/hosts/tablet.nix index 3ec9e20..7343cda 100644 --- a/hosts/tablet.nix +++ b/hosts/tablet.nix @@ -52,6 +52,8 @@ lidSwitchExternalPower = "lock"; }; + nixpkgs.hostPlatform = "x86_64-linux"; + system.stateVersion = "23.11"; }; } diff --git a/hosts/vm-base.nix b/hosts/vm-base.nix index 9c7a57a..8584fbd 100644 --- a/hosts/vm-base.nix +++ b/hosts/vm-base.nix @@ -20,5 +20,6 @@ virtualisation.forwardPorts = [ { from = "host"; host.port = 2222; guest.port = 22; } ]; + nixpkgs.hostPlatform = "x86_64-linux"; }; } diff --git a/inputs.nix b/inputs.nix new file mode 100644 index 0000000..1c6c039 --- /dev/null +++ b/inputs.nix @@ -0,0 +1,84 @@ +let self = { + lock ? import lockFile, + lockFile ? ./lock.nix, + pkgs ? throw "inputs called without pkgs", +}: + +{ + inherit lock; + nixos-vscode-server = rec { + url = "https://github.com/nix-community/nixos-vscode-server/archive/${lock.nixos-vscode-server.revision}.tar.gz"; + updateScript = pkgs.den-http-get-updater { + fileLocation = lockFile; + previousHash = lock.nixos-vscode-server.sha256; + previousVersion = lock.nixos-vscode-server.revision; + versionUrl = "https://api.github.com/repos/nix-community/nixos-vscode-server/commits"; + contentParser = "jq -rc '.[0].sha' <<< \"$newVersion\""; + prefetchUrlLocation = { + file = ./inputs.nix; + attrpath = "nixos-vscode-server.url"; + }; + }; + outPath = builtins.fetchTarball { + inherit url; + name = "nixos-vscode-server"; + sha256 = "${lock.nixos-vscode-server.sha256}"; + }; + }; + nixpkgs = rec { + url = "https://github.com/NixOS/nixpkgs/archive/${lock.nixpkgs.revision}.tar.gz"; + updateScript = pkgs.den-http-get-updater { + fileLocation = lockFile; + previousHash = lock.nixpkgs.sha256; + previousVersion = lock.nixpkgs.revision; + versionUrl = "https://channels.nixos.org/nixos-24.11/git-revision"; + prefetchUrlLocation = { + file = ./inputs.nix; + attrpath = "nixpkgs.url"; + }; + }; + outPath = builtins.fetchTarball { + inherit url; + name = "nixpkgs"; + sha256 = "${lock.nixpkgs.sha256}"; + }; + }; + nixpkgs-unstable = rec { + url = "https://github.com/NixOS/nixpkgs/archive/${lock.nixpkgs-unstable.revision}.tar.gz"; + updateScript = pkgs.den-http-get-updater { + fileLocation = lockFile; + previousHash = lock.nixpkgs-unstable.sha256; + previousVersion = lock.nixpkgs-unstable.revision; + versionUrl = "https://channels.nixos.org/nixos-unstable/git-revision"; + prefetchUrlLocation = { + file = ./inputs.nix; + attrpath = "nixpkgs-unstable.url"; + }; + }; + outPath = builtins.fetchTarball { + inherit url; + name = "nixpkgs-unstable"; + sha256 = "${lock.nixpkgs-unstable.sha256}"; + }; + }; + cosmic-modules = rec { + url = "https://github.com/lilyinstarlight/nixos-cosmic/archive/${lock.cosmic-modules.revision}.tar.gz"; + updateScript = pkgs.den-http-get-updater { + fileLocation = lockFile; + previousHash = lock.cosmic-modules.sha256; + previousVersion = lock.cosmic-modules.revision; + versionUrl = "https://api.github.com/repos/lilyinstarlight/nixos-cosmic/commits"; + contentParser = "jq -rc '.[0].sha' <<< \"$newVersion\""; + prefetchUrlLocation = { + file = ./inputs.nix; + attrpath = "cosmic-modules.url"; + }; + }; + outPath = builtins.fetchTarball { + inherit url; + name = "cosmic-modules"; + sha256 = "${lock.cosmic-modules.sha256}"; + }; + }; +}; +in self diff --git a/lock.nix b/lock.nix new file mode 100644 index 0000000..a18318a --- /dev/null +++ b/lock.nix @@ -0,0 +1,18 @@ +{ + nixos-vscode-server = { + revision = "8b6db451de46ecf9b4ab3d01ef76e59957ff549f"; + sha256 = "09j4kvsxw1d5dvnhbsgih0icbrxqv90nzf0b589rb5z6gnzwjnqf"; + }; + nixpkgs = { + revision = "d02d88f8de5b882ccdde0465d8fa2db3aa1169f7"; + sha256 = "0hdb0ajwfl7xn1hznik4kj35adiksc8k5apllz3jniwrszpkwrwm"; + }; + nixpkgs-unstable = { + revision = "5e5402ecbcb27af32284d4a62553c019a3a49ea6"; + sha256 = "0a8xv91nz7qkyxs3nhszxj3vb9s5v1xgyhmm32y1fbb8njx7hrw1"; + }; + cosmic-modules = { + revision = "c709db4b95e58f410978bb49c87cb74214d03e78"; + sha256 = "1szkgpsvm3yrdsg1rm0rr9yagcy8ynakvymlcw43c0736980bcba"; + }; +} diff --git a/nix-os/core.nix b/nix-os/core.nix index d09e57b..34c6f41 100644 --- a/nix-os/core.nix +++ b/nix-os/core.nix @@ -23,8 +23,6 @@ channel.enable = false; settings.experimental-features = [ "no-url-literals" - "nix-command" - "flakes" ]; nixPath = [ "nixpkgs=${pkgs.selfExpr { useConfig = false; }}" diff --git a/outputs.nix b/outputs.nix index e8fb8fa..48ad9b6 100644 --- a/outputs.nix +++ b/outputs.nix @@ -1,11 +1,12 @@ { - inputs, + inputsPath ? ./inputs.nix, + inputs ? import inputsPath {}, selfPath ? ./. }: let -lib = (import "${inputs.nixpkgs}/lib").extend (import ./lib/overlays/version-info-fixup.nix { revision = inputs.nixpkgs.rev; }); +lib = (import "${inputs.nixpkgs}/lib").extend (import ./lib/overlays/version-info-fixup.nix { revision = inputs.lock.nixpkgs.revision; }); systems = [ "x86_64-linux" @@ -16,7 +17,7 @@ systems = [ forEachSystem = lib.genAttrs systems; self = { - inherit inputs lib self; + inherit inputs inputsPath lib self; outPath = selfPath; modifiedNixpkgs = import ./pkgs/top-level/impure.nix; modifiedNixpkgsPure = import ./pkgs/top-level/default.nix; @@ -30,13 +31,14 @@ self = { overlays = { cosmicPackages = import ./pkgs/overlays/cosmic-packages.nix { inherit inputs; }; selfExpr = import ./pkgs/overlays/selfExpr.nix { nixpkgsPath = inputs.nixpkgs; }; - unstableWithMeta = import ./pkgs/overlays/unstable-with-meta.nix { unstableSource = inputs.nixpkgs-unstable; revision = inputs.nixpkgs-unstable.rev; }; + unstableWithMeta = import ./pkgs/overlays/unstable-with-meta.nix { unstableSource = inputs.nixpkgs-unstable; revision = inputs.lock.nixpkgs-unstable.revision; }; versionInfoFixup = import ./pkgs/overlays/version-info-fixup.nix { inherit inputs; }; }; nixosConfigurations = let nixosSystem = import "${inputs.nixpkgs}/nixos/lib/eval-config.nix"; mkNixosSystem = path: nixosSystem { inherit lib; + system = null; modules = [ path { diff --git a/pkgs/overlays/version-info-fixup.nix b/pkgs/overlays/version-info-fixup.nix index b9ffa3a..b1f2ecc 100644 --- a/pkgs/overlays/version-info-fixup.nix +++ b/pkgs/overlays/version-info-fixup.nix @@ -1,7 +1,7 @@ { inputs ? import ../../inputs.nix {} }: self: super: { - lib = super.lib.extend (import ../../lib/overlays/version-info-fixup.nix { revision = inputs.nixpkgs.rev; }); + lib = super.lib.extend (import ../../lib/overlays/version-info-fixup.nix { revision = inputs.lock.nixpkgs.revision; }); } // super.lib.optionalAttrs (super ? unstable && super ? unstableRevision) { unstable = super.unstable // { diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index 2ee6687..9194e56 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -1,4 +1,4 @@ -{ inputs ? import ../../inputs.nix {} +{ inputs ? (import ../../. {}).inputs , uninitializedNixpkgs ? import "${inputs.nixpkgs}/pkgs/top-level/default.nix" , ... } @ args: @@ -14,7 +14,7 @@ let overlays = (args.overlays or []) ++ [ # ../.. should be nix store path that represents self in outputs.nix that is gc-rooted by this point ( import ../overlays/selfExpr.nix { nixpkgsPath = "${builtins.toString ../..}/pkgs/top-level/impure.nix"; } ) - ( import ../overlays/unstable-with-meta.nix { unstableSource = inputs.nixpkgs-unstable; revision = inputs.nixpkgs-unstable.rev; } ) + ( import ../overlays/unstable-with-meta.nix { unstableSource = inputs.nixpkgs-unstable; revision = inputs.lock.nixpkgs-unstable.revision; } ) ( import ../overlays/unstable-latest.nix ) ( import ../overlays/version-info-fixup.nix { inherit inputs; } ) ( import ./by-name-overlay.nix ../by-name )